
Posterior draws of the linear predictor for mvgam objects
Source:R/posterior_epred.mvgam.R
posterior_linpred.mvgam.RdCompute posterior draws of the linear predictor, that is draws before applying any link functions or other transformations. Can be performed for the data used to fit the model (posterior predictive checks) or for new data.
Usage
# S3 method for mvgam
posterior_linpred(
object,
transform = FALSE,
newdata,
ndraws = NULL,
data_test,
process_error = TRUE,
...
)Arguments
- object
listobject of classmvgamorjsdgam. Seemvgam()- transform
logical; ifFALSE(the default), draws of the linear predictor are returned. IfTRUE, draws of the transformed linear predictor, i.e. the conditional expectation, are returned.- newdata
Optional
dataframeorlistof test data containing the same variables that were included in the originaldataused to fit the model. If not supplied, predictions are generated for the original observations used for the model fit.- ndraws
Positive
integerindicating how many posterior draws should be used. IfNULL(the default) all draws are used.- data_test
Deprecated. Still works in place of
newdatabut users are recommended to usenewdatainstead for more seamless integration intoRworkflows- process_error
logical. IfTRUEandnewdatais supplied, expected uncertainty in the process model is accounted for by using draws from any latent trend SD parameters. IfFALSE, uncertainty in the latent trend component is ignored when calculating predictions. If nonewdatais supplied, draws from the fitted model's posterior predictive distribution will be used (which will always include uncertainty in any latent trend components)- ...
Ignored
Value
A matrix of dimension n_samples x n_obs, where
n_samples is the number of posterior samples from the fitted object
and n_obs is the number of observations in newdata
Details
Note that for all types of predictions for models that did not
include a trend_formula, uncertainty in the dynamic trend component can
be ignored by setting process_error = FALSE. However, if a
trend_formula was supplied in the model, predictions for this component
cannot be ignored. If process_error = TRUE, trend predictions will
ignore autocorrelation coefficients or GP length scale coefficients,
ultimately assuming the process is stationary. This method is similar to
the types of posterior predictions returned from brms models when using
autocorrelated error predictions for newdata. This function is therefore
more suited to posterior simulation from the GAM components of a
mvgam model, while the forecasting functions
plot_mvgam_fc and forecast.mvgam are better
suited to generate h-step ahead forecasts that respect the temporal
dynamics of estimated latent trends.
Examples
# \donttest{
# Simulate some data and fit a model
simdat <- sim_mvgam(
n_series = 1,
trend_model = AR()
)
mod <- mvgam(
y ~ s(season, bs = 'cc'),
trend_model = AR(),
noncentred = TRUE,
data = simdat$data_train,
chains = 2,
silent = 2
)
# Extract linear predictor values
linpreds <- posterior_linpred(mod)
str(linpreds)
#> num [1:1000, 1:75] -0.979 -1.727 -1.459 -1.95 -0.568 ...
# }