
Predict Win Probability from Current Game State
Source:R/in_match_prediction.R
predict_win_probability.RdCalculate win probability for the batting-first team given the current match state. Uses scoreboard-friendly inputs. For Test matches, returns three-way probabilities (team1 win, draw, team2 win) via a decomposed two-model pipeline.
Usage
predict_win_probability(
current_score,
wickets,
overs,
innings,
target = NULL,
format = "t20",
venue_stats = NULL,
match_state = NULL,
skill_adjustments = NULL,
models = NULL
)Arguments
- current_score
Integer. Current team score.
- wickets
Integer. Wickets fallen (0-10).
- overs
Numeric. Overs bowled in cricket notation (e.g., 10.3 = 10 overs + 3 balls).
- innings
Integer. Current innings (1-2 for limited overs, 1-4 for Test).
- target
Integer. Target score (required if innings = 2 for limited overs, or innings = 4 for Test).
- format
Character. Match format: "t20", "odi", "test".
- venue_stats
List. Venue-specific statistics (optional). If NULL, uses format averages. For Test, can include venue_avg (1st innings average) and venue_result_rate (historical P(result) at venue).
- match_state
List. Additional Test match state (optional). Can include:
completed_innings - list of lists with runs, wickets, overs per innings
batting_is_team1 - logical, is batting team the team listed first?
- skill_adjustments
List. Team/player skill adjustments (optional).
- models
List. Pre-loaded models from load_in_match_models(). If NULL, models are loaded automatically.
Value
A bouncer_win_prob object. For limited-overs formats:
win_prob - Win probability for batting-first team (0-1)
projected_score - Projected final innings score
For Test format, additionally:
draw_prob - Draw probability (0-1)
team1_win - Team 1 win probability
team2_win - Team 2 win probability
Examples
if (FALSE) { # \dontrun{
# T20 first innings: India 85/2 after 10 overs
wp <- predict_win_probability(85, 2, 10.0, innings = 1, format = "t20")
print(wp)
# T20 second innings: Chasing 180, currently 100/3 after 12.4 overs
wp <- predict_win_probability(100, 3, 12.4, innings = 2, target = 180, format = "t20")
print(wp)
# Test match: 3rd innings, team2 batting at 150/4 after 50 overs
wp <- predict_win_probability(150, 4, 50, innings = 3, format = "test",
match_state = list(
completed_innings = list(
list(runs = 350, wickets = 10, overs = 120),
list(runs = 280, wickets = 10, overs = 95)
),
batting_is_team1 = FALSE
))
print(wp)
} # }