The distribution of a (test) statistic T(ypred), or a pair of (test)
statistics, over the simulations from the posterior or prior predictive
distribution. Each of these functions makes the same plot as the
corresponding ppc_ function but without comparing to
any observed data y. The Plot Descriptions section at
PPC-test-statistics has details on the individual plots.
ppd_stat(
ypred,
stat = "mean",
show_marginal = FALSE,
...,
discrete = FALSE,
binwidth = NULL,
bins = NULL,
breaks = NULL,
freq = !show_marginal
)ppd_stat_grouped(
ypred,
group,
stat = "mean",
show_marginal = FALSE,
...,
discrete = FALSE,
facet_args = list(),
binwidth = NULL,
bins = NULL,
breaks = NULL,
freq = !show_marginal
)
ppd_stat_freqpoly(
ypred,
stat = "mean",
show_marginal = FALSE,
...,
facet_args = list(),
binwidth = NULL,
bins = NULL,
freq = TRUE
)
ppd_stat_freqpoly_grouped(
ypred,
group,
stat = "mean",
show_marginal = FALSE,
...,
facet_args = list(),
binwidth = NULL,
bins = NULL,
freq = TRUE
)
ppd_stat_2d(
ypred,
stat = c("mean", "sd"),
show_marginal = FALSE,
...,
size = 2.5,
alpha = 0.7
)
ppd_stat_data(ypred, group = NULL, stat, show_marginal = FALSE)
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.
An S by N matrix of draws from the posterior (or prior)
predictive distribution, or a posterior::draws object. The number of
rows, S, is the size of the posterior (or prior) sample used to generate
ypred. The number of columns, N, is the number of predicted
observations.
A single function or a string naming a function, except for the 2D plot which requires a vector of exactly two names or functions. In all cases the function(s) should take a vector input and return a scalar statistic. If specified as a string (or strings) then the legend will display the function name(s). If specified as a function (or functions) then generic naming is used in the legend.
Plot the marginal PPD along with the ypreds.
Currently unused.
For ppc_stat() and ppc_stat_grouped(), if TRUE then a
bar chart is used instead of a histogram.
Passed to ggplot2::geom_histogram(), ggplot2::geom_area(),
and ggdist::stat_dots() to override the default binwidth.
Passed to ggplot2::geom_histogram() and ggplot2::geom_area()
to override the default binning.
Passed to ggplot2::geom_histogram() as an alternative to
binwidth.
For histograms and frequency polygons, freq=TRUE (the default)
puts count on the y-axis. Setting freq=FALSE puts density on the y-axis.
(For many plots the y-axis text is off by default. To view the count or
density labels on the y-axis see the yaxis_text() convenience
function.)
A grouping variable of the same length as y.
Will be coerced to factor if not already a factor.
Each value in group is interpreted as the group level pertaining
to the corresponding observation.
A named list of arguments (other than facets) passed
to ggplot2::facet_wrap() or ggplot2::facet_grid()
to control faceting. Note: if scales is not included in facet_args
then bayesplot may use scales="free" as the default (depending
on the plot) instead of the ggplot2 default of scales="fixed".
For the 2D plot only, arguments passed to
ggplot2::geom_point() to control the appearance of scatterplot points.
For Binomial data, the plots may be more useful if the input contains the "success" proportions (not discrete "success" or "failure" counts).
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)
Other PPDs:
PPD-distributions,
PPD-intervals,
PPD-overview
yrep <- example_yrep_draws()
ppd_stat(yrep)
ppd_stat(yrep, stat = "sd") + legend_none()
ppd_stat(yrep, show_marginal = TRUE)
# use your own function for the 'stat' argument
color_scheme_set("brightblue")
q25 <- function(y) quantile(y, 0.25)
ppd_stat(yrep, stat = "q25") # legend includes function name
ppd_stat(yrep, stat = "q25", show_marginal = TRUE)
Run the code above in your browser using DataLab