conditional_effects.mvgam {mvgam} | R Documentation |
Display Conditional Effects of Predictors
Description
Display conditional effects of one or more numeric and/or categorical
predictors in mvgam
models, including two-way interaction effects.
Usage
## S3 method for class 'mvgam'
conditional_effects(
x,
effects = NULL,
type = "response",
points = TRUE,
rug = TRUE,
...
)
## S3 method for class 'mvgam_conditional_effects'
plot(x, plot = TRUE, ask = FALSE, ...)
## S3 method for class 'mvgam_conditional_effects'
print(x, ...)
Arguments
x |
Object of class |
effects |
An optional character vector naming effects (main effects or
interactions) for which to compute conditional plots. Interactions are
specified by a |
type |
|
points |
|
rug |
|
... |
other arguments to pass to |
plot |
Logical; indicates if plots should be
plotted directly in the active graphic device.
Defaults to |
ask |
|
Details
This function acts as a wrapper to the more
flexible plot_predictions
.
When creating conditional_effects
for a particular predictor
(or interaction of two predictors), one has to choose the values of all
other predictors to condition on. By default, the mean is used for
continuous variables and the reference category is used for factors. Use
plot_predictions
to change these
and create more bespoke conditional effects plots.
Value
conditional_effects
returns an object of class
mvgam_conditional_effects
which is a
named list with one slot per effect containing a ggplot
object,
which can be further customized using the ggplot2 package.
The corresponding plot
method will draw these plots in the active graphic device
Author(s)
Nicholas J Clark
See Also
Examples
# Simulate some data
simdat <- sim_mvgam(family = poisson(),
seasonality = 'hierarchical')
# Fit a model
mod <- mvgam(y ~ s(season, by = series, k = 5) + year:series,
family = poisson(),
data = simdat$data_train,
chains = 2)
# Plot all main effects on the response scale
conditional_effects(mod)
# Change the prediction interval to 70% using plot_predictions() argument
# 'conf_level'
conditional_effects(mod, conf_level = 0.7)
# Plot all main effects on the link scale
conditional_effects(mod, type = 'link')
# Works the same for smooth terms, including smooth interactions
set.seed(0)
dat <- mgcv::gamSim(1, n = 200, scale = 2)
mod <- mvgam(y ~ te(x0, x1, k = 5) + s(x2, k = 6) + s(x3, k = 6),
data = dat,
family = gaussian(),
chains = 2)
conditional_effects(mod)
conditional_effects(mod, conf_level = 0.5, type = 'link')