foot_prob: Plot football matches probabilities for out-of-sample...

View source: R/foot_prob.R

foot_probR Documentation

Plot football matches probabilities for out-of-sample football matches.

Description

The function provides a table containing the home win, draw and away win probabilities for a bunch of out-of-sample matches as specified by stan_foot or mle_foot.

Usage

foot_prob(object, data, home_team, away_team)

Arguments

object

An object either of class stanFoot, CmdStanFit, stanfit, or class list containing the Maximum Likelihood Estimates (MLE) for the model parameters fitted with mle_foot.

data

A data frame containing match data with columns:

  • periods: Time point of each observation (integer >= 1).

  • home_team: Home team's name (character string).

  • away_team: Away team's name (character string).

  • home_goals: Goals scored by the home team (integer >= 0).

  • away_goals: Goals scored by the away team (integer >= 0).

home_team

The home team(s) for the predicted matches.

away_team

The away team(s) for the predicted matches.

Details

For Bayesian models the results probabilities are computed according to the simulation from the posterior predictive distribution of future (out-of-sample) matches. Specifically, matches are ordered from those in which the favorite team has the highest posterior probability of winning to those where the underdog is more likely to win. For MLE models fitted via the mle_foot the probabilities are computed by simulating from the MLE estimates.

Value

A list with components:

  • prob_table: A data frame containing the results probabilities of the out-of-sample matches.

  • prob_plot: A ggplot object for Bayesian models only showing the posterior predictive heatmap of exact score probabilities, with the true result highlighted.

Author(s)

Leonardo Egidi legidi@units.it and Roberto Macrì Demartino roberto.macridemartino@deams.units.it.

Examples

## Not run: 
if (instantiate::stan_cmdstan_exists()) {
  library(dplyr)

  data("italy")
  italy_2000 <- italy %>%
    dplyr::select(Season, home, visitor, hgoal, vgoal) %>%
    dplyr::filter(Season == "2000")

  colnames(italy_2000) <- c("periods", "home_team", "away_team", "home_goals", "away_goals")



  fit <- stan_foot(
    data = italy_2000,
    model = "double_pois",
    predict = 18
  ) # double pois

  foot_prob(
    fit, italy_2000, "Inter",
    "Bologna FC"
  )

  foot_prob(fit, italy_2000) # all the out-of-sample matches
}

## End(Not run)


LeoEgidi/footBayes documentation built on June 2, 2025, 11:32 a.m.