| PPC-distributions | R Documentation |
Compare the empirical distribution of the data y to the distributions of
simulated/replicated data yrep from the posterior predictive distribution.
See the Plot Descriptions section, below, for details.
ppc_data(y, yrep, group = NULL)
ppc_dens_overlay(
y,
yrep,
...,
size = 0.25,
alpha = 0.7,
trim = FALSE,
bw = NULL,
adjust = NULL,
kernel = NULL,
bounds = NULL,
n_dens = NULL
)
ppc_dens_overlay_grouped(
y,
yrep,
group,
...,
size = 0.25,
alpha = 0.7,
trim = FALSE,
bw = NULL,
adjust = NULL,
kernel = NULL,
bounds = NULL,
n_dens = NULL
)
ppc_ecdf_overlay(
y,
yrep,
...,
discrete = deprecated(),
pad = TRUE,
size = 0.25,
alpha = 0.7
)
ppc_ecdf_overlay_grouped(
y,
yrep,
group,
...,
discrete = deprecated(),
pad = TRUE,
size = 0.25,
alpha = 0.7
)
ppc_dens(y, yrep, ..., trim = FALSE, size = 0.5, alpha = 1, bounds = NULL)
ppc_hist(
y,
yrep,
...,
binwidth = NULL,
bins = NULL,
breaks = NULL,
freq = TRUE
)
ppc_freqpoly(
y,
yrep,
...,
binwidth = NULL,
bins = NULL,
freq = TRUE,
size = 0.5,
alpha = 1
)
ppc_freqpoly_grouped(
y,
yrep,
group,
...,
binwidth = NULL,
bins = NULL,
freq = TRUE,
size = 0.5,
alpha = 1
)
ppc_boxplot(y, yrep, ..., notch = TRUE, size = 0.5, alpha = 1)
ppc_dots(y, yrep, ..., binwidth = NA, quantiles = 100, freq = TRUE)
ppc_violin_grouped(
y,
yrep,
group,
...,
probs = c(0.1, 0.5, 0.9),
size = 1,
alpha = 1,
y_draw = c("violin", "points", "both"),
y_size = 1,
y_alpha = 1,
y_jitter = 0.1
)
ppc_pit_ecdf(
y,
yrep,
...,
pit = NULL,
K = NULL,
prob = 0.99,
plot_diff = FALSE,
interpolate_adj = NULL,
method = NULL,
test = NULL,
gamma = NULL,
linewidth = NULL,
color = NULL,
help_text = NULL,
pareto_pit = NULL,
help_text_shrinkage = NULL
)
ppc_pit_ecdf_grouped(
y,
yrep,
group,
...,
K = NULL,
pit = NULL,
prob = 0.99,
plot_diff = FALSE,
interpolate_adj = NULL,
method = NULL,
test = NULL,
gamma = NULL,
linewidth = NULL,
color = NULL,
help_text = NULL,
pareto_pit = NULL,
help_text_shrinkage = NULL
)
For Binomial data, the plots may be more useful if the input contains the "success" proportions (not discrete "success" or "failure" counts).
The plotting functions return a ggplot object that can be further
customized using the ggplot2 package. The functions with suffix
_data() return the data that would have been drawn by the plotting
function.
ppc_hist(), ppc_freqpoly(), ppc_dens(), ppc_boxplot()A separate histogram, shaded frequency polygon, smoothed kernel density
estimate, or box and whiskers plot is displayed for y and each
dataset (row) in yrep. For these plots yrep should therefore
contain only a small number of rows. See the Examples section.
ppc_dots()A dot plot plot is displayed for y and each dataset (row) in yrep.
For these plots yrep should therefore contain only a small number of rows.
See the Examples section.
ppc_freqpoly_grouped()A separate frequency polygon is plotted for each level of a grouping
variable for y and each dataset (row) in yrep. For this plot
yrep should therefore contain only a small number of rows. See the
Examples section.
ppc_ecdf_overlay(), ppc_dens_overlay(),
ppc_ecdf_overlay_grouped(), ppc_dens_overlay_grouped()Kernel density or empirical CDF estimates of each dataset (row) in yrep
are overlaid, with the distribution of y itself on top (and in a darker
shade). For an example of ppc_dens_overlay() also see Gabry et al.
(2019).
ppc_violin_grouped()The density estimate of yrep within each level of a grouping
variable is plotted as a violin with horizontal lines at notable
quantiles. y is overlaid on the plot either as a violin, points, or
both, depending on the y_draw argument.
ppc_pit_ecdf(), ppc_pit_ecdf_grouped()The PIT-ECDF of empirical PIT values for y relative to corresponding
draws in yrep (or precomputed values supplied via pit).
With method = "independent", the plot shows 100 * prob% central
simultaneous confidence intervals under an independence assumption.
With method = "correlated", the plot uses a dependence-aware
uniformity assessment and can highlight suspicious regions.
See Säilynoja et al. (2022), Säilynoja et al. (2026), and
Tesso & Vehtari (2026) for details.
Note that the default "independent" method is superseded by
the "correlated" method (Tesso & Vehtari, 2026) which accounts for
dependent LOO-PIT values.
ppc_data()This function prepares data for plotting with ggplot2 and doesn't itself make any plots. Users can call it directly to obtain the underlying data frame that (in most cases) is passed to ggplot2. This is useful when you want to customize the appearance of PPC plots beyond what the built-in plotting functions allow, or when you want to construct new types of PPC visualizations based on the same underlying data.
Gabry, J. , Simpson, D. , Vehtari, A. , Betancourt, M. and Gelman, A. (2019), Visualization in Bayesian workflow. J. R. Stat. Soc. A, 182: 389-402. doi:10.1111/rssa.12378. (journal version, arXiv preprint, code on GitHub)
Säilynoja, T., Bürkner, P.-C., and Vehtari, A. (2022). Graphical test for discrete uniformity and its applications in goodness-of-fit evaluation and multiple sample comparison. Statistics and Computing. 32(2), 32. doi:10.1007/s11222-022-10090-6. arXiv preprint: https://arxiv.org/abs/2103.10522
Säilynoja, T., Johnson, A., Martin, O., and Vehtari, A. (2026). Recommendations for visual predictive checks in Bayesian workflow. Journal of Visualization and Interaction. 1(1). doi:10.54337/jovi.v1i1.11478.
Tesso, H., and Vehtari, A. (2026). LOO-PIT predictive model checking. arXiv preprint arXiv:2603.02928. doi:10.48550/arXiv.2603.02928.
Gelman, A., Carlin, J. B., Stern, H. S., Dunson, D. B., Vehtari, A., and Rubin, D. B. (2013). Bayesian Data Analysis. Chapman & Hall/CRC Press, London, third edition. (Ch. 6)
Other PPCs:
PPC-calibration,
PPC-censoring,
PPC-discrete,
PPC-errors,
PPC-intervals,
PPC-loo,
PPC-overview,
PPC-scatterplots,
PPC-test-statistics
color_scheme_set("brightblue")
y <- example_y_data()
yrep <- example_yrep_draws()
group <- example_group_data()
dim(yrep)
ppc_dens_overlay(y, yrep[1:25, ])
# ppc_ecdf_overlay
ppc_ecdf_overlay(y, yrep[sample(nrow(yrep), 25), ])
# PIT-ECDF and PIT-ECDF difference plot of the PIT values of y compared to
# yrep with 99% simultaneous confidence bands.
ppc_pit_ecdf(y, yrep, prob = 0.99, plot_diff = FALSE)
ppc_pit_ecdf(y, yrep, prob = 0.99, plot_diff = TRUE)
# for ppc_hist,dens,freqpoly,boxplot,dots definitely use a subset yrep rows so
# only a few (instead of nrow(yrep)) histograms are plotted
ppc_hist(y, yrep[1:8, ])
color_scheme_set("red")
ppc_boxplot(y, yrep[1:8, ])
# wizard hat plot
color_scheme_set("blue")
ppc_dens(y, yrep[200:202, ])
# dot plot
ppc_dots(y, yrep[1:8, ])
# frequency polygons
ppc_freqpoly(y, yrep[1:3, ], alpha = 0.1, size = 1, binwidth = 5)
ppc_freqpoly_grouped(y, yrep[1:3, ], group) + yaxis_text()
# if groups are different sizes then the 'freq' argument can be useful
ppc_freqpoly_grouped(y, yrep[1:3, ], group, freq = FALSE) + yaxis_text()
# density and distribution overlays by group
ppc_dens_overlay_grouped(y, yrep[1:25, ], group = group)
ppc_ecdf_overlay_grouped(y, yrep[1:25, ], group = group)
# PIT-ECDF plots of the PIT values by group
# with 99% simultaneous confidence bands.
ppc_pit_ecdf_grouped(y, yrep, group=group, prob=0.99)
# don't need to only use small number of rows for ppc_violin_grouped
# (as it pools yrep draws within groups)
color_scheme_set("gray")
ppc_violin_grouped(y, yrep, group, size = 1.5)
ppc_violin_grouped(y, yrep, group, alpha = 0)
# change how y is drawn
ppc_violin_grouped(y, yrep, group, alpha = 0, y_draw = "points", y_size = 1.5)
ppc_violin_grouped(y, yrep, group,
alpha = 0, y_draw = "both",
y_size = 1.5, y_alpha = 0.5, y_jitter = 0.33
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.