| PPC-scatterplots | R Documentation |
Scatterplots of the observed data y vs. simulated/replicated data
yrep from the posterior predictive distribution. See the
Plot Descriptions and Details sections, below.
ppc_scatter(
y,
yrep,
...,
facet_args = list(),
size = 2.5,
alpha = 0.8,
ref_line = TRUE
)
ppc_scatter_avg(
y,
yrep,
...,
stat = "mean",
size = 2.5,
alpha = 0.8,
ref_line = TRUE
)
ppc_scatter_avg_grouped(
y,
yrep,
group,
...,
stat = "mean",
facet_args = list(),
size = 2.5,
alpha = 0.8,
ref_line = TRUE
)
ppc_scatter_data(y, yrep)
ppc_scatter_avg_data(y, yrep, group = NULL, stat = "mean")
y |
A vector of observations. See Details. |
yrep |
An |
... |
Currently unused. |
facet_args |
A named list of arguments (other than |
size, alpha |
Arguments passed to |
ref_line |
If |
stat |
A function or a string naming a function for computing the
posterior average. In both cases, the function should take a vector input
and return a scalar statistic. The function name is displayed in the
axis-label, and the underlying |
group |
A grouping variable of the same length as |
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_scatter()For each dataset (row) in yrep a scatterplot is generated showing y
against that row of yrep. For this plot yrep should only contain a
small number of rows.
ppc_scatter_avg()A single scatterplot of y against the average values of yrep, i.e.,
the points (x,y) = (average(yrep[, n]), y[n]), where each yrep[, n] is
a vector of length equal to the number of posterior draws and average()
is a summary statistic. Unlike for ppc_scatter(), for
ppc_scatter_avg() yrep should contain many draws (rows).
ppc_scatter_avg_grouped()The same as ppc_scatter_avg(), but a separate plot is generated for
each level of a grouping variable.
ppc_scatter_data(), ppc_scatter_avg_data()Data-preparation back ends for the ppc_scatter*() family of plotting
functions. ppc_scatter_data() returns a data frame with one row per
observation per yrep draw, while ppc_scatter_avg_data() returns a
data frame with one row per observation summarising yrep draws with
the chosen stat. Users can call these functions directly to create
custom visualizations with ggplot2.
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-distributions,
PPC-errors,
PPC-intervals,
PPC-loo,
PPC-overview,
PPC-test-statistics
y <- example_y_data()
yrep <- example_yrep_draws()
p1 <- ppc_scatter_avg(y, yrep)
p1
# don't draw line x=y
ppc_scatter_avg(y, yrep, ref_line = FALSE)
p2 <- ppc_scatter(y, yrep[20:23, ], alpha = 0.5, size = 1.5)
p2
# give x and y axes the same limits
lims <- ggplot2::lims(x = c(0, 160), y = c(0, 160))
p1 + lims
p2 + lims
# "average" function is customizable
ppc_scatter_avg(y, yrep, stat = "median", ref_line = FALSE)
# for ppc_scatter_avg_grouped the default is to allow the facets
# to have different x and y axes
group <- example_group_data()
ppc_scatter_avg_grouped(y, yrep, group)
# let x-axis vary but force y-axis to be the same
ppc_scatter_avg_grouped(y, yrep, group, facet_args = list(scales = "free_x"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.