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:
The data frame must not contain missing values. |
dynamic_rank |
A logical value indicating whether a dynamic ranking model is used (default is |
home_effect |
A logical value indicating the inclusion of a home effect in the model. (default is |
prior_par |
A list specifying the prior distributions for the parameters of interest, using the
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:
|
... |
Additional arguments passed to |
Value
A list of class "btdFoot"
containing:
-
fit
: The fittedstanfit
object returned bystan
. -
rank
: A data frame with the rankings, including columns:-
periods
: The time period. -
team
: The team name. -
rank_points
: The estimated strength of the team based on the chosenrank_measure
.
-
-
data
: The input data. -
stan_data
: The data list prepared for Stan. -
stan_code
: The path to the Stan model code used. -
stan_args
: The optional parameters passed to (...
). -
rank_measure
: The method used to compute the rankings.
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)