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

h2h_long(cr_data, ..., fill = list())

to_h2h_long(mat, value = "h2h_value", drop = FALSE)

# S3 method for h2h_long
as_tibble(x, ...)

Arguments

cr_data

Competition results ready for as_longcr().

...

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

fill

A named list that for each variable supplies a single value to use instead of NA for missing pairs (see tidyr's complete()).

mat

Matrix of Head-to-Head values.

value

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

drop

Use TRUE to drop rows with missing Head-to-Head values (see Details).

x

Object to be converted to tibble.

Value

An object of class h2h_long which is a tibble with columns player1, player2 and those, produced by Head-to-Head functions (for h2h_long() maybe none).

as_tibble() applied to h2h_long object drops h2h_long class.

Details

h2h_long() computes Head-to-Head values in long format. It allows computation of multiple Head-to-Head values at the same time by supplying multiple summary functions in .... If no function is supplied in ..., it returns all appropriate combinations of matchups (see next paragraph).

After computing Head-to-Head values of actually present matchups, they are aligned with "levels" (see levels2()) of player vector (after applying as_longcr()). This is a way to target function on fixed set of players by using factor columns. The procedure is:

  • Implicit missing matchups are turned into explicit (by adding corresponding rows with filling values in Head-to-Head columns) by using tidyr's complete().

  • All matchups not containing players from "levels" are removed.

Use fill as in complete() to control filling values. To drop those rows use tidyr's drop_na().

to_h2h_long() takes object of h2h_mat structure and converts it into h2h_long object with value column named as stored in value. Use drop = TRUE to remove rows with missing values in value column (but not in players').

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

ncaa2005 %>% h2h_long( mean_score = mean(score1), mean_abs_score = mean(abs(score1 - score2)) )
#> # A long format of Head-to-Head values: #> # A tibble: 25 x 4 #> player1 player2 mean_score mean_abs_score #> <chr> <chr> <dbl> <dbl> #> 1 Duke Duke 8.75 0 #> 2 Duke Miami 7 45 #> 3 Duke UNC 21 3 #> 4 Duke UVA 7 31 #> 5 Duke VT 0 45 #> 6 Miami Duke 52 45 #> 7 Miami Miami 34.5 0 #> 8 Miami UNC 34 18 #> 9 Miami UVA 25 8 #> 10 Miami VT 27 20 #> # … with 15 more rows
ncaa2005[-(1:2), ] %>% h2h_long( mean_score = mean(score1), fill = list(mean_score = 0) )
#> # A long format of Head-to-Head values: #> # A tibble: 25 x 3 #> player1 player2 mean_score #> <chr> <chr> <dbl> #> 1 Duke Duke 9.33 #> 2 Duke Miami 0 #> 3 Duke UNC 21 #> 4 Duke UVA 7 #> 5 Duke VT 0 #> 6 Miami Duke 0 #> 7 Miami Miami 28.7 #> 8 Miami UNC 34 #> 9 Miami UVA 25 #> 10 Miami VT 27 #> # … with 15 more rows