elo {comperank} | R Documentation |
Elo method
Description
Functions to compute rating and ranking using Elo method.
Usage
rate_elo(cr_data, K = 30, ksi = 400, initial_ratings = 0)
rank_elo(cr_data, K = 30, ksi = 400, initial_ratings = 0,
keep_rating = FALSE, ties = c("average", "first", "last", "random", "max",
"min"), round_digits = 7)
add_elo_ratings(cr_data, K = 30, ksi = 400, initial_ratings = 0)
elo(rating1, score1, rating2, score2, K = 30, ksi = 400)
Arguments
cr_data |
Competition results in format ready for as_longcr(). |
K |
K-factor for Elo formula. |
ksi |
Normalization coefficient for Elo formula. |
initial_ratings |
Initial ratings (see Iterative ratings). |
keep_rating |
Whether to keep rating column in ranking output. |
ties |
Value for |
round_digits |
Value for |
rating1 |
Rating of player1 before the game. |
score1 |
Score of player1 in the game. |
rating2 |
Rating of player2 before the game. |
score2 |
Score of player2 in the game. |
Details
rate_elo()
and add_elo_ratings()
are wrappers for
rate_iterative()
and add_iterative_ratings()
correspondingly. Rate
function is based on Elo algorithm of updating ratings:
Probability of player1 (with rating r1) winning against player2 (with rating r2) is computed based on rating difference and sigmoid function:
P = 1 / (1 + 10^( (r2 - r1) / ksi ) )
.ksi
defines the spread of ratings.Result of the game from player1 perspective is computed based on rule:
S = 1
(ifscore1
>score2
),S = 0.5
(ifscore1
==score2
) andS = 0
(ifscore1
<score2
).Rating delta is computed:
d = K * (S - P)
. The more theK
the more the delta (with other being equal).New ratings are computed:
r1_new = r1 + d
,r2_new = r2 - d
.
elo()
function implements this algorithm. It is vectorized over all its
arguments with standard R recycling functionality. Note that not this
function is used in rate_elo()
and add_elo_ratings()
because of its not
appropriate output format, but rather its non-vectorized reimplementation is.
Ratings are computed based only on games between players of interest (see
Players) and NA
values.
Value
rate_elo()
returns a tibble with columns
player
(player identifier) and rating_elo
(Elo
ratings, based on row order, by the end of competition
results). Bigger value indicates better player performance.
rank_elo()
returns a tibble
with columns player
, rating_elo
(if
keep_rating = TRUE
) and ranking_elo
(Elo ranking
computed with round_rank()
).
add_elo_ratings()
returns a widecr form of cr_data
with four rating columns added:
-
rating1Before - Rating of player1 before the game.
-
rating2Before - Rating of player2 before the game.
-
rating1After - Rating of player1 after the game.
-
rating2After - Rating of player2 after the game.
elo()
always returns a matrix with two columns containing ratings after the
game. Rows represent games, columns - players.
Players
comperank
offers a possibility to handle certain set of players. It is done
by having player
column (in longcr format) as factor
with levels specifying all players of interest. In case of factor the result
is returned only for players from its levels. Otherwise - for all present
players.
References
Wikipedia page for Elo rating system.
Examples
# Elo ratings
rate_elo(ncaa2005)
rank_elo(ncaa2005)
rank_elo(ncaa2005, keep_rating = TRUE)
add_elo_ratings(ncaa2005, initial_ratings = 100)
# Elo function
elo((0:12)*100, 1, 0, 0)
elo((0:12)*100, 1, 0, 0, K = 10)
elo((0:12)*10, 1, 0, 0, ksi = 40)