pp_foot: Posterior predictive checks for football models

View source: R/pp_foot.R

pp_footR Documentation

Posterior predictive checks for football models

Description

The function provides posterior predictive plots to check the adequacy of the Bayesian models as returned by the stan_foot function.

Usage

pp_foot(object, data, type = "aggregated", coverage = 0.95)

Arguments

object

An object either of class stanFoot, CmdStanFit, stanfit.

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

type

Type of plots, one among "aggregated" or "matches". Default is "aggregated".

coverage

Argument to specify the width 1-\alpha of posterior probability intervals. Default is 0.95.

Details

Posterior predictive plots: when "aggregated" (default) is selected, the function returns a frequency plot for some pre-selected goal-difference values, along with their correspondent Bayesian p-values, computed as Pr(y_rep \ge y)|y), where y_rep is a data replication from the posterior predictive distribution (more details in Gelman et al., 2013). Bayesian p-values very close to 0 or 1 could exhibit possible model misfits.

When "matches" is selected an ordered-frequency plot for all the goal-differences in the considered matches is provided, along with the empirical Bayesian coverage at level 1-\alpha.

Value

A list with elements:

  • pp_plot: A ggplot object for the selected type of plot.

  • pp_table: A data frame of summary statistics:

    • For "aggregated": Goal differences and their Bayesian p‑values.

    • For "matches": Nominal 1-alpha and observed empirical Bayesian coverage.

Author(s)

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

References

Gelman, A., Carlin, J. B., Stern, H. S., Dunson, D. B., Vehtari, A., & Rubin, D. B. (2013). Bayesian data analysis. CRC press.

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(italy_2000, "double_pois", iter_sampling = 200)

  pp_foot(fit, italy_2000)
}

## End(Not run)


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