Title: | Volleyball Match Simulation Tools |
---|---|
Description: | Functions for simulating volleyball match outcomes. |
Authors: | Ben Raymond [aut, cre], Dwight Wynne [aut], Adrien Ickowicz [aut], openvolley.org [org] |
Maintainer: | Ben Raymond <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.3.7 |
Built: | 2024-11-18 05:25:25 UTC |
Source: | https://github.com/openvolley/volleysim |
Estimate parameters required for simulation
vs_estimate_rates( x, target_team, by = "none", moderate = TRUE, process_model = "all" )
vs_estimate_rates( x, target_team, by = "none", moderate = TRUE, process_model = "all" )
x |
datavolleyplays: the plays component of a datavolley object as returned by |
target_team |
string: the team name to calculate rates for. If missing or NULL, rates will be calculated across the entire data.frame |
by |
string: grouping to calculate rates by. Either "none" (calculate whole-data set rates), "match" (by match), or "set" (by match and set) |
moderate |
logical: if
|
process_model |
string: estimate the rates required for which process model? Either "sideout", "phase", or "all" |
A tibble, with columns match_id (if by
is "match"), set_number (if by
is "set"), and (if target_team
is "each") "team". The remaining columns depend on the process_model
: for "sideout", column sideout. If process_model
is "phase" then additionally the columns serve_ace, serve_error, rec_loss_other, rec_att_error, rec_att_kill, rec_att_replayed, rec_no_att, rec_block, trans_loss_other, trans_att_error, trans_att_kill, trans_att_replayed, trans_no_att, and trans_block
## Not run: library(datavolley) x <- dv_read(dv_example_file()) rates <- vs_estimate_rates(x, target_team = "each") vs_simulate_set(rates) ## simulate a single set vs_simulate_match(rates) ## simulate a match ## so given the performances of the two teams during that match, we expect ## that the home team should have won, with 3-0 being the most likely scoreline ## compare to the actual match result summary(x) ## End(Not run)
## Not run: library(datavolley) x <- dv_read(dv_example_file()) rates <- vs_estimate_rates(x, target_team = "each") vs_simulate_set(rates) ## simulate a single set vs_simulate_match(rates) ## simulate a match ## so given the performances of the two teams during that match, we expect ## that the home team should have won, with 3-0 being the most likely scoreline ## compare to the actual match result summary(x) ## End(Not run)
Example DataVolley files provided as part of the volleysim package
vs_example_file(choice = 1)
vs_example_file(choice = 1)
choice |
numeric: which data file to return?
|
path to the file
The example data files came from https://www.volleynet.at/dvdownload/information/f-Damen/
## Not run: myfile <- vs_example_file() x <- datavolley::dv_read(myfile) summary(x) ## End(Not run)
## Not run: myfile <- vs_example_file() x <- datavolley::dv_read(myfile) summary(x) ## End(Not run)
Create a win probability graph for a match
vs_match_win_probability( pbp, so, go_to = 25, go_to_tiebreak = 15, max_sets = 5, show_plot = TRUE, home_color = "blue", visiting_color = "darkred" )
vs_match_win_probability( pbp, so, go_to = 25, go_to_tiebreak = 15, max_sets = 5, show_plot = TRUE, home_color = "blue", visiting_color = "darkred" )
pbp |
data frame: a data frame containing the set number, home team, visiting team, serving team, point-winning team, home team score, and visiting team score at the end of each point,
easiest to obtain by subsetting the plays component of a datavolley object as returned by |
so |
integer: a two-element vector of sideout rates for the home team and visiting team, easiest to obtain using |
go_to |
integer: the minimum score that must be reached to end a non-tiebreaker set (typically 25 for indoor volleyball in sets 1 to 4, or 21 in beach volleyball) |
go_to_tiebreak |
integer: the minimum score that must be reached to end a tiebreaker set (typically 15) |
max_sets |
integer: the maximum number of sets that can be played, either 3 or 5 |
show_plot |
logical: if |
home_color |
string: the color used to indicate points in the match where the home team is favored to win |
visiting_color |
string: the same as |
A data frame containing the home team's probability of winning the set (set_probs
) and match (match_probs
) at each point in the set.
The first row of the data frame refers to the start of the match (0-0, Set 1).
## Not run: library(datavolley) x <- dv_read(vs_example_file()) sideout_rates <- vs_estimate_rates(x, target_team = "each")$sideout play_by_play <- subset(plays(x), point) vs_match_win_probability(play_by_play, sideout_rates) ## data frame is not printed to console ## but can be stored in a variable match_win_probs <- vs_match_win_probability(play_by_play, sideout_rates) ## End(Not run)
## Not run: library(datavolley) x <- dv_read(vs_example_file()) sideout_rates <- vs_estimate_rates(x, target_team = "each")$sideout play_by_play <- subset(plays(x), point) vs_match_win_probability(play_by_play, sideout_rates) ## data frame is not printed to console ## but can be stored in a variable match_win_probs <- vs_match_win_probability(play_by_play, sideout_rates) ## End(Not run)
Simulate a volleyball match using either best-of-5 or best-of-3 scoring
vs_simulate_match( rates, process_model = "phase", serving = NA, serving5 = NA, max_sets = 5, go_to = 25, go_to5 = 15, point_margin = 2L, point_margin5 = 2L, n = 2000, simple = TRUE, method = "theoretical" ) vs_simulate_match_mc(...) vs_simulate_match_theor(...) vs_simulate_match_beach(...)
vs_simulate_match( rates, process_model = "phase", serving = NA, serving5 = NA, max_sets = 5, go_to = 25, go_to5 = 15, point_margin = 2L, point_margin5 = 2L, n = 2000, simple = TRUE, method = "theoretical" ) vs_simulate_match_mc(...) vs_simulate_match_theor(...) vs_simulate_match_beach(...)
rates |
list: A two-element list, each element of which is a set of rates as returned by |
process_model |
string: either "sideout" or "phase". See |
serving |
logical: if |
serving5 |
logical: if |
max_sets |
integer: the maximum number of sets to be played (either 3 or 5) |
go_to |
integer: the minimum score that must be reached to end the set (typically 25 for indoor volleyball in sets 1 to 4, 15 in set 5, or 21 in beach volleyball) |
go_to5 |
integer: the minimum score that must be reached to end the tiebreaker set (typically 15 for indoor volleyball) |
point_margin |
integer: the minimum score difference in order to win the set. Only applicable to |
point_margin5 |
integer: the minimum score difference in order to win the tiebreaker set. Only applicable to |
n |
integer: the number of simulations to run. Only applicable to |
simple |
logical: if |
method |
string: the simulation method to use. Either "monte carlo" or "theoretical". Details TBD |
... |
parameters as for |
vs_estimate_rates()
vs_simulate_set()
## Not run: library(datavolley) x <- dv_read(dv_example_file()) rates <- vs_estimate_rates(x, target_team = "each") vs_simulate_set(rates) ## simulate a single set vs_simulate_match(rates) ## simulate a match ## so given the performances of the two teams during that match, we expect ## that the home team should have won, with 3-0 being the most likely scoreline ## compare to the actual match result summary(x) ## End(Not run)
## Not run: library(datavolley) x <- dv_read(dv_example_file()) rates <- vs_estimate_rates(x, target_team = "each") vs_simulate_set(rates) ## simulate a single set vs_simulate_match(rates) ## simulate a match ## so given the performances of the two teams during that match, we expect ## that the home team should have won, with 3-0 being the most likely scoreline ## compare to the actual match result summary(x) ## End(Not run)
vs_simulate_set_theor
and vs_simulate_set_mc
are convenience functions for vs_simulate_set(..., method = "theoretical")
and vs_simulate_set(..., method = "monte carlo")
respectively.
vs_simulate_set( rates, process_model = "phase", serving = NA, go_to = 25, point_margin = 2, simple = FALSE, id = NULL, method = "theoretical" ) vs_simulate_set_mc(...) vs_simulate_set_theor(...)
vs_simulate_set( rates, process_model = "phase", serving = NA, go_to = 25, point_margin = 2, simple = FALSE, id = NULL, method = "theoretical" ) vs_simulate_set_mc(...) vs_simulate_set_theor(...)
rates |
list: A two-element list, each element of which is a set of rates as returned by
|
process_model |
string: either "sideout" or "phase". The "sideout" model uses the estimated sideout rates (in the |
serving |
logical: if |
go_to |
integer: the minimum score that must be reached to end the set (typically 25 for indoor volleyball in sets 1 to 4, 15 in set 5, or 21 in beach volleyball) |
point_margin |
integer: the minimum score difference in order to win the set. Only applicable to |
simple |
logical: if |
id |
: an optional value that (if non- |
method |
string: the simulation method to use. Either "monte carlo" or "theoretical". Details TBD |
... |
: parameters as for |
Integer (1 or 2) or a data frame, depending on the value of simple
vs_estimate_rates()
vs_simulate_match()
## Not run: library(datavolley) x <- dv_read(dv_example_file()) rates <- vs_estimate_rates(x, target_team = "each") vs_simulate_set(rates) ## simulate a single set vs_simulate_match(rates) ## simulate a match ## so given the performances of the two teams during that match, we expect ## that the home team should have won, with 3-0 being the most likely scoreline ## compare to the actual match result summary(x) ## End(Not run) ## sideout rates as a function for team 2 sofun2 <- function(serving, point_won_by, ...) { ## if team 2 won their previous sideout opportunity, their sideout rate is 0.6 ## otherwise it's 0.5 prevso <- tail(na.omit(point_won_by[serving == 1]), 1) if (length(prevso) < 1 || prevso == 1) { ## first sideout opportunity or lost the last one 0.5 } else { 0.6 } } rates <- list(list(sideout = 0.55), ## first team has constant 55% sideout rate list(sideout = sofun2)) ## function for team 2's sideout rate ## need to use method = "monte carlo" for this vs_simulate_set(rates = rates, process_model = "sideout", method = "monte carlo")
## Not run: library(datavolley) x <- dv_read(dv_example_file()) rates <- vs_estimate_rates(x, target_team = "each") vs_simulate_set(rates) ## simulate a single set vs_simulate_match(rates) ## simulate a match ## so given the performances of the two teams during that match, we expect ## that the home team should have won, with 3-0 being the most likely scoreline ## compare to the actual match result summary(x) ## End(Not run) ## sideout rates as a function for team 2 sofun2 <- function(serving, point_won_by, ...) { ## if team 2 won their previous sideout opportunity, their sideout rate is 0.6 ## otherwise it's 0.5 prevso <- tail(na.omit(point_won_by[serving == 1]), 1) if (length(prevso) < 1 || prevso == 1) { ## first sideout opportunity or lost the last one 0.5 } else { 0.6 } } rates <- list(list(sideout = 0.55), ## first team has constant 55% sideout rate list(sideout = sofun2)) ## function for team 2's sideout rate ## need to use method = "monte carlo" for this vs_simulate_set(rates = rates, process_model = "sideout", method = "monte carlo")
The vs_estimate_rates()
function returns a team's performance rates across a range of aspects of play, including serve ace rate, serve error rate, and so on. Using vs_theoretical_sideout_rates()
We can estimate the theoretical sideout rate that we would expect to see, given those parameters. This can be compared to the actual sideout rate achieved by the team.
vs_theoretical_sideout_rates(rates, process_model = "phase")
vs_theoretical_sideout_rates(rates, process_model = "phase")
rates |
list: rates as returned by |
process_model |
string: currently only "phase". See |
The theoretical sideout rates of the two teams
## Not run: library(datavolley) x <- dv_read(dv_example_file()) rates <- list(vs_estimate_rates(x, target_team = home_team(x)), vs_estimate_rates(x, target_team = visiting_team(x))) ## the theoretical sideout rates vs_theoretical_sideout_rates(rates) ## compare to their actual sideout rates c(rates[[1]]$sideout, rates[[2]]$sideout) ## End(Not run)
## Not run: library(datavolley) x <- dv_read(dv_example_file()) rates <- list(vs_estimate_rates(x, target_team = home_team(x)), vs_estimate_rates(x, target_team = visiting_team(x))) ## the theoretical sideout rates vs_theoretical_sideout_rates(rates) ## compare to their actual sideout rates c(rates[[1]]$sideout, rates[[2]]$sideout) ## End(Not run)