predict.dynamic_fit: In-sample fitted values and posterior predictive replicates

View source: R/predict.R

predict.dynamic_fitR Documentation

In-sample fitted values and posterior predictive replicates

Description

In-sample fitted values and posterior predictive replicates

Usage

## S3 method for class 'dynamic_fit'
predict(
  object,
  type = c("mean", "response", "prob"),
  conditional = FALSE,
  probs = c(0.025, 0.5, 0.975),
  ...
)

Arguments

object

A "dynamic_fit" object.

type

"mean" (default) returns the posterior of the mean of y; "response" returns posterior predictive replicates of y. For the multinomial family "prob" returns the posterior of the category shares p_{t,k} (the mean is then the expected count N_t p_{t,k}).

conditional

Logical. Leave FALSE (the default) for anything compared against observed data – posterior predictive checks, calibration – and set TRUE only to inspect the latent intensity process. With FALSE, means and replicates come from the full zero-inflated model (the gate is included, so structural zeros are reproduced); with TRUE, they are conditional on the gate being open, i.e. drawn straight from the Poisson/binomial observation model, and show systematically too few zeros under zero inflation. Without zero inflation the two versions are identical, and the argument is ignored for the multinomial family (which has no gate). See DynCount-package for the gate notation.

probs

Quantile probabilities for the summary. Default c(0.025, 0.5, 0.975).

...

Unused.

Value

A list with summary (a data frame, one row per observation) and draws (the underlying draws matrix, draws x time). For the multinomial family summary is in long format with one row per observation and category (columns time, category, observed, ...) and draws is a ⁠draws x time x K⁠ array.

Examples

sim <- simulate_dynamic_poisson(40, 0.2, 2, seed = 1)
fit <- fit_dynamic_model(sim$y, nsave = 200, nburn = 100, seed = 1)
head(predict(fit)$summary)                     # posterior of the mean of y
head(predict(fit, type = "response")$summary)  # posterior predictive

DynCount documentation built on Sept. 28, 2026, 5:10 p.m.