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 type in round_rank(): "desc" or "asc".

ties

Value for ties in round_rank().

round_digits

Value for round_digits in round_rank().

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:

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:

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:

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)


[Package comperank version 0.1.1 Index]