# \donttest{
# Simulate some time series
dat <- sim_mvgam(T = 80, n_series = 3)
# Fit a basic model
mod <- mvgam(y ~ s(season, bs = 'cc') + s(series, bs = 're'),
data = dat$data_train,
trend_model = RW(),
chains = 2,
silent = 2)
# Plot predictions and residuals for each series
plot(mod, type = 'forecast', series = 1)
plot(mod, type = 'forecast', series = 2)
plot(mod, type = 'forecast', series = 3)
plot(mod, type = 'residuals', series = 1)
plot(mod, type = 'residuals', series = 2)
plot(mod, type = 'residuals', series = 3)
# Plot model effects
plot(mod, type = 'smooths')
plot(mod, type = 're')
# More flexible plots with 'marginaleffects' utilities
library(marginaleffects)
plot_predictions(mod, condition = 'season', type = 'link')
plot_predictions(mod,
condition = c('season', 'series', 'series'),
type = 'link')
plot_predictions(mod, condition = 'series', type = 'link')
# When using a State-Space model with predictors on the process
# model, set trend_effects = TRUE to visualise process effects
mod <- mvgam(y ~ -1,
trend_formula = ~ s(season, bs = 'cc'),
data = dat$data_train,
trend_model = RW(),
chains = 2,
silent = 2)
plot(mod, type = 'smooths', trend_effects = TRUE)
# But marginaleffects functions work without any modification
plot_predictions(mod, condition = 'season', type = 'link')
# }
Run the code above in your browser using DataLab