I found the “footBayes” package for R and decided to run the code from the manual to see how it works: https://cran.r-project.org/web/packages/footBayes/footBayes.pdf
library(footBayes)
library(engsoccerdata)
library(bayesplot)
library(loo)
library(ggplot2)
library(dplyr)
library(tidyverse)
if(requireNamespace("engsoccerdata")){
require(engsoccerdata)
require(tidyverse)
require(dplyr)
### Use Italian Serie A from 2000 to 2002
italy <- as_tibble(italy)
italy_2000_2002<- italy %>%
dplyr::select(Season, home, visitor, hgoal,vgoal) %>%
dplyr::filter(Season=="2000" | Season=="2001"| Season=="2002")
### Fit Stan models
## no dynamics, no predictions
fit1 <- stan_foot(data = italy_2000_2002,
model="double_pois") # double poisson
print(fit1, pars =c("home", "sigma_att",
"sigma_def"))
fit2 <- stan_foot(data = italy_2000_2002,
model="biv_pois") # bivariate poisson
print(fit2, pars =c("home", "rho",
"sigma_att", "sigma_def"))
fit3 <- stan_foot(data = italy_2000_2002,
model="skellam") # skellam
print(fit3, pars =c("home", "sigma_att",
"sigma_def"))
fit4 <- stan_foot(data = italy_2000_2002,
model="student_t") # student_t
print(fit4, pars =c("home", "beta"))
## seasonal dynamics, no prediction
fit5 <- stan_foot(data = italy_2000_2002,
model="double_pois",
dynamic_type ="seasonal") # double poisson
print(fit5, pars =c("home", "Sigma_att",
"Sigma_def"))
## seasonal dynamics, prediction for the last season
fit6 <- stan_foot(data = italy_2000_2002,
model="double_pois",
dynamic_type ="seasonal",
predict = 306) # double poisson
print(fit6, pars =c("home", "Sigma_att",
"Sigma_def"))
## other priors' options
fit_p <- stan_foot(data = italy_2000_2002,
model="double_pois",
priors = student_t (4, 0, NULL),
prior_sd = laplace(0,1)) # double poisson with
# student_t priors for teams abilities
# and laplace prior for the hyper sds
print(fit_p, pars = c("home", "sigma_att",
"sigma_def"))
}
But as a result I encountered the error:
SAMPLING FOR MODEL 'anon_model' NOW (CHAIN 4).
Chain 4:
Chain 4: Gradient evaluation took 4.9e-05 seconds
Chain 4: 1000 transitions using 10 leapfrog steps per transition would take 0.49 seconds.
Chain 4: Adjust your expectations accordingly!
Chain 4:
Chain 4:
Chain 4: Iteration: 1 / 2000 [ 0%] (Warmup)
Chain 4: Iteration: 200 / 2000 [ 10%] (Warmup)
Chain 4: Iteration: 400 / 2000 [ 20%] (Warmup)
Chain 4: Iteration: 600 / 2000 [ 30%] (Warmup)
Chain 4: Iteration: 800 / 2000 [ 40%] (Warmup)
Chain 4: Iteration: 1000 / 2000 [ 50%] (Warmup)
Chain 4: Iteration: 1001 / 2000 [ 50%] (Sampling)
Chain 4: Iteration: 1200 / 2000 [ 60%] (Sampling)
Chain 4: Iteration: 1400 / 2000 [ 70%] (Sampling)
Chain 4: Iteration: 1600 / 2000 [ 80%] (Sampling)
Chain 4: Iteration: 1800 / 2000 [ 90%] (Sampling)
Chain 4: Iteration: 2000 / 2000 [100%] (Sampling)
Chain 4:
Chain 4: Elapsed Time: 25.842 seconds (Warm-up)
Chain 4: 24.925 seconds (Sampling)
Chain 4: 50.767 seconds (Total)
Chain 4:
Error in check_pars(allpars, pars) : no parameter home
In addition: Warning messages:
1: The largest R-hat is 2.29, indicating chains have not mixed.
Running the chains for more iterations may help. See
https://mc-stan.org/misc/warnings.html#r-hat
2: Bulk Effective Samples Size (ESS) is too low, indicating posterior means and medians may be unreliable.
Running the chains for more iterations may help. See
https://mc-stan.org/misc/warnings.html#bulk-ess
3: Tail Effective Samples Size (ESS) is too low, indicating posterior variances and tail quantiles may be unreliable.
Running the chains for more iterations may help. See
https://mc-stan.org/misc/warnings.html#tail-ess
4: There were 78 divergent transitions after warmup. See
https://mc-stan.org/misc/warnings.html#divergent-transitions-after-warmup
to find out why this is a problem and how to eliminate them.
5: There were 4 chains where the estimated Bayesian Fraction of Missing Information was low. See
https://mc-stan.org/misc/warnings.html#bfmi-low
6: Examine the pairs() plot to diagnose sampling problems
7: The largest R-hat is 1.28, indicating chains have not mixed.
Running the chains for more iterations may help. See
https://mc-stan.org/misc/warnings.html#r-hat
8: Bulk Effective Samples Size (ESS) is too low, indicating posterior means and medians may be unreliable.
Running the chains for more iterations may help. See
https://mc-stan.org/misc/warnings.html#bulk-ess
9: Tail Effective Samples Size (ESS) is too low, indicating posterior variances and tail quantiles may be unreliable.
Running the chains for more iterations may help. See
https://mc-stan.org/misc/warnings.html#tail-ess
How to fix this error?