Simulate a set between two players given a number of parameters, that include probability of each player winning a point on their first serve, on their second serve, and the probability that their first serve will go in.
simSet(pA, pB,
playTiebreak = TRUE, players = c("A", "B"),
p2A = NULL, firstServeA = NULL,
p2B = NULL, firstServeB = NULL)
param | details |
---|---|
pA | probability of player A winning point on their first serve |
pB | probability of player B winning point on their first serve |
playTiebreak | play tiebreak in the event the set reaches 6 games all |
players | player names (vector of length 2) |
detail | return a detailed list about the set, including service probabilities, games won, game data and result |
p2A | probability of player A winning point on their second serve |
firstServeA | probability of player A’s first serve being in |
p2A | probability of player B winning point on their second serve |
firstServeB | probability of player B’s first serve being in |
The default function returns a 1, if the server wins the set, or 0, if the returner wins the set. If detail
argument is changed to TRUE
, then the function will return a list with details about the simulated set, including service probabilities, games won by each player, and the result (1 or 0)
There are a number of generic methods available for the detailed list returned by simSet
, these are print
and summary
, example use is show below.
simSet(pA = .78, pB = .70, p2A = .56, p2B = .6,
firstServeA = .67, firstServeB = .7)
## [1] 1
egSet <- simSet(pA = .78, pB = .70, p2A = .56, p2B = .6,
firstServeA = .67, firstServeB = .7, detail = TRUE)
The object egSet
has a class of svR_set which comes with a few methods
egSet
## Set Result:
## A: 4
## B: 6
## B won the set.
## Server order: A, B, A, B, A, B, A, B, A, B
summary(egSet)
## Set Result:
## A: 4
## B: 6
## B won the set.
##
## Server order: A, B, A, B, A, B, A, B, A, B
##
## player p p2 firstServe
## A 0.78 0.56 0.67
## B 0.70 0.60 0.70
simDf
If detail = TRUE
then the list can also be entered into the function simDf
which will convert the simulated set into a dataframe.
df <- simDf(egSet)
df
## pA pB setA setB set_res gameNo serving p p2 firstServe game_res
## 1 A B 4 6 0 1 A 0.78 0.56 0.67 0
## 2 A B 4 6 0 2 B 0.70 0.60 0.70 1
## 3 A B 4 6 0 3 A 0.78 0.56 0.67 1
## 4 A B 4 6 0 4 B 0.70 0.60 0.70 1
## 5 A B 4 6 0 5 A 0.78 0.56 0.67 1
## 6 A B 4 6 0 6 B 0.70 0.60 0.70 1
## 7 A B 4 6 0 7 A 0.78 0.56 0.67 1
## 8 A B 4 6 0 8 B 0.70 0.60 0.70 1
## 9 A B 4 6 0 9 A 0.78 0.56 0.67 1
## 10 A B 4 6 0 10 B 0.70 0.60 0.70 1
## server returner
## 1 1 4
## 2 7 5
## 3 4 2
## 4 4 0
## 5 4 2
## 6 4 2
## 7 4 0
## 8 4 0
## 9 4 2
## 10 4 0
The dataset contains the following variables:
variables | about |
---|---|
pA | player A |
pB | player B |
setA | games won by player A |
setB | games won by player B |
set_res | set result (1 if player A wins, 0 if player B wins) |
gameNo | game number in set |
serving | player serving |
p | probability of server winning a point on their first serve |
p2 | probability of server winning a point on their second serve |
firstServe | probability of first serve being in |
game_res | game result (1 if server wins, 0 if returner wins) |
server | number of points won by server in service game |
returner | number of points won by returner in service game |