Skip to contents

Plot posterior (default) or prior (prior = TRUE) predictive checks. This is a convenience wrapper around the bayesplot::ppc_*() methods. See prior predictive checks for an example.

Usage

# S3 method for class 'mcpfit'
pp_check(
  object,
  type = "dens_overlay",
  facet_by = NULL,
  newdata = NULL,
  prior = FALSE,
  group_effects = TRUE,
  arma = "replicate",
  ndraws = 100,
  nsamples = lifecycle::deprecated(),
  varying = lifecycle::deprecated(),
  ...
)

Arguments

object

An mcpfit object.

type

String specifying the type of plot. See bayesplot::available_ppc() for available plot types, omitting the "ppc_" prefix (e.g., "dens_overlay", "ribbon", "intervals").

facet_by

Name of a grouping column used by group-level effects.

newdata

A tibble or a data.frame containing predictors in the model.

  • If NULL (default), the original data is used.

  • Grouping factors must only contain levels from the fitted data. Use group_effects = FALSE to predict without group-level effects, e.g., for new groups.

  • For models with ar() or ma(): fitted(), residuals(), log_lik(), and predict() condition on the response history by default, so newdata must include the response. For fitted(), predict(), and residuals(), missing response histories are supported only in the original fitted data, using retained posterior imputations as histories. Predictions are fresh response draws, including at missing rows. With arma = "replicate", predict() and posterior_predict() generate fresh response series recursively, so their newdata need only contain predictors and required response auxiliaries. log_lik() is unavailable when a missing response enters a later observed history.

  • For models with y | weights(): Require the weights column except for fitted() and predict().

prior

Logical. Evaluate prior draws (TRUE) instead of posterior draws (FALSE, default). The selected draws must be available; prior-only fits require prior = TRUE.

group_effects

Group-level effects to include. One of:

  • TRUE All group-level deviations.

  • FALSE or NA No group-level deviations, i.e., population-level predictions. Like re_formula = NA in {brms}.

  • "cp" or "predictor": All group-level deviations belonging to that part of the model.

  • Character vector of group-level parameter names, e.g., c("cp_1_id", "x_2_id"). [Experimental] * is a wildcard, e.g., "state*_1_id" selects all levels of a factor and "*_id" selects all effects by id. See names using ranef(fit). Can be combined, e.g., c("cp", "sigma_*").

arma

How to include AR and MA effects.

  • TRUE: Condition on the observed response history, i.e., one-step-ahead evaluation of the GARMA residual recurrence. Requires the response variable in newdata.

  • FALSE: Disregard AR and MA effects. For family = gaussian(), predict() uses only sigma for residuals.

  • "replicate": Generate fresh response series recursively instead of conditioning on the observed responses. Only for predictions: predict(), posterior_predict(), and pp_check() (where it is the default). Applies equally to prior and posterior draws.

For posterior evaluation of the original data, retained JAGS imputations supply missing GARMA histories. In models with group-level effects, this currently requires all such effects (group_effects = TRUE).

ndraws

Integer or NULL. Number of posterior draws to return/summarise. NULL means "all". More draws trade speed for accuracy.

nsamples

Deprecated. Use ndraws instead.

varying

Deprecated. Use group_effects instead.

...

Further arguments passed to bayesplot::ppc_type(y, yrep, ...)

Value

A ggplot2 object for single plots. Enriched by patchwork for faceted plots.

Details

Missing responses are omitted from the observed-data check. LOO predictive checks use posterior draws and the original fitted data, so they do not support prior = TRUE or newdata. For GARMA models, they default to arma = TRUE to match the one-step-ahead log-likelihood used for the LOO weights.

Author

Jonas Kristoffer Lindeløv jonas@lindeloev.dk

Examples

# \donttest{
pp_check(demo_fit)

pp_check(demo_fit, type = "ecdf_overlay")

#pp_check(some_group_fit, type = "loo_intervals", facet_by = "id")
# }