
Compute pointwise Log-Likelihoods from fitted mvgam objects
Source:R/logLik.mvgam.R
logLik.mvgam.Rd
Compute pointwise Log-Likelihoods from fitted mvgam objects
Usage
# S3 method for mvgam
logLik(object, linpreds, newdata, family_pars, include_forecast = TRUE, ...)
Arguments
- object
list
object of classmvgam
orjsdgam
- linpreds
Optional
matrix
of linear predictor draws to use for calculating pointwise log-likelihoods- newdata
Optional
data.frame
orlist
object specifying which series each column inlinpreds
belongs to. Iflinpreds
is supplied, thennewdata
must also be supplied- family_pars
Optional
list
containing posterior draws of family-specific parameters (i.e. shape, scale or overdispersion parameters). Required iflinpreds
andnewdata
are supplied- include_forecast
Logical. If
newdata
were fed to the model to compute forecasts, should the log-likelihood draws for these observations also be returned. Defaults toTRUE
- ...
Ignored
Value
A matrix
of dimension n_samples x n_observations
containing the pointwise
log-likelihood draws for all observations in newdata
. If no newdata
is supplied,
log-likelihood draws are returned for all observations that were originally fed to
the model (training observations and, if supplied to the
original model via the newdata
argument in mvgam
,
testing observations)
Examples
# \donttest{
# Simulate some data and fit a model
simdat <- sim_mvgam(n_series = 1, trend_model = 'AR1')
mod <- mvgam(y ~ s(season, bs = 'cc', k = 6),
trend_model = AR(),
data = simdat$data_train,
chains = 2,
silent = 2)
# Extract logLikelihood values
lls <- logLik(mod)
str(lls)
#> num [1:1000, 1:75] -4.23 -4.88 -5.51 -5.44 -4.77 ...
# }