h2h_mat: Compute matrix format of Head-to-Head values

View source: R/head-to-head.R

h2h_matR Documentation

Compute matrix format of Head-to-Head values

Description

Functions to compute Head-to-Head values in matrix pair-value format.

Usage

h2h_mat(cr_data, ..., fill = NULL)

to_h2h_mat(tbl, value = NULL, fill = NULL)

Arguments

cr_data

Competition results ready for as_longcr().

...

Name-value pairs of Head-to-Head functions (see Details).

fill

A single value to use instead of NA for missing pairs.

tbl

Data frame in long format of Head-to-Head values.

value

String name for column with Head-to-Head value.

Details

h2h_mat() computes Head-to-Head values in matrix format. It allows multiple Head-to-Head functions in ... but only first (if present) will be used. Basically, it uses supplied function to compute long format of Head-to-Head values and then transforms it naturally to matrix, filling missing values with fill.

to_h2h_mat() takes object of h2h_long structure and converts it into h2h_mat using column with name value for values and filling data for implicitly missing (not explicitly provided in tbl) player pairs with fill. If value is NULL it takes first non-player column. If there is no such column, it will use vector of dummy values (NAs or fills).

Value

An object of class h2h_mat which is a matrix with row names indicating first player in matchup, col names - second and values - Head-to-Head values.

Head-to-Head value

Head-to-Head value is a summary statistic of direct confrontation between two players. It is assumed that this value can be computed based only on the players' matchups. In other words, every game is converted into series of "subgames" between ordered pairs of players (including selfplay) which is stored as widecr object. After that, summary of item, defined by columns player1 and player2, is computed using summarise_item().

That said, name-value pairs of Head-to-Head functions should be defined as for summarise_item() applied to data with columns game, player1, score1, player2, score2.

See Also

Long format of Head-to-Head values.

Common Head-to-Head functions.

Examples

# Only first function is used
ncaa2005 %>%
  h2h_mat(
    mean_score = mean(score1),
    mean_abs_score = mean(abs(score1 - score2))
  )

ncaa2005[-(1:2), ] %>%
  h2h_mat(mean_score = mean(score1), fill = 0)

comperes documentation built on March 7, 2023, 7:02 p.m.