Skip to contents

log_lik() returns the pointwise log-likelihood matrix used for model-fit diagnostics. waic() computes Watanabe-Akaike information criterion using loo::waic().

Usage

log_lik(object, ...)

# S3 method for class 'stLMM'
log_lik(object,
  sub_sample = list(start = 1L, thin = 1L), ...)

# S3 method for class 'stLMM_chains'
log_lik(object,
  sub_sample = list(start = 1L, thin = 1L), ...)

# S3 method for class 'stLMM_recovery'
log_lik(object,
  sub_sample = list(start = 1L, thin = 1L), ...)

# S3 method for class 'stLMM_recovery_chains'
log_lik(object,
  sub_sample = list(start = 1L, thin = 1L), ...)

waic(object, ...)

# S3 method for class 'stLMM'
waic(object,
  sub_sample = list(start = 1L, thin = 1L), ...)

# S3 method for class 'stLMM_chains'
waic(object,
  sub_sample = list(start = 1L, thin = 1L), ...)

# S3 method for class 'stLMM_recovery'
waic(object,
  sub_sample = list(start = 1L, thin = 1L), ...)

# S3 method for class 'stLMM_recovery_chains'
waic(object,
  sub_sample = list(start = 1L, thin = 1L), ...)

Arguments

object

An stLMM fit, recovered stLMM_recovery object, or corresponding multi-chain object. Models with structured process terms require saved or recovered latent process samples.

sub_sample

A list with optional integer entries start and thin. For ordinary fits these select posterior draw indices. For recovered objects and Polya-Gamma process fits with saved process draws, these select saved or recovered draws through recover_iter.

...

Additional arguments. For waic(), these are passed to loo::waic().

Details

The returned log-likelihood matrix has posterior draws in rows and observed response rows in columns. Missing response rows are excluded because they do not contribute to the fitted likelihood.

The calculation is conditional on the latent model expression. For Gaussian models, each entry is evaluated with the fitted linear predictor and the draw-specific residual standard deviation. For binomial models, entries are computed with the inverse-logit probability and fitted trial count. For fixed-size negative-binomial models, entries are computed with the log-mean linear predictor and the fitted size parameter.

For models with structured process terms, log_lik() requires saved or recovered latent process samples so that the latent linear predictor can be evaluated draw by draw. Gaussian process models should therefore be passed to recover() before calling log_lik() or waic(). Polya-Gamma process fits can be used directly when process draws were saved during stLMM().

waic() requires the optional loo package. loo is suggested, not imported, so ordinary model fitting does not require it.

Value

log_lik() returns a numeric matrix. waic() returns the object produced by loo::waic().

Examples

set.seed(1)
dat <- data.frame(y = rnorm(8), x = seq(-1, 1, length.out = 8))
fit <- stLMM(y ~ x, data = dat, n_samples = 8, warmup = FALSE, verbose = FALSE)
ll <- log_lik(fit, sub_sample = list(start = 5, thin = 1))

if (requireNamespace("loo", quietly = TRUE)) {
  waic(fit, sub_sample = list(start = 5, thin = 1))
}
#> Warning: 
#> 4 (50.0%) p_waic estimates greater than 0.4. We recommend trying loo instead.
#> 
#> Computed from 4 by 8 log-likelihood matrix.
#> 
#>           Estimate  SE
#> elpd_waic    -11.8 2.1
#> p_waic         2.3 0.7
#> waic          23.7 4.3
#> 
#> 4 (50.0%) p_waic estimates greater than 0.4. We recommend trying loo instead.