| plot.mvgam | R Documentation |
This function takes a fitted mvgam object and produces plots of
smooth functions, forecasts, trends and uncertainty components
## S3 method for class 'mvgam'
plot(
x,
type = "residuals",
series = 1,
residuals = FALSE,
newdata,
data_test,
trend_effects = FALSE,
...
)
x |
|
type |
|
series |
|
residuals |
|
newdata |
Optional |
data_test |
Deprecated. Still works in place of |
trend_effects |
logical. If |
... |
Additional arguments for each individual plotting function. |
These plots are useful for getting an overview of the fitted
model and its estimated random effects or smooth functions, but the
individual plotting functions and the functions from the marginaleffects
and gratia packages offer far more customisation.
A base R plot or set of plots
Nicholas J Clark
plot_mvgam_resids,
plot_mvgam_smooth,
plot_mvgam_fc,
plot_mvgam_trend,
plot_mvgam_uncertainty,
plot_mvgam_factors,
plot_mvgam_randomeffects,
conditional_effects.mvgam,
plot_predictions,
plot_slopes,
gratia_mvgam_enhancements
## Not run:
# 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'
)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.