3

I am using the elo package in R to calculate college football scores over the course of several decades. But I am having trouble understanding the regression function in the package:

This is the example given in the package documentation:

tournament$elo.Visitor <- 1500
elo.run(score(points.Home, points.Visitor) ~ team.Home + elo.Visitor +
    regress(half, 1500, 0.2),
    data = tournament, k = 20)

"Giving a logical vector identifies these matches after which to regress back to the mean. Giving any other kind of vector regresses after the appropriate groupings (see, e.g., duplicated(..., fromLast = TRUE)). The other two arguments determine what Elo to regress to (to =), and by how much to regress toward that value (by =)."

I have tried to enter "regress(half, 1500, 0.2)" on my computer but R does not recognize "half". What are they putting in there to make their regression work?

kjetil b halvorsen
  • 63,378
  • 26
  • 142
  • 467

1 Answers1

1

Notice that half is a variable in the dataset tournament:

library(elo)
data(tournament)
str(tournament)

>  'data.frame':    56 obs. of  7 variables: 
>  $ team.Home     : chr  "Blundering Baboons" "Defense-less Dogs" "Fabulous Frogs" "Helpless Hyenas" ...
>  $ team.Visitor  : chr  "Athletic Armadillos" "Cunning Cats" "Elegant Emus" "Gallivanting Gorillas" ...
$ points.Home   : num  14 21 15 13 22 18 20 23 25 23 ...
$ points.Visitor: num  22 18 11 15 13 20 22 10 16 18 ...
$ week          : num  1 1 1 1 2 2 2 2 3 3 ...
$ half          : chr  "First Half of Season" "First Half of Season" "First Half of Season" "First Half of Season" ...
$ elo.Visitor   : num  1500 1500 1500 1500 1500 1500 1500 1500 1500 1500 ...

tournament$elo.Visitor <- 1500
elo.run(score(points.Home, points.Visitor) ~ team.Home + elo.Visitor +
      regress(half, 1500, 0.2),
    data = tournament, k = 20)

An object of class 'elo.run.regressed', containing information on 8 teams and 56 matches, with 2 regressions.

So you just have to use (or more likely create) the relevant variable name(s) in your own dataset:

Robert Long
  • 53,316
  • 10
  • 84
  • 148
  • Hi Robert, so if I group them by a variable such asseason, it will regress by the end of the season? –  Oct 18 '18 at 17:07
  • @AlexElfering yes, it looks that way - just play around with the example and feed it different vectors and you should be able to understand exactly what it is doing ? – Robert Long Oct 19 '18 at 07:34