plot_btdPosterior {footBayes}R Documentation

Plot Posterior Distributions for btdFoot Objects

Description

Plots for the posterior distributions of team log-strengths and other parameters with customizable plot types and facets.

Usage

plot_btdPosterior(
  x,
  pars = "logStrength",
  plot_type = "boxplot",
  teams = NULL,
  ncol = NULL,
  scales = NULL,
  ...
)

Arguments

x

An object of class btdFoot.

pars

A character string specifying the parameter to plot. Choices are "logStrength", "logTie", and "home". Default is "logStrength".

plot_type

A character string specifying the type of plot. Choices are "boxplot" and "density". Default is "boxplot".

teams

An optional character vector specifying team names to include in the posterior boxplots or density plots. If NULL, all teams are included.

ncol

An optional integer specifying the number of columns in the facet wrap when using a dynamic Bayesian Bradley-Terry-Davidson model. Default is 8.

scales

An optional character string specifying the scales for the facets when using a dynamic Bayesian Bradley-Terry-Davidson model. Options include "free", "fixed", "free_x", and "free_y". Default is "free_x".

...

Additional arguments passed to geom_boxplot(), geom_density_ridges(), or other geoms for customization (e.g., size, alpha, color).

Details

Value

A ggplot object representing the posterior distributions plot.

Author(s)

Roberto Macrì Demartino roberto.macridemartino@phd.unipd.it.

Examples

## Not run: 
library(dplyr)

# Load example data
data("italy")

# Prepare the data
italy_2020_2021_rank <- italy %>%
  select(Season, home, visitor, hgoal, vgoal) %>%
  filter(Season %in% c("2020", "2021")) %>%
  mutate(match_outcome = case_when(
    hgoal > vgoal ~ 1,        # Home team wins
    hgoal == vgoal ~ 2,       # Draw
    hgoal < vgoal ~ 3         # Away team wins
  )) %>%
  mutate(periods = case_when(
    row_number() <= 190 ~ 1,
    row_number() <= 380 ~ 2,
    row_number() <= 570 ~ 3,
    TRUE ~ 4
  )) %>%  # Assign periods based on match number
  select(periods, home_team = home,
         away_team = visitor, match_outcome)

# Fit the Bayesian Bradley-Terry-Davidson model with dynamic ranking
fit_rank_dyn <- btd_foot(
  data = italy_2020_2021_rank,
  dynamic_rank = TRUE,
  rank_measure = "median",
  iter = 1000,
  cores = 2,
  chains = 2
)

# Plot posterior distributions with default settings
plot_btdPosterior(fit_rank_dyn)

# Plot posterior distributions for specific teams with customized facets
plot_btdPosterior(
  fit_rank_dyn,
  teams = c("AC Milan", "AS Roma", "Juventus", "Inter"),
  ncol = 2
)

plot_btdPosterior(
  fit_rank_dyn,
  plot_type = "density",
  teams = c("AC Milan", "AS Roma", "Juventus", "Inter"),
  ncol = 2
)

## End(Not run)


[Package footBayes version 1.0.0 Index]