eheinzen / elo

An R package to calculate Elo ratings
https://eheinzen.github.io/elo/
37 stars 3 forks source link

[BUG] elo.run.multiteam ignores initial.elos #62

Open BenoitLondon opened 8 months ago

BenoitLondon commented 8 months ago

Hi, first thanks for this great package, it is very interesting and nicely designed!

I ran into the issue with elo.run.multiteam where it ignores intial ratings so for now I rewrote the function to pass it to elo.run (not sure it s the correct way but looks ok)

elo.run.multiteam2 <- function (formula, data, na.action, subset, k = NULL, initial.elos = NULL, 
          ...) 
{
    Call <- match.call()
    Call[[1L]] <- quote(elo::elo.model.frame)
    Call$required.vars <- c("elos", "k", "group", "regress")
    Call$ncol.k <- 2
    Call$ncol.elos <- 1
    mf <- eval(Call, parent.frame())
    if (nrow(mf) == 0) 
        stop("No (non-missing) observations")
    Terms <- stats::terms(mf)
    if (any(mf$adjust.A != 0)) 
        warning("Any adjustments using 'adjust()' are being ignored.")
    mf2 <- multiteam_model_frame(mf)
    er <- elo.run(wins.A ~ elo.A + elo.B + k(k) + group(group) + 
                      regress(regress, to = attr(mf$regress, "to"), by = attr(mf$regress, 
                                                                              "by")), data = mf2, 
                  initial.elos = initial.elos,...)
    er$Call <- Call
    er$terms <- Terms
    er$na.action <- stats::na.action(mf)
    er$n.matches <- nrow(mf)
    class(er) <- c("elo.run.multiteam", class(er))
    er
}