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)
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. |
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.
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
(if score1
> score2
), S = 0.5
(if score1
== score2
) and
S = 0
(if score1
< score2
).
Rating delta is computed: d = K * (S - P)
. The more the K
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.
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.
Wikipedia page for Elo rating system.
# Elo ratings
rate_elo(ncaa2005)#> # A tibble: 5 x 2
#> player rating_elo
#> <chr> <dbl>
#> 1 Duke -56.2
#> 2 Miami 57.9
#> 3 UNC -1.26
#> 4 UVA -29.2
#> 5 VT 28.8
rank_elo(ncaa2005)#> # A tibble: 5 x 2
#> player ranking_elo
#> <chr> <dbl>
#> 1 Duke 5
#> 2 Miami 1
#> 3 UNC 3
#> 4 UVA 4
#> 5 VT 2
rank_elo(ncaa2005, keep_rating = TRUE)#> # A tibble: 5 x 3
#> player rating_elo ranking_elo
#> <chr> <dbl> <dbl>
#> 1 Duke -56.2 5
#> 2 Miami 57.9 1
#> 3 UNC -1.26 3
#> 4 UVA -29.2 4
#> 5 VT 28.8 2
add_elo_ratings(ncaa2005, initial_ratings = 100)#> # A widecr object:
#> # A tibble: 10 x 9
#> game player1 score1 player2 score2 rating1Before rating2Before rating1After
#> <int> <chr> <int> <chr> <int> <dbl> <dbl> <dbl>
#> 1 1 Duke 7 Miami 52 100 100 85
#> 2 2 Duke 21 UNC 24 85 100 70.6
#> 3 3 Duke 7 UVA 38 70.6 100 56.9
#> 4 4 Duke 0 VT 45 56.9 100 43.8
#> 5 5 Miami 34 UNC 16 115 114. 130.
#> 6 6 Miami 25 UVA 17 130. 114. 144.
#> 7 7 Miami 27 VT 7 144. 113. 158.
#> 8 8 UNC 7 UVA 5 99.4 99.4 114.
#> 9 9 UNC 3 VT 30 114. 99.5 98.7
#> 10 10 UVA 14 VT 52 84.4 115. 70.8
#> # … with 1 more variable: rating2After <dbl>
# Elo function
elo((0:12)*100, 1, 0, 0)#> [,1] [,2]
#> [1,] 15.0000 -15.00000000
#> [2,] 110.7981 -10.79805001
#> [3,] 207.2076 -7.20759220
#> [4,] 304.5294 -4.52938672
#> [5,] 402.7273 -2.72727273
#> [6,] 501.5972 -1.59720646
#> [7,] 600.9196 -0.91960290
#> [8,] 700.5242 -0.52416274
#> [9,] 800.2970 -0.29702970
#> [10,] 900.1678 -0.16775902
#> [11,] 1000.0946 -0.09456928
#> [12,] 1100.0533 -0.05325368
#> [13,] 1200.0300 -0.02997003elo((0:12)*100, 1, 0, 0, K = 10)#> [,1] [,2]
#> [1,] 5.0000 -5.00000000
#> [2,] 103.5994 -3.59935000
#> [3,] 202.4025 -2.40253073
#> [4,] 301.5098 -1.50979557
#> [5,] 400.9091 -0.90909091
#> [6,] 500.5324 -0.53240215
#> [7,] 600.3065 -0.30653430
#> [8,] 700.1747 -0.17472091
#> [9,] 800.0990 -0.09900990
#> [10,] 900.0559 -0.05591967
#> [11,] 1000.0315 -0.03152309
#> [12,] 1100.0178 -0.01775123
#> [13,] 1200.0100 -0.00999001elo((0:12)*10, 1, 0, 0, ksi = 40)#> [,1] [,2]
#> [1,] 15.00000 -15.00000000
#> [2,] 20.79805 -10.79805001
#> [3,] 27.20759 -7.20759220
#> [4,] 34.52939 -4.52938672
#> [5,] 42.72727 -2.72727273
#> [6,] 51.59721 -1.59720646
#> [7,] 60.91960 -0.91960290
#> [8,] 70.52416 -0.52416274
#> [9,] 80.29703 -0.29702970
#> [10,] 90.16776 -0.16775902
#> [11,] 100.09457 -0.09456928
#> [12,] 110.05325 -0.05325368
#> [13,] 120.02997 -0.02997003