Plot football abilities from Stan and MLE models
Description
Depicts teams' abilities either from the Stan models fitted via the stan_foot function
or from MLE models fitted via the mle_foot function. Supported MLE models include
"double_pois", "biv_pois", "dixon_coles", "neg_bin",
"skellam", and "student_t". Models with separate attack and defence parameters
(all except "student_t") display attack and defence effects; the "student_t" model
displays combined global abilities.
Usage
foot_abilities(object, data, type = "both", teams = NULL)Arguments
object |
An object either of class |
data |
A data frame containing match data with columns:
|
type |
Type of ability for models with separate attack/defence parameters: one among |
teams |
An optional character vector specifying team names to include. If |
Value
A ggplot object showing each selected team's ability estimates:
For static Bayesian or MLE fits, horizontal error bars (95% intervals) and point estimates.
For dynamic Bayesian fits, ribbon and line plots over
periods.
Examples
## Not run:
if (instantiate::stan_cmdstan_exists()) {
library(dplyr)
data("italy")
italy <- as_tibble(italy)
### no dynamics, no prediction
italy_2000_2002 <- italy %>%
dplyr::select(Season, home, visitor, hgoal, vgoal) %>%
dplyr::filter(Season == "2000" | Season == "2001" | Season == "2002")
colnames(italy_2000_2002) <- c("periods", "home_team", "away_team", "home_goals", "away_goals")
fit1 <- stan_foot(
data = italy_2000_2002,
model = "double_pois"
) # double poisson
fit2 <- stan_foot(
data = italy_2000_2002,
model = "biv_pois"
) # bivariate poisson
fit3 <- stan_foot(
data = italy_2000_2002,
model = "skellam"
) # skellam
fit4 <- stan_foot(
data = italy_2000_2002,
model = "student_t"
) # student_t
foot_abilities(fit1, italy_2000_2002)
foot_abilities(fit2, italy_2000_2002)
foot_abilities(fit3, italy_2000_2002)
foot_abilities(fit4, italy_2000_2002)
### seasonal dynamics, predict the last season
fit5 <- stan_foot(
data = italy_2000_2002,
model = "biv_pois",
predict = 180,
dynamic_type = "seasonal"
) # bivariate poisson
foot_abilities(fit5, italy_2000_2002)
}
### MLE models (no Stan required)
data("italy")
italy_2000 <- italy[italy$Season == "2000", ]
italy_2000 <- data.frame(
periods = italy_2000$Season,
home_team = italy_2000$home,
away_team = italy_2000$visitor,
home_goals = italy_2000$hgoal,
away_goals = italy_2000$vgoal
)
## Dixon-Coles MLE
mle_dc <- mle_foot(data = italy_2000, model = "dixon_coles")
foot_abilities(mle_dc, italy_2000)
## Negative Binomial MLE
mle_nb <- mle_foot(data = italy_2000, model = "neg_bin")
foot_abilities(mle_nb, italy_2000, type = "attack")
## End(Not run)