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

## Usage

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

## Arguments

- rates
list: A two-element list, each element of which is a set of rates as returned by

`vs_estimate_rates`

. Experimental: for`process_model`

"sideout", the`sideout`

rate component can be a function. This function will be called at each step of the simulation with the parameters:`team_1_score`

- the score of team 1 at each point in the set so far`team_2_score`

- the score of team 2 at each point in the set so far`team_1_rotation`

- the rotation of team 1 at each point in the set so far (rotations are counted relative to the team's starting rotation, which is 1)`team_2_rotation`

- the rotation of team 2 at each point in the set so far (rotations are counted relative to the team's starting rotation, which is 1)`serving`

- the serving team 1 or 2 at each point in the set so far`point_won_by`

- which team won each point in the set so far (this will be NA for the last entry, because that's the current point that hasn't been simulated yet)`outcome`

- the outcome of each point in the set so far, either "Sideout" or "Breakpoint" if`process_model`

is "sideout", or details TBD if`process_model`

is "phase" The function should return the sideout rate of the receiving team.

- process_model
string: either "sideout" or "phase". The "sideout" model uses the estimated sideout rates (in the

`rates`

object) directly. The "phase" model breaks play down into different phases (serve, serve receive, etc) and uses the rates associated with those separate phases- serving
logical: if

`TRUE`

, team 1 will serve first. If`NA`

, the team serving first will be chosen at random- 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

`method`

"monte carlo". For`method`

"theoretical" a two-point margin is always used- simple
logical: if

`TRUE`

, return simplified output. Only applicable to`method`

"monte carlo". If`simple = TRUE`

, return the team (1 or 2) that won the set. If`simple = FALSE`

, return extra details in a data.frame- id
: an optional value that (if non-

`NULL`

) will be returned in the`id`

column of the returned data frame, if`simple`

is`FALSE`

- method
string: the simulation method to use. Either "monte carlo" or "theoretical". Details TBD

- ...
: parameters as for

`vs_simulate_set`

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

## Examples

```
if (FALSE) {
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)
}
## 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")
#> team_1_score team_2_score team_1_rotation team_2_rotation serving
#> 1 0 0 1 1 1
#> 2 0 1 1 2 2
#> 3 0 2 1 2 2
#> 4 0 3 1 2 2
#> 5 0 4 1 2 2
#> 6 1 4 2 2 1
#> 7 2 4 2 2 1
#> 8 3 4 2 2 1
#> 9 3 5 2 3 2
#> 10 3 6 2 3 2
#> 11 4 6 3 3 1
#> 12 5 6 3 3 1
#> 13 6 6 3 3 1
#> 14 6 7 3 4 2
#> 15 7 7 4 4 1
#> 16 7 8 4 5 2
#> 17 8 8 5 5 1
#> 18 9 8 5 5 1
#> 19 9 9 5 6 2
#> 20 10 9 6 6 1
#> 21 11 9 6 6 1
#> 22 12 9 6 6 1
#> 23 13 9 6 6 1
#> 24 14 9 6 6 1
#> 25 15 9 6 6 1
#> 26 16 9 6 6 1
#> 27 17 9 6 6 1
#> 28 18 9 6 6 1
#> 29 19 9 6 6 1
#> 30 19 10 6 1 2
#> 31 20 10 1 1 1
#> 32 21 10 1 1 1
#> 33 22 10 1 1 1
#> 34 22 11 1 2 2
#> 35 22 12 1 2 2
#> 36 23 12 2 2 1
#> 37 23 13 2 3 2
#> 38 24 13 3 3 1
#> point_won_by set_won_by outcome
#> 1 2 1 Sideout
#> 2 2 1 Breakpoint
#> 3 2 1 Breakpoint
#> 4 2 1 Breakpoint
#> 5 1 1 Sideout
#> 6 1 1 Breakpoint
#> 7 1 1 Breakpoint
#> 8 2 1 Sideout
#> 9 2 1 Breakpoint
#> 10 1 1 Sideout
#> 11 1 1 Breakpoint
#> 12 1 1 Breakpoint
#> 13 2 1 Sideout
#> 14 1 1 Sideout
#> 15 2 1 Sideout
#> 16 1 1 Sideout
#> 17 1 1 Breakpoint
#> 18 2 1 Sideout
#> 19 1 1 Sideout
#> 20 1 1 Breakpoint
#> 21 1 1 Breakpoint
#> 22 1 1 Breakpoint
#> 23 1 1 Breakpoint
#> 24 1 1 Breakpoint
#> 25 1 1 Breakpoint
#> 26 1 1 Breakpoint
#> 27 1 1 Breakpoint
#> 28 1 1 Breakpoint
#> 29 2 1 Sideout
#> 30 1 1 Sideout
#> 31 1 1 Breakpoint
#> 32 1 1 Breakpoint
#> 33 2 1 Sideout
#> 34 2 1 Breakpoint
#> 35 1 1 Sideout
#> 36 2 1 Sideout
#> 37 1 1 Sideout
#> 38 1 1 Breakpoint
```