Skip to contents

Central quantile intervals of the draws posterior_predict.mvgam() returns, one per observation.

Usage

# S3 method for class 'mvgam'
predictive_interval(object, prob = 0.9, ...)

Arguments

object

A fitted mvgam object.

prob

Numeric in (0, 1). The probability mass each interval holds. Defaults to 0.9.

...

Arguments of posterior_predict.mvgam(), such as newdata or incl_autocor.

Value

A numeric matrix with one row per observation and two columns, the lower and upper bounds.

Author

Nicholas J Clark

Examples

# \dontrun{
set.seed(13)
simdat <- sim_mvgam(family = poisson(), n_series = 1L,
                    n_timepoints = 120L, trend_model = AR())
mod <- mvgam(y ~ s(x, k = 5), trend_formula = ~ AR(p = 1),
             data = simdat$data_train, family = poisson(),
             chains = 2, silent = 2)
#> Warning: 8 of 2000 (0.0%) transitions ended with a divergence.
#> See https://mc-stan.org/misc/warnings for details.

# 90 percent intervals, one row per observation
intervals <- predictive_interval(mod)
head(intervals)
#>      5% 95%
#> [1,]  0   5
#> [2,]  6  20
#> [3,]  4  14
#> [4,]  4  15
#> [5,]  1   9
#> [6,]  2  13

# The share of observed counts the intervals cover
y <- simdat$data_train$y
mean(y >= intervals[, 1] & y <= intervals[, 2])
#> [1] 0.7777778

# Next: pp_check() plots the predictive draws against the data
# }