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

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.

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.

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).

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

Examples

# Only first function is used ncaa2005 %>% h2h_mat( mean_score = mean(score1), mean_abs_score = mean(abs(score1 - score2)) )
#> Using mean_score as value.
#> # A matrix format of Head-to-Head values: #> Duke Miami UNC UVA VT #> Duke 8.75 7.0 21.0 7.0 0.0 #> Miami 52.00 34.5 34.0 25.0 27.0 #> UNC 24.00 16.0 12.5 7.0 3.0 #> UVA 38.00 17.0 5.0 18.5 14.0 #> VT 45.00 7.0 30.0 52.0 33.5
ncaa2005[-(1:2), ] %>% h2h_mat(mean_score = mean(score1), fill = 0)
#> # A matrix format of Head-to-Head values: #> Duke Miami UNC UVA VT #> Duke 9.333333 0.00000 21.0 7.0 0.0 #> Miami 0.000000 28.66667 34.0 25.0 27.0 #> UNC 24.000000 16.00000 12.5 7.0 3.0 #> UVA 38.000000 17.00000 5.0 18.5 14.0 #> VT 45.000000 7.00000 30.0 52.0 33.5