iterative {comperank} | R Documentation |
Iterative rating method
Description
Functions to compute Iterative numeric ratings, i.e. which are recomputed after every game, and corresponding rankings.
Usage
rate_iterative(cr_data, rate_fun, initial_ratings = 0)
rank_iterative(cr_data, rate_fun, initial_ratings = 0, keep_rating = FALSE,
type = "desc", ties = c("average", "first", "last", "random", "max",
"min"), round_digits = 7)
add_iterative_ratings(cr_data, rate_fun, initial_ratings = 0)
Arguments
cr_data |
Competition results in format ready for as_longcr(). |
rate_fun |
Rating function (see Details). |
initial_ratings |
Initial ratings (see Details). |
keep_rating |
Whether to keep rating column in ranking output. |
type |
Value for |
ties |
Value for |
round_digits |
Value for |
Details
Iterative ratings of group of players are recomputed after every
game based on players' game scores and their ratings just before the game.
Theoretically this kind of ratings can be non-numeric and be computed on
competition results with variable number of players but they rarely do. This
package provides functions for computing iterative numeric ratings for
pairgames (competition results with games only
between two players). Error is thrown if cr_data
is not pairgames.
Games in widecr form are arranged in increasing order
of values in column game
(if it is present) and processed from first to
last row.
NA
values in column player
are allowed. These players are treated as
'ghosts': players of the same rating as opponent before the game. 'Ghosts'
are not actual players so they don't appear in the output of
rate_iterative()
. For games between two 'ghosts' ratings before and after
the game are set to 0.
The core of the rating system is rate_fun
. It should take the
following arguments:
-
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_fun
should return a numeric vector of length 2: first element being a
rating of player1 after the game, second - of player2.
Ratings are computed based only on games between players of interest (see
Players) and NA
values.
Initial ratings should be defined with argument initial_ratings
. It
can be:
A single numeric value. In this case initial ratings for all players are set to this value.
A named vector of ratings. All non-
NA
players, for which rating is computed, should be present in its names (as character representation of players' actual identifiers).A data frame with first column representing player and second - initial rating. It will be converted to named vector with deframe() from
tibble
package.
Value
rate_iterative()
returns a tibble with columns
player
(player identifier) and rating_iterative
(Iterative
ratings, based on row order, by the end of competition
results). Interpretation of numbers depends on rating function
rate_fun
.
rank_iterative()
returns a tibble
with columns player
,
rating_iterative
(if keep_rating = TRUE
) and ranking_iterative
(Iterative ranking computed with round_rank()
based on
specified type
).
add_iterative_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.
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.
Examples
test_rate_fun <- function(rating1, score1, rating2, score2) {
c(rating1, rating2) + ((score1 >= score2) * 2 - 1) * c(1, -1)
}
set.seed(1002)
cr_data <- data.frame(
game = rep(1:10, each = 2),
player = rep(1:5, times = 4),
score = runif(20)
)
cr_data$player[c(6, 8)] <- NA
# Different settings of add_iterative_ratings
add_iterative_ratings(cr_data, test_rate_fun)
add_iterative_ratings(cr_data, test_rate_fun, initial_ratings = 10)
add_iterative_ratings(
cr_data, test_rate_fun,
initial_ratings = c("1" = 1, "2" = 2, "3" = 3, "4" = 4, "5" = 5)
)
add_iterative_ratings(
cr_data, test_rate_fun,
initial_ratings = data.frame(1:5, 0:4)
)
# Ratings and ranking at the end of competition results.
rate_iterative(cr_data, test_rate_fun)
rank_iterative(cr_data, test_rate_fun, type = "desc")
rank_iterative(cr_data, test_rate_fun, type = "desc", keep_rating = TRUE)