btd_foot {footBayes}R Documentation

Bayesian Bradley-Terry-Davidson Model

Description

Fits a Bayesian Bradley-Terry-Davidson model using Stan. Supports both static and dynamic ranking models, allowing for the estimation of team strengths over time.

Usage

btd_foot(
  data,
  dynamic_rank = FALSE,
  home_effect = FALSE,
  prior_par = list(logStrength = normal(0, 3), logTie = normal(0, 0.3), home = normal(0,
    5)),
  rank_measure = "median",
  ...
)

Arguments

data

A data frame containing the observations 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).

  • match_outcome: Outcome (1 if home team beats away team, 2 for tie, and 3 if away team beats home team).

The data frame must not contain missing values.

dynamic_rank

A logical value indicating whether a dynamic ranking model is used (default is FALSE).

home_effect

A logical value indicating the inclusion of a home effect in the model. (default is FALSE).

prior_par

A list specifying the prior distributions for the parameters of interest, using the normal function:

  • logStrength: Prior for the team log-strengths. Default is normal(0, 3).

  • logTie: Prior for the tie parameter. Default is normal(0, 0.3).

  • home: Prior for the home effect (home). Applicable only if home_effect = TRUE. Default is normal(0, 5).

Only normal priors are allowed for this model.

rank_measure

A character string specifying the method used to summarize the posterior distributions of the team strengths. Options are:

  • "median": Uses the median of the posterior samples (default).

  • "mean": Uses the mean of the posterior samples.

  • "map": Uses the Maximum A Posteriori estimate, calculated as the mode of the posterior distribution.

...

Additional arguments passed to stan (e.g., iter, chains, control).

Value

A list of class "btdFoot" containing:

Author(s)

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

Examples

## Not run: 

library(dplyr)

data("italy")

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

# Dynamic Ranking Example with Median Rank Measure
fit_result_dyn <- btd_foot(
  data = italy_2020_2021,
  dynamic_rank = TRUE,
  home_effect = TRUE,
  prior_par = list(
    logStrength = normal(0, 10),
    logTie = normal(0, 5),
    home = normal(0, 5)
  ),
  rank_measure = "median",
  iter = 1000,
  cores = 2,
  chains = 2
)

print(fit_result_dyn)

print(fit_result_dyn, pars = c("logStrength", "home"), teams = c("AC Milan", "AS Roma"))

# Static Ranking Example with MAP Rank Measure
fit_result_stat <- btd_foot(
  data = italy_2020_2021,
  dynamic_rank = FALSE,
  prior_par = list(
    logStrength = normal(0, 10),
    logTie = normal(0, 5),
    home = normal(0, 5)
  ),
  rank_measure = "map",
  iter = 1000,
  chains = 2
)

print(fit_result_stat)

## End(Not run)

[Package footBayes version 1.0.0 Index]