diff --git a/.Rbuildignore b/.Rbuildignore index cace7fd..448bf13 100755 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -18,3 +18,4 @@ TODO \.xcf ^docs$ ^\.github$ +.lintr$ diff --git a/.lintr b/.lintr index 6525b6a..54ccdd4 100644 --- a/.lintr +++ b/.lintr @@ -1,6 +1,4 @@ linters: linters_with_defaults( line_length_linter(100L) ) -exclusions: list( - "data-raw" -) +exclusions: list("data-raw") diff --git a/DESCRIPTION b/DESCRIPTION index 2933001..196efab 100755 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -35,6 +35,7 @@ Language: en-US URL: https://github.com/gogonzo/sport LazyData: true RoxygenNote: 7.2.3 +Roxygen: list(markdown = TRUE) Suggests: dplyr, knitr, diff --git a/R/data.R b/R/data.R index 60acedd..2c100a4 100755 --- a/R/data.R +++ b/R/data.R @@ -1,21 +1,21 @@ #' Heat results of Speedway Grand-Prix #' #' Actual dataset containing heats results of all Speedway Grand-Prix turnaments -#' \code{gpheats}. +#' `gpheats`. #' #' @format A data frame with >19000 rows and 11 variables: #' \describe{ -#' \item{id}{event identifier} -#' \item{season}{year of Grand-Prix, 1995-now} -#' \item{date}{date of turnament} -#' \item{round}{round in season} -#' \item{name}{Turnament name} -#' \item{heat}{heat number, 1-23} -#' \item{field}{number of gate, 1-4} -#' \item{rider}{rider name, string} -#' \item{points}{paints gained, integer} -#' \item{position}{position at finish line, string} -#' \item{rank}{rank at finish line, integer} +#' - `id` - event identifier +#' - `season` - year of Grand-Prix, 1995-now +#' - `date` - date of turnament +#' - `round` - round in season +#' - `name` - Turnament name +#' - `heat` - heat number, 1-23 +#' - `field` - number of gate, 1-4 +#' - `rider` - rider name, string +#' - `points` - paints gained, integer +#' - `position` - position at finish line, string +#' - `rank` - rank at finish line, integer #' } #' @source internal #' @name gpheats @@ -24,19 +24,19 @@ NULL #' Turnament results of Speedway Grand-Prix #' #' Actual dataset containing turnament results of all Speedway Grand-Prix events -#' \code{gpsquads} +#' `gpsquads` #' #' @format A data frame with >4000 rows and 9 variables: #' \describe{ -#' \item{id}{event identifier} -#' \item{season}{year of Grand-Prix, 1995-now} -#' \item{date}{date of turnament} -#' \item{place}{stadium of event} -#' \item{round}{round in season} -#' \item{name}{Turnament name} -#' \item{rider}{rider names, 1-6} -#' \item{points}{points gained, integer} -#' \item{classification}{classification after an event} +#' - `id` - event identifier +#' - `season` - year of Grand-Prix, 1995-now +#' - `date` - date of turnament +#' - `place` - stadium of event +#' - `round` - round in season +#' - `name` - Turnament name +#' - `rider` - rider names, 1-6 +#' - `points` - points gained, integer +#' - `classification` - classification after an event #' } #' @source internal #' @name gpsquads diff --git a/R/output.R b/R/output.R index 4730570..763ed93 100755 --- a/R/output.R +++ b/R/output.R @@ -10,20 +10,20 @@ NULL #' @param object of class rating #' @param ... optional arguments #' @return -#' List with following elements \itemize{ -#' \item \code{formula} modeled formula. -#' \item \code{method} type of algorithm used. -#' \item \code{Overall Accuracy} named vector containing players ratings. -#' \item \code{r} data.frame summarized players ratings and model winning probabilities. Probabilities are returned only in models with one variable (ratings) \itemize{ -#' \item \code{name} of a player -#' \item \code{r} players ratings -#' \item \code{rd} players ratings deviation -#' \item \code{`Model probability`} mean predicted probability of winning the challenge by the player. -#' \item \code{`True probability`} mean observed probability of winning the challenge by the player. -#' \item \code{`Accuracy`} Accuracy of prediction. -#' \item \code{`pairings`} number of pairwise occurrences. -#' } -#' } +#' List with following elements: +#' - `formula` modeled formula. +#' - `method` type of algorithm used. +#' - `Overall Accuracy` named vector containing players ratings. +#' - `r` data.frame summarized players ratings and model winning probabilities. +#' +#' Probabilities are returned only in models with one variable (ratings): +#' - `name` of a player +#' - `r` players ratings +#' - `rd` players ratings deviation +#' - `Model probability` mean predicted probability of winning the challenge by the player. +#' - `True probability` mean observed probability of winning the challenge by the player. +#' - `Accuracy` Accuracy of prediction. +#' - `pairings` number of pairwise occurrences. #' #' @examples #' model <- glicko_run( @@ -141,7 +141,7 @@ plot.rating <- function(x, n = 10, players, ...) { names(data)[1] <- variable data <- data[order(data$r, decreasing = TRUE), ][1:n, ] - data[[variable]] <- reorder(data[[variable]], nrow(data):1) + data[[variable]] <- reorder(data[[variable]], rev(seq_len(nrow(data)))) ggplot(data, aes(x = .data[[variable]], y = .data$r)) + ggtitle("Actual ratings") + geom_linerange( diff --git a/R/predict.R b/R/predict.R index cf2ab1b..0ec5614 100755 --- a/R/predict.R +++ b/R/predict.R @@ -13,7 +13,7 @@ #' predict(glicko, gpheats[17:20, ]) #' @export predict.rating <- function(object, newdata, ...) { - if (missing(newdata)) stop("newdata is requested to predict", call. = F) + if (missing(newdata)) stop("newdata is requested to predict", call. = FALSE) method <- attr(object, "method") formula <- attr(object, "formula") all_vars <- all.vars(formula) @@ -89,8 +89,8 @@ predict.rating <- function(object, newdata, ...) { ) } - P <- model$pairs # data.table - P <- P[, Y := ifelse(P > .5, 1, ifelse(P == .5, .5, 0))] + pairs <- model$pairs # data.table + pairs <- pairs[, Y := ifelse(P > .5, 1, ifelse(P == .5, .5, 0))] - return(P) + return(pairs) } diff --git a/R/rating_run.R b/R/rating_run.R index a31cf0c..8d54140 100755 --- a/R/rating_run.R +++ b/R/rating_run.R @@ -7,38 +7,38 @@ NULL #' #' Apply rating algorithm #' @param formula formula which specifies the model. RHS Allows only player -#' rating parameter and it should be specified in following manner: +#' rating parameter and it should be specified in following manner:\cr #' -#' \code{rank | id ~ player(name)}. -#' \itemize{ -#' \item {rank} player position in event. -#' \item {id} event identifier in which pairwise comparison is assessed. -#' \item {player(name)} name of the contestant. In this case \code{player(name)} +#' `rank | id ~ player(name)`. +#' - `rank` player position in event. +#' - `id` event identifier in which pairwise comparison is assessed. +#' - `player(name)` name of the contestant. In this case `player(name)` #' helps algorithm point name of the column where player names are stored. -#' } -#' Users can also specify formula in in different way: -#' \code{rank | id ~ player(name|team)}. Which means that players are playing in teams, +#' +#' Users can also specify formula in in different way:\cr +#' +#' `rank | id ~ player(name|team)`. Which means that players are playing in teams, #' and results are observed for teams not for players. For more see vignette. #' -#' @param method one of \code{c("glicko", "glicko2", "bbt", "dbl")} +#' @param method one of `c("glicko", "glicko2", "bbt", "dbl")` #' #' @param data data.frame which contains columns specified in formula, and -#' optional columns defined by \code{lambda}, \code{weight}. +#' optional columns defined by `lambda`, `weight`. #' #' @param r named vector of initial players ratings estimates. If not specified -#' then \code{r} will be created automatically for parameters specified in \code{formula} -#' with initial value \code{init_r}. +#' then `r` will be created automatically for parameters specified in `formula` +#' with initial value `init_r`. #' #' @param rd rd named vector of initial rating deviation estimates. If not specified -#' then \code{rd} will be created automatically for parameters specified in \code{formula} -#' with initial value \code{init_rd}. +#' then `rd` will be created automatically for parameters specified in `formula` +#' with initial value `init_rd`. #' #' @param sigma (only for glicko2) named vector of initial players ratings -#' estimates. If not specified then \code{sigma} will be created automatically for -#' parameters specified in \code{formula} with initial value \code{init_sigma}. +#' estimates. If not specified then `sigma` will be created automatically for +#' parameters specified in `formula` with initial value `init_sigma`. #' #' @param lambda name of the column in `data` containing lambda values or one -#' constant value (eg. \code{lambda = colname} or \code{lambda = 0.5}). +#' constant value (eg. `lambda = colname` or `lambda = 0.5`). #' Lambda impact prior variance, and uncertainty of the matchup result. The #' higher lambda, the higher prior variance and more uncertain result of the #' matchup. Higher lambda flattens chances of winning. @@ -50,29 +50,29 @@ NULL #' #' #' @param weight name of the column in `data` containing weights values or -#' one constant (eg. \code{weight = colname} or \code{weight = 0.5}). +#' one constant (eg. `weight = colname` or `weight = 0.5`). #' Weights increasing (weight > 1) or decreasing (weight < 1) update change. #' Higher weight increasing impact of event result on rating estimate. #' -#' @param kappa controls \code{rd} shrinkage not to be greater than \code{rd*(1 - kappa)}. -#' `kappa=1` means that \code{rd} will not be decreased. +#' @param kappa controls `rd` shrinkage not to be greater than `rd*(1 - kappa)`. +#' `kappa=1` means that `rd` will not be decreased. #' @param tau The system constant. Which constrains the change in volatility over -#' time. Reasonable choices are between 0.3 and 1.2 (\code{default = 0.5}), though +#' time. Reasonable choices are between 0.3 and 1.2 (`default = 0.5`), though #' the system should be tested to decide which value results in greatest -#' predictive accuracy. Smaller values of \code{tau} prevent the volatility measures +#' predictive accuracy. Smaller values of `tau` prevent the volatility measures #' from changing by large amounts, which in turn prevent enormous changes in #' ratings based on very improbable results. If the application of Glicko-2 is #' expected to involve extremely improbable collections of game outcomes, then -#' `tau` should be set to a small value, even as small as, say, \code{tau= 0}. +#' `tau` should be set to a small value, even as small as, say, `tau= 0`. #' -#' @param init_r initial values for \code{r} if not provided. -#' Default (\code{glicko = 1500}, \code{glicko2 = 1500}, \code{bbt = 25}, -#' \code{dbl = 0}) +#' @param init_r initial values for `r` if not provided. +#' Default (`glicko = 1500`, `glicko2 = 1500`, `bbt = 25`, +#' `dbl = 0`) #' -#' @param init_rd initial values for \code{rd} if not provided. -#' Default (\code{glicko = 350}, \code{glicko2 = 350}, \code{bbt = 25/3}, \code{dbl = 1}) +#' @param init_rd initial values for `rd` if not provided. +#' Default (`glicko = 350`, `glicko2 = 350`, `bbt = 25/3`, `dbl = 1`) #' -#' @param init_sigma initial values for \code{sigma} if not provided. +#' @param init_sigma initial values for `sigma` if not provided. #' Default = 0.5 #' @keywords internal rating_run <- function( @@ -225,24 +225,17 @@ rating_run <- function( #' #' @return #' -#' A "rating" object is returned: \itemize{ -#' -#' \item \code{final_r} named vector containing players ratings. -#' -#' \item \code{final_rd} named vector containing players ratings deviations. +#' A "rating" object is returned: #' -#' \item \code{r} data.frame with evolution of the ratings and ratings deviations +#' - `final_r` named vector containing players ratings. +#' - `final_rd` named vector containing players ratings deviations. +#' - `r` data.frame with evolution of the ratings and ratings deviations #' estimated at each event. -#' -#' \item \code{pairs} pairwise combinations of players in analysed events with +#' - `pairs` pairwise combinations of players in analysed events with #' prior probability and result of a challenge. -#' -#' \item \code{class} of the object. -#' -#' \item \code{method} type of algorithm used. -#' -#' \item \code{settings} arguments specified in function call. -#' } +#' - `class` of the object. +#' - `method` type of algorithm used. +#' - `settings` arguments specified in function call. #' #' @examples #' # the simplest example @@ -321,26 +314,18 @@ glicko_run <- function(data, formula, #' #' @return #' -#' A "rating" object is returned: \itemize{ +#' A "rating" object is returned: #' -#' \item \code{final_r} named vector containing players ratings. -#' -#' \item \code{final_rd} named vector containing players ratings deviations. -#' -#' \item \code{final_sigma} named vector containing players ratings volatile. -#' -#' \item \code{r} data.frame with evolution of the ratings and ratings deviations -#' estimated at each event. -#' -#' \item \code{pairs} pairwise combinations of players in analysed events with +#' - `final_r` named vector containing players ratings. +#' - `final_rd` named vector containing players ratings deviations. +#' - `final_sigma` named vector containing players ratings volatile. +#' - `r` data.frame with evolution of the ratings and ratings deviations +#' estimated at each event. +#' - `pairs` pairwise combinations of players in analysed events with #' prior probability and result of a challenge. -#' -#' \item \code{class} of the object. -#' -#' \item \code{method} type of algorithm used. -#' -#' \item \code{settings} arguments specified in function call. -#' } +#' - `class` of the object. +#' - `method` type of algorithm used. +#' - `settings` arguments specified in function call. #' #' @examples #' # the simplest example @@ -428,24 +413,16 @@ glicko2_run <- function(formula, #' #' @return #' -#' A "rating" object is returned: \itemize{ -#' -#' \item \code{final_r} named vector containing players ratings. -#' -#' \item \code{final_rd} named vector containing players ratings deviations. -#' -#' \item \code{r} data.frame with evolution of the ratings and ratings deviations +#' A "rating" object is returned: +#' - `final_r` named vector containing players ratings. +#' - `final_rd` named vector containing players ratings deviations. +#' - `r` data.frame with evolution of the ratings and ratings deviations #' estimated at each event. -#' -#' \item \code{pairs} pairwise combinations of players in analysed events with +#' - `pairs` pairwise combinations of players in analysed events with #' prior probability and result of a challenge. -#' -#' \item \code{class} of the object. -#' -#' \item \code{method} type of algorithm used. -#' -#' \item \code{settings} arguments specified in function call. -#' } +#' - `class` of the object. +#' - `method` type of algorithm used. +#' - `settings` arguments specified in function call. #' #' @examples #' # the simplest example @@ -531,24 +508,17 @@ bbt_run <- function(formula, #' #' @return #' -#' A "rating" object is returned: \itemize{ -#' -#' \item \code{final_r} named vector containing players ratings. -#' -#' \item \code{final_rd} named vector containing players ratings deviations. -#' -#' \item \code{r} data.frame with evolution of the ratings and ratings deviations +#' A "rating" object is returned: +#' - `final_r` named vector containing players ratings. +#' - `final_rd` named vector containing players ratings deviations. +#' - `r` data.frame with evolution of the ratings and ratings deviations #' estimated at each event. -#' -#' \item \code{pairs} pairwise combinations of players in analysed events with +#' - `pairs` pairwise combinations of players in analysed events with #' prior probability and result of a challenge. -#' -#' \item \code{class} of the object. -#' -#' \item \code{method} type of algorithm used. -#' -#' \item \code{settings} arguments specified in function call. -#' } +#' - `class` of the object. +#' - `method` type of algorithm used. +#' - `settings` arguments specified in function call. +# #' #' @examples #' # the simplest example @@ -594,10 +564,10 @@ dbl_run <- function(formula, terms <- get_terms(data, formula) - MAP <- get_terms_map(data, terms) - X <- get_terms_mat(data, terms) + map <- get_terms_map(data, terms) + x <- get_terms_mat(data, terms) cls <- get_terms_cls(data, terms) - unique_params <- unname(unlist(apply(MAP, 2, unique))) + unique_params <- unname(unlist(apply(map, 2, unique))) team <- get_team_name(formula) team_vec <- as.character(data[[team]]) @@ -611,15 +581,13 @@ dbl_run <- function(formula, if (is.null(kappa)) kappa <- 0.0001 - - g <- dbl( unique_id = unique(id_vec), id_vec = id_vec, rank_vec = rank_vec, team_vec = team_vec, - MAP = as.matrix(MAP), - X = as.matrix(X), + MAP = as.matrix(map), + X = as.matrix(x), cls = cls, R = r, RD = rd, diff --git a/R/terms.R b/R/terms.R index 5988f5b..23ba600 100755 --- a/R/terms.R +++ b/R/terms.R @@ -14,10 +14,12 @@ is_lhs_valid <- function(formula, data) { if (length(all.vars(update(formula, . ~ 0))) == 1) { warning("LHS of formula doesn't contain `| id` element. It will be assummed that all belongs to the same event id", - call. = F + call. = FALSE ) - } else if (length(all.vars(update(formula, . ~ 0))) == 2 & - !grepl("[|]", format(update(formula, . ~ 0)))) { + } else if ( + length(all.vars(update(formula, . ~ 0))) == 2 && + !grepl("[|]", format(update(formula, . ~ 0))) + ) { stop("LHS of formula must be seperated by `|` operator eg. `rank | id ~ .`", call. = FALSE ) @@ -62,8 +64,7 @@ is_team_term_valid <- function(formula, single) { team_term_vars <- gsub("player\\(|\\)", "", team_term) team_term_vars <- trimws(unlist(strsplit(x = team_term_vars, split = "[|]"))) - if (!length(team_term_vars) %in% c(1, 2) && - all(team_term_vars != "")) { + if (!length(team_term_vars) %in% c(1, 2) && all(team_term_vars != "")) { stop("Only one or two variables are allowed within player(...) term function: Please specify as one of following: * player(player_var | team_var) diff --git a/R/utils.R b/R/utils.R index 0622ced..46c43ee 100755 --- a/R/utils.R +++ b/R/utils.R @@ -38,7 +38,8 @@ check_numeric_argument <- function(x, var_name, min = -Inf, max = Inf) { call. = FALSE ) } else if (any(!is.finite(x))) { - stop(sprintf("Variable %s contains non-finite values. All elements should be finite.", var_name), + stop( + sprintf("Variable %s contains non-finite values. All elements should be finite.", var_name), call. = FALSE ) } else if (any(x < min | x > max)) { @@ -69,11 +70,10 @@ check_integer_argument <- function(x, var_name, min = -Inf, max = Inf) { check_string_argument <- function(x, var_name) { if (!is.character(x)) { - stop(sprintf("Variable %s should be of type character.", var_name), - call. = FALSE - ) + stop(sprintf("Variable %s should be of type character.", var_name), call. = FALSE) } else if (any(is.na(x))) { - stop(sprintf("Variable %s contains non-finite values. All elements should be finite.", var_name), + stop( + sprintf("Variable %s contains non-finite values. All elements should be finite.", var_name), call. = FALSE ) } @@ -232,14 +232,15 @@ initialize_vec <- function(var, data, argname, min = -Inf, max = Inf) { var, argname )) } - var_vec <- data[[var]] # 1/n_it + var_vec <- data[[var]] # 1 divided by n_it check_numeric_argument(var_vec, var, min = min, max = max) } else if (is.numeric(var) && length(var) == 1) { check_numeric_argument(var, argname, min = min, max = max) var_vec <- rep(var, nrow(data)) } else { - stop(sprintf("%s should be variable name from `data` argument or - single numeric value.", argname)) + stop( + sprintf("%s should be variable name from `data` argument or single numeric value.", argname) + ) } return(var_vec) diff --git a/data-raw/ranking.R b/data-raw/ranking.R index 0e2fefb..a46f3f3 100755 --- a/data-raw/ranking.R +++ b/data-raw/ranking.R @@ -2,13 +2,13 @@ #' #' Ranks multiple inputs with custom options #' -#' @param a vector of attributes with prefix \code{a*} as variable to be ranked. Multiple arguments can be provided like \code{a1}, \code{a2}, ... \code{a10}. All arguments will be examined in given order to obtain ranking. If some observation have the same attribute (tie) then next argument will be decisive about ranking etc. -#' @param b vector of attributes with prefix \code{b*} -#' @param x vector with non-NA value pointing for an excluded from ranking. Ranking for \code{!is.na(x)} is being set to \code{NA} and others are updated +#' @param a vector of attributes with prefix `a*` as variable to be ranked. Multiple arguments can be provided like `a1`, `a2`, ... `a10`. All arguments will be examined in given order to obtain ranking. If some observation have the same attribute (tie) then next argument will be decisive about ranking etc. +#' @param b vector of attributes with prefix `b*` +#' @param x vector with non-NA value pointing for an excluded from ranking. Ranking for `!is.na(x)` is being set to `NA` and others are updated #' @param ties method of dealing with ties. Available 'first' and default='none' #' #' @return A list with the elements -#' \item{y}{The sum of the squared values.} +#' - `y` - The sum of the squared values. #' @note This is a very simple function. #' @examples #' df <- diff --git a/man/bbt_run.Rd b/man/bbt_run.Rd index 2c1df3c..8700b83 100755 --- a/man/bbt_run.Rd +++ b/man/bbt_run.Rd @@ -19,18 +19,20 @@ bbt_run( } \arguments{ \item{formula}{formula which specifies the model. RHS Allows only player -rating parameter and it should be specified in following manner: +rating parameter and it should be specified in following manner:\cr \code{rank | id ~ player(name)}. \itemize{ - \item {rank} player position in event. - \item {id} event identifier in which pairwise comparison is assessed. - \item {player(name)} name of the contestant. In this case \code{player(name)} - helps algorithm point name of the column where player names are stored. +\item \code{rank} player position in event. +\item \code{id} event identifier in which pairwise comparison is assessed. +\item \code{player(name)} name of the contestant. In this case \code{player(name)} +helps algorithm point name of the column where player names are stored. } -Users can also specify formula in in different way: - \code{rank | id ~ player(name|team)}. Which means that players are playing in teams, - and results are observed for teams not for players. For more see vignette.} + +Users can also specify formula in in different way:\cr + +\code{rank | id ~ player(name|team)}. Which means that players are playing in teams, +and results are observed for teams not for players. For more see vignette.} \item{data}{data.frame which contains columns specified in formula, and optional columns defined by \code{lambda}, \code{weight}.} @@ -50,42 +52,36 @@ Default (\code{glicko = 1500}, \code{glicko2 = 1500}, \code{bbt = 25}, \item{init_rd}{initial values for \code{rd} if not provided. Default (\code{glicko = 350}, \code{glicko2 = 350}, \code{bbt = 25/3}, \code{dbl = 1})} -\item{lambda}{name of the column in `data` containing lambda values or one +\item{lambda}{name of the column in \code{data} containing lambda values or one constant value (eg. \code{lambda = colname} or \code{lambda = 0.5}). Lambda impact prior variance, and uncertainty of the matchup result. The higher lambda, the higher prior variance and more uncertain result of the matchup. Higher lambda flattens chances of winning.} -\item{share}{name of the column in `data` containing player share in team +\item{share}{name of the column in \code{data} containing player share in team efforts. It's used to first calculate combined rating of the team and then redistribute ratings update back to players level. Warning - it should -be used only if formula is specified with players nested within teams (`player(player|team)`).} +be used only if formula is specified with players nested within teams (\code{player(player|team)}).} -\item{weight}{name of the column in `data` containing weights values or +\item{weight}{name of the column in \code{data} containing weights values or one constant (eg. \code{weight = colname} or \code{weight = 0.5}). Weights increasing (weight > 1) or decreasing (weight < 1) update change. Higher weight increasing impact of event result on rating estimate.} \item{kappa}{controls \code{rd} shrinkage not to be greater than \code{rd*(1 - kappa)}. -`kappa=1` means that \code{rd} will not be decreased.} +\code{kappa=1} means that \code{rd} will not be decreased.} } \value{ -A "rating" object is returned: \itemize{ - +A "rating" object is returned: +\itemize{ \item \code{final_r} named vector containing players ratings. - \item \code{final_rd} named vector containing players ratings deviations. - \item \code{r} data.frame with evolution of the ratings and ratings deviations - estimated at each event. - +estimated at each event. \item \code{pairs} pairwise combinations of players in analysed events with prior probability and result of a challenge. - \item \code{class} of the object. - \item \code{method} type of algorithm used. - \item \code{settings} arguments specified in function call. } } diff --git a/man/dbl_run.Rd b/man/dbl_run.Rd index df69b2a..0494796 100755 --- a/man/dbl_run.Rd +++ b/man/dbl_run.Rd @@ -19,8 +19,8 @@ dbl_run( \arguments{ \item{formula}{formula which specifies the model. Unlike other algorithms in the packages (glicko_run, glicko2_run, bbt_run), this method doesn't allow -players nested in teams with `player(player | team)` and user should matchup -in formula using `player(player)`. DBL allows user specify multiple parameters +players nested in teams with \code{player(player | team)} and user should matchup +in formula using \code{player(player)}. DBL allows user specify multiple parameters also in interaction with others.} \item{data}{data.frame which contains columns specified in formula, and @@ -34,19 +34,19 @@ with initial value \code{init_r}.} then \code{rd} will be created automatically for parameters specified in \code{formula} with initial value \code{init_rd}.} -\item{lambda}{name of the column in `data` containing lambda values or one +\item{lambda}{name of the column in \code{data} containing lambda values or one constant value (eg. \code{lambda = colname} or \code{lambda = 0.5}). Lambda impact prior variance, and uncertainty of the matchup result. The higher lambda, the higher prior variance and more uncertain result of the matchup. Higher lambda flattens chances of winning.} -\item{weight}{name of the column in `data` containing weights values or +\item{weight}{name of the column in \code{data} containing weights values or one constant (eg. \code{weight = colname} or \code{weight = 0.5}). Weights increasing (weight > 1) or decreasing (weight < 1) update change. Higher weight increasing impact of event result on rating estimate.} \item{kappa}{controls \code{rd} shrinkage not to be greater than \code{rd*(1 - kappa)}. -`kappa=1` means that \code{rd} will not be decreased.} +\code{kappa=1} means that \code{rd} will not be decreased.} \item{init_r}{initial values for \code{r} if not provided. Default (\code{glicko = 1500}, \code{glicko2 = 1500}, \code{bbt = 25}, @@ -56,22 +56,16 @@ Default (\code{glicko = 1500}, \code{glicko2 = 1500}, \code{bbt = 25}, Default (\code{glicko = 350}, \code{glicko2 = 350}, \code{bbt = 25/3}, \code{dbl = 1})} } \value{ -A "rating" object is returned: \itemize{ - +A "rating" object is returned: +\itemize{ \item \code{final_r} named vector containing players ratings. - \item \code{final_rd} named vector containing players ratings deviations. - \item \code{r} data.frame with evolution of the ratings and ratings deviations - estimated at each event. - +estimated at each event. \item \code{pairs} pairwise combinations of players in analysed events with prior probability and result of a challenge. - \item \code{class} of the object. - \item \code{method} type of algorithm used. - \item \code{settings} arguments specified in function call. } } diff --git a/man/glicko2_run.Rd b/man/glicko2_run.Rd index 09d5984..1a83b5b 100755 --- a/man/glicko2_run.Rd +++ b/man/glicko2_run.Rd @@ -22,18 +22,20 @@ glicko2_run( } \arguments{ \item{formula}{formula which specifies the model. RHS Allows only player -rating parameter and it should be specified in following manner: +rating parameter and it should be specified in following manner:\cr \code{rank | id ~ player(name)}. \itemize{ - \item {rank} player position in event. - \item {id} event identifier in which pairwise comparison is assessed. - \item {player(name)} name of the contestant. In this case \code{player(name)} - helps algorithm point name of the column where player names are stored. +\item \code{rank} player position in event. +\item \code{id} event identifier in which pairwise comparison is assessed. +\item \code{player(name)} name of the contestant. In this case \code{player(name)} +helps algorithm point name of the column where player names are stored. } -Users can also specify formula in in different way: - \code{rank | id ~ player(name|team)}. Which means that players are playing in teams, - and results are observed for teams not for players. For more see vignette.} + +Users can also specify formula in in different way:\cr + +\code{rank | id ~ player(name|team)}. Which means that players are playing in teams, +and results are observed for teams not for players. For more see vignette.} \item{data}{data.frame which contains columns specified in formula, and optional columns defined by \code{lambda}, \code{weight}.} @@ -50,18 +52,18 @@ with initial value \code{init_rd}.} estimates. If not specified then \code{sigma} will be created automatically for parameters specified in \code{formula} with initial value \code{init_sigma}.} -\item{lambda}{name of the column in `data` containing lambda values or one +\item{lambda}{name of the column in \code{data} containing lambda values or one constant value (eg. \code{lambda = colname} or \code{lambda = 0.5}). Lambda impact prior variance, and uncertainty of the matchup result. The higher lambda, the higher prior variance and more uncertain result of the matchup. Higher lambda flattens chances of winning.} -\item{share}{name of the column in `data` containing player share in team +\item{share}{name of the column in \code{data} containing player share in team efforts. It's used to first calculate combined rating of the team and then redistribute ratings update back to players level. Warning - it should -be used only if formula is specified with players nested within teams (`player(player|team)`).} +be used only if formula is specified with players nested within teams (\code{player(player|team)}).} -\item{weight}{name of the column in `data` containing weights values or +\item{weight}{name of the column in \code{data} containing weights values or one constant (eg. \code{weight = colname} or \code{weight = 0.5}). Weights increasing (weight > 1) or decreasing (weight < 1) update change. Higher weight increasing impact of event result on rating estimate.} @@ -77,7 +79,7 @@ Default (\code{glicko = 350}, \code{glicko2 = 350}, \code{bbt = 25/3}, \code{dbl Default = 0.5} \item{kappa}{controls \code{rd} shrinkage not to be greater than \code{rd*(1 - kappa)}. -`kappa=1` means that \code{rd} will not be decreased.} +\code{kappa=1} means that \code{rd} will not be decreased.} \item{tau}{The system constant. Which constrains the change in volatility over time. Reasonable choices are between 0.3 and 1.2 (\code{default = 0.5}), though @@ -86,27 +88,20 @@ predictive accuracy. Smaller values of \code{tau} prevent the volatility measure from changing by large amounts, which in turn prevent enormous changes in ratings based on very improbable results. If the application of Glicko-2 is expected to involve extremely improbable collections of game outcomes, then -`tau` should be set to a small value, even as small as, say, \code{tau= 0}.} +\code{tau} should be set to a small value, even as small as, say, \code{tau= 0}.} } \value{ -A "rating" object is returned: \itemize{ - +A "rating" object is returned: +\itemize{ \item \code{final_r} named vector containing players ratings. - \item \code{final_rd} named vector containing players ratings deviations. - \item \code{final_sigma} named vector containing players ratings volatile. - \item \code{r} data.frame with evolution of the ratings and ratings deviations - estimated at each event. - +estimated at each event. \item \code{pairs} pairwise combinations of players in analysed events with prior probability and result of a challenge. - \item \code{class} of the object. - \item \code{method} type of algorithm used. - \item \code{settings} arguments specified in function call. } } diff --git a/man/glicko_run.Rd b/man/glicko_run.Rd index e59e15b..85023bc 100755 --- a/man/glicko_run.Rd +++ b/man/glicko_run.Rd @@ -22,18 +22,20 @@ glicko_run( optional columns defined by \code{lambda}, \code{weight}.} \item{formula}{formula which specifies the model. RHS Allows only player -rating parameter and it should be specified in following manner: +rating parameter and it should be specified in following manner:\cr \code{rank | id ~ player(name)}. \itemize{ - \item {rank} player position in event. - \item {id} event identifier in which pairwise comparison is assessed. - \item {player(name)} name of the contestant. In this case \code{player(name)} - helps algorithm point name of the column where player names are stored. +\item \code{rank} player position in event. +\item \code{id} event identifier in which pairwise comparison is assessed. +\item \code{player(name)} name of the contestant. In this case \code{player(name)} +helps algorithm point name of the column where player names are stored. } -Users can also specify formula in in different way: - \code{rank | id ~ player(name|team)}. Which means that players are playing in teams, - and results are observed for teams not for players. For more see vignette.} + +Users can also specify formula in in different way:\cr + +\code{rank | id ~ player(name|team)}. Which means that players are playing in teams, +and results are observed for teams not for players. For more see vignette.} \item{r}{named vector of initial players ratings estimates. If not specified then \code{r} will be created automatically for parameters specified in \code{formula} @@ -50,42 +52,36 @@ Default (\code{glicko = 1500}, \code{glicko2 = 1500}, \code{bbt = 25}, \item{init_rd}{initial values for \code{rd} if not provided. Default (\code{glicko = 350}, \code{glicko2 = 350}, \code{bbt = 25/3}, \code{dbl = 1})} -\item{lambda}{name of the column in `data` containing lambda values or one +\item{lambda}{name of the column in \code{data} containing lambda values or one constant value (eg. \code{lambda = colname} or \code{lambda = 0.5}). Lambda impact prior variance, and uncertainty of the matchup result. The higher lambda, the higher prior variance and more uncertain result of the matchup. Higher lambda flattens chances of winning.} -\item{share}{name of the column in `data` containing player share in team +\item{share}{name of the column in \code{data} containing player share in team efforts. It's used to first calculate combined rating of the team and then redistribute ratings update back to players level. Warning - it should -be used only if formula is specified with players nested within teams (`player(player|team)`).} +be used only if formula is specified with players nested within teams (\code{player(player|team)}).} -\item{weight}{name of the column in `data` containing weights values or +\item{weight}{name of the column in \code{data} containing weights values or one constant (eg. \code{weight = colname} or \code{weight = 0.5}). Weights increasing (weight > 1) or decreasing (weight < 1) update change. Higher weight increasing impact of event result on rating estimate.} \item{kappa}{controls \code{rd} shrinkage not to be greater than \code{rd*(1 - kappa)}. -`kappa=1` means that \code{rd} will not be decreased.} +\code{kappa=1} means that \code{rd} will not be decreased.} } \value{ -A "rating" object is returned: \itemize{ - +A "rating" object is returned: +\itemize{ \item \code{final_r} named vector containing players ratings. - \item \code{final_rd} named vector containing players ratings deviations. - \item \code{r} data.frame with evolution of the ratings and ratings deviations - estimated at each event. - +estimated at each event. \item \code{pairs} pairwise combinations of players in analysed events with prior probability and result of a challenge. - \item \code{class} of the object. - \item \code{method} type of algorithm used. - \item \code{settings} arguments specified in function call. } } diff --git a/man/gpheats.Rd b/man/gpheats.Rd index 2587e0a..9ecd14e 100755 --- a/man/gpheats.Rd +++ b/man/gpheats.Rd @@ -6,17 +6,19 @@ \format{ A data frame with >19000 rows and 11 variables: \describe{ - \item{id}{event identifier} - \item{season}{year of Grand-Prix, 1995-now} - \item{date}{date of turnament} - \item{round}{round in season} - \item{name}{Turnament name} - \item{heat}{heat number, 1-23} - \item{field}{number of gate, 1-4} - \item{rider}{rider name, string} - \item{points}{paints gained, integer} - \item{position}{position at finish line, string} - \item{rank}{rank at finish line, integer} +\itemize{ +\item \code{id} - event identifier +\item \code{season} - year of Grand-Prix, 1995-now +\item \code{date} - date of turnament +\item \code{round} - round in season +\item \code{name} - Turnament name +\item \code{heat} - heat number, 1-23 +\item \code{field} - number of gate, 1-4 +\item \code{rider} - rider name, string +\item \code{points} - paints gained, integer +\item \code{position} - position at finish line, string +\item \code{rank} - rank at finish line, integer +} } } \source{ diff --git a/man/gpsquads.Rd b/man/gpsquads.Rd index f70ca54..279d613 100755 --- a/man/gpsquads.Rd +++ b/man/gpsquads.Rd @@ -6,15 +6,17 @@ \format{ A data frame with >4000 rows and 9 variables: \describe{ - \item{id}{event identifier} - \item{season}{year of Grand-Prix, 1995-now} - \item{date}{date of turnament} - \item{place}{stadium of event} - \item{round}{round in season} - \item{name}{Turnament name} - \item{rider}{rider names, 1-6} - \item{points}{points gained, integer} - \item{classification}{classification after an event} +\itemize{ +\item \code{id} - event identifier +\item \code{season} - year of Grand-Prix, 1995-now +\item \code{date} - date of turnament +\item \code{place} - stadium of event +\item \code{round} - round in season +\item \code{name} - Turnament name +\item \code{rider} - rider names, 1-6 +\item \code{points} - points gained, integer +\item \code{classification} - classification after an event +} } } \source{ diff --git a/man/rating_run.Rd b/man/rating_run.Rd index 6741920..a6a270f 100644 --- a/man/rating_run.Rd +++ b/man/rating_run.Rd @@ -28,18 +28,20 @@ rating_run( optional columns defined by \code{lambda}, \code{weight}.} \item{formula}{formula which specifies the model. RHS Allows only player -rating parameter and it should be specified in following manner: +rating parameter and it should be specified in following manner:\cr \code{rank | id ~ player(name)}. \itemize{ - \item {rank} player position in event. - \item {id} event identifier in which pairwise comparison is assessed. - \item {player(name)} name of the contestant. In this case \code{player(name)} - helps algorithm point name of the column where player names are stored. +\item \code{rank} player position in event. +\item \code{id} event identifier in which pairwise comparison is assessed. +\item \code{player(name)} name of the contestant. In this case \code{player(name)} +helps algorithm point name of the column where player names are stored. } -Users can also specify formula in in different way: - \code{rank | id ~ player(name|team)}. Which means that players are playing in teams, - and results are observed for teams not for players. For more see vignette.} + +Users can also specify formula in in different way:\cr + +\code{rank | id ~ player(name|team)}. Which means that players are playing in teams, +and results are observed for teams not for players. For more see vignette.} \item{r}{named vector of initial players ratings estimates. If not specified then \code{r} will be created automatically for parameters specified in \code{formula} @@ -63,24 +65,24 @@ Default (\code{glicko = 350}, \code{glicko2 = 350}, \code{bbt = 25/3}, \code{dbl \item{init_sigma}{initial values for \code{sigma} if not provided. Default = 0.5} -\item{lambda}{name of the column in `data` containing lambda values or one +\item{lambda}{name of the column in \code{data} containing lambda values or one constant value (eg. \code{lambda = colname} or \code{lambda = 0.5}). Lambda impact prior variance, and uncertainty of the matchup result. The higher lambda, the higher prior variance and more uncertain result of the matchup. Higher lambda flattens chances of winning.} -\item{share}{name of the column in `data` containing player share in team +\item{share}{name of the column in \code{data} containing player share in team efforts. It's used to first calculate combined rating of the team and then redistribute ratings update back to players level. Warning - it should -be used only if formula is specified with players nested within teams (`player(player|team)`).} +be used only if formula is specified with players nested within teams (\code{player(player|team)}).} -\item{weight}{name of the column in `data` containing weights values or +\item{weight}{name of the column in \code{data} containing weights values or one constant (eg. \code{weight = colname} or \code{weight = 0.5}). Weights increasing (weight > 1) or decreasing (weight < 1) update change. Higher weight increasing impact of event result on rating estimate.} \item{kappa}{controls \code{rd} shrinkage not to be greater than \code{rd*(1 - kappa)}. -`kappa=1` means that \code{rd} will not be decreased.} +\code{kappa=1} means that \code{rd} will not be decreased.} \item{tau}{The system constant. Which constrains the change in volatility over time. Reasonable choices are between 0.3 and 1.2 (\code{default = 0.5}), though @@ -89,7 +91,7 @@ predictive accuracy. Smaller values of \code{tau} prevent the volatility measure from changing by large amounts, which in turn prevent enormous changes in ratings based on very improbable results. If the application of Glicko-2 is expected to involve extremely improbable collections of game outcomes, then -`tau` should be set to a small value, even as small as, say, \code{tau= 0}.} +\code{tau} should be set to a small value, even as small as, say, \code{tau= 0}.} } \description{ Apply rating algorithm diff --git a/man/summary.rating.Rd b/man/summary.rating.Rd index 19974a2..b022767 100755 --- a/man/summary.rating.Rd +++ b/man/summary.rating.Rd @@ -12,24 +12,28 @@ \item{...}{optional arguments} } \value{ -List with following elements \itemize{ +List with following elements: +\itemize{ \item \code{formula} modeled formula. \item \code{method} type of algorithm used. -\item \code{Overall Accuracy} named vector containing players ratings. -\item \code{r} data.frame summarized players ratings and model winning probabilities. Probabilities are returned only in models with one variable (ratings) \itemize{ +\item \verb{Overall Accuracy} named vector containing players ratings. +\item \code{r} data.frame summarized players ratings and model winning probabilities. +} + +Probabilities are returned only in models with one variable (ratings): +\itemize{ \item \code{name} of a player \item \code{r} players ratings \item \code{rd} players ratings deviation -\item \code{`Model probability`} mean predicted probability of winning the challenge by the player. -\item \code{`True probability`} mean observed probability of winning the challenge by the player. -\item \code{`Accuracy`} Accuracy of prediction. -\item \code{`pairings`} number of pairwise occurrences. -} +\item \verb{Model probability} mean predicted probability of winning the challenge by the player. +\item \verb{True probability} mean observed probability of winning the challenge by the player. +\item \code{Accuracy} Accuracy of prediction. +\item \code{pairings} number of pairwise occurrences. } } \description{ Summarizing rating objects -Summary for object of class `rating` +Summary for object of class \code{rating} } \examples{ model <- glicko_run(