Learn R Programming

brms (version 1.3.1)

pp_check.brmsfit: Posterior Predictive Checks for brmsfit Objects

Description

Perform posterior predictive checks with the help of the bayesplot package.

Usage

"pp_check"(object, type, nsamples, group = NULL, x = NULL, newdata = NULL, re_formula = NULL, allow_new_levels = FALSE, incl_autocor = TRUE, subset = NULL, ntrys = 5, quiet = TRUE, ...)

Arguments

object
An object of class brmsfit.
type
Type of the ppc plot as given by a character string. Currently, the following plots (as names) are implemented: dens dens_overlay, ecdf_overlay, error_binned, error_hist, error_scatter, error_scatter_avg, error_scatter_avg_vs_x, freqpoly, freqpoly_grouped, hist, intervals, intervals_grouped, ribbon, ribbon_grouped, scatter, scatter_avg, scatter_avg_grouped, stat, stat_2d, stat_freqpoly_grouped, stat_grouped, and violin_grouped.
nsamples
Positive integer indicating how many posterior samples should be used. If NULL all samples are used. If not specified, the number of posterior samples is chosen automatically. Ignored if subset is not NULL.
group
Optional name of a grouping factor in the model by which to stratify the ppc plot. This argument is required for ppc *_grouped types and ignored otherwise.
x
Optional name of a variable in the model. Only used for ppc types having an x argument and ignored otherwise.
newdata
An optional data.frame for which to evaluate predictions. If NULL (default), the orginal data of the model is used.
re_formula
formula containing random effects to be considered in the prediction. If NULL (default), include all random effects; if NA, include no random effects.
allow_new_levels
A flag indicating if new levels of random effects are allowed (defaults to FALSE). Only relevant if newdata is provided.
incl_autocor
A flag indicating if autocorrelation parameters should be included in the predictions. Defaults to TRUE.
subset
A numeric vector specifying the posterior samples to be used. If NULL (the default), all samples are used.
ntrys
Parameter used in rejection sampling for truncated discrete models only (defaults to 5). For more details see predict.brmsfit.
quiet
A flag indicating whether messages produced by ggplot2 during the plotting process should be silenced. Default is TRUE.
...
Further arguments passed to the ppc functions of the bayesplot package.

Value

A ggplot object that can be further customized using the ggplot2 package.

Details

For a detailed explanation of each of the ppc functions, see the PPC documentation of the bayesplot package.

Examples

Run this code
## Not run: 
# fit <-  brm(count ~ log_Age_c + log_Base4_c * Trt_c
#             + (1|patient) + (1|visit),
#             data = epilepsy, family = poisson())
# 
# pp_check(fit)  # shows dens_overlay plot by default
# pp_check(fit, type = "error_hist", nsamples = 11)
# pp_check(fit, type = "scatter_avg", nsamples = 100)
# pp_check(fit, type = "stat_2d")
# ## End(Not run)

Run the code above in your browser using DataLab