gobbios / EloRating

Animal dominance hierarchies
4 stars 0 forks source link

elo.seq(init = "bottom") not working as expected #5

Open ckimock opened 3 years ago

ckimock commented 3 years ago

Hi - I've been using the init = "bottom" argument in elo.seq() to calculate Elo Ratings and it doesn't seem to be working as expected. When I've been using the argument, animals entering the hierarchy are not assigned the lowest ratings - they are assigned the average rating. I've attached a pdf of code output to illustrate this. Any and all assistance would be greatly appreciated! EloSeq-issue.pdf

gobbios commented 3 years ago

It works now for the example data set:

xdata <- read.table(system.file("ex-sequence.txt", package = "EloRating"), header = TRUE)
xpres <- read.table(system.file("ex-presence.txt", package = "EloRating"), header = TRUE)
xpres$Date <- as.Date(xpres$Date)
res <- elo.seq(xdata$winner, xdata$loser, xdata$Date, presence = xpres, init = "bottom")
eloplot(res)

or numerically:

extract_elo(res, extractdate = "2000-05-31")
   c    a    d    f    k    g    n    w    z 
1327 1210 1139 1128  995  935  809  768  506 
extract_elo(res, extractdate = "2000-06-01")
   c    d    f    a    k    g    n    w    s    z 
1327 1139 1128 1111  995  935  809  768  605  506 

Confirm using the group's lowest rating on the day before s's appearance (which will be s's initial rating) and the opponent's rating of s (a) on the day produces s's rating:

e.single(506, 1210, 1)
[1]  605 1111
ckimock commented 3 years ago

The code is now working for my data as well. Thank you!