Expected Values of the Posterior Predictive Distribution
Source:R/posterior_epred.mvgam.R
fitted.mvgam.Rd
This method extracts posterior estimates of the fitted values (i.e. the actual predictions, included estimates for any trend states, that were obtained when fitting the model). It also includes an option for obtaining summaries of the computed draws.
Arguments
- object
An object of class
mvgam
- process_error
Logical. If
TRUE
and a dynamic trend model was fit, expected uncertainty in the process model is accounted for by using draws from the latent trend SD parameters. IfFALSE
, uncertainty in the latent trend component is ignored when calculating predictions- scale
Either
"response"
or"linear"
. If"response"
, results are returned on the scale of the response variable. If"linear"
, results are returned on the scale of the linear predictor term, that is without applying the inverse link function or other transformations.- summary
Should summary statistics be returned instead of the raw values? Default is
TRUE
..- robust
If
FALSE
(the default) the mean is used as the measure of central tendency and the standard deviation as the measure of variability. IfTRUE
, the median and the median absolute deviation (MAD) are applied instead. Only used ifsummary
isTRUE
.- probs
The percentiles to be computed by the
quantile
function. Only used ifsummary
isTRUE
.- ...
Further arguments passed to
prepare_predictions
that control several aspects of data validation and prediction.
Value
An array
of predicted mean response values.
If summary = FALSE
the output resembles those of
posterior_epred.mvgam
and predict.mvgam
.
If summary = TRUE
the output is an n_observations
x E
matrix. The number of summary statistics E
is equal to 2 +
length(probs)
: The Estimate
column contains point estimates (either
mean or median depending on argument robust
), while the
Est.Error
column contains uncertainty estimates (either standard
deviation or median absolute deviation depending on argument
robust
). The remaining columns starting with Q
contain
quantile estimates as specified via argument probs
.
Details
This method gives the actual fitted values from the model (i.e. what you
will see if you generate hindcasts from the fitted model using hindcast.mvgam
with type = 'expected'
). These
predictions can be overly precise if a flexible dynamic trend component was included
in the model. This is in contrast to the set of predict functions (i.e.
posterior_epred.mvgam
or predict.mvgam
), which will assume
any dynamic trend component has reached stationarity when returning hypothetical predictions
Examples
if (FALSE) {
# Simulate some data and fit a model
simdat <- sim_mvgam(n_series = 1, trend_model = 'AR1')
mod <- mvgam(y ~ s(season, bs = 'cc'),
trend_model = 'AR1',
data = simdat$data_train,
chains = 2,
burnin = 300,
samples = 300)
# Extract fitted values (posterior expectations)
expectations <- fitted(mod)
str(expectations)
}