This is a wrapper function that produces a sequence of plots illustrating the posterior predictive distribution. Optional plots are:
An envelope plot of the posterior predictive distribution as a time series,
overlayed with the data values (if plot_data=TRUE
is used)
The centered posterior predictive distributions, as plotted by ts_postpred,
and overlayed with the data residuals (if plot_residuals=TRUE
is used)
The approximate residual standard deviation, calculated from a moving
window of 10 data points in sequence. (if plot_sd=TRUE
is used)
These three plots are repeated, for a sequence of different variables expressed on the x-axis, potentially highlighting different features of the dataset or model structure:
The data sequence (if whichplots=
contains 1
)
The x=
variable supplied (if whichplots=
contains 2
)
The y=
variable supplied (if whichplots=
contains 3
)
The fitted values, as estimated by the posterior predictive median
(if whichplots=
contains 4
)
While not an omnibus posterior predictive check, this plot can be useful for detecting an overparameterized model, or else improper specification of observation error.
It should be noted that this function will only produce meaningful results with a vector of data, as opposed to a single value.
The posterior predictive distribution can be specified in two possible ways:
either a single output object from jagsUI
with an associated parameter
name, or as a matrix or data.frame
of posterior samples.
plot_postpred(
ypp,
y,
p = NULL,
x = NULL,
whichplots = c(1, 2, 4),
plot_data = TRUE,
plot_residuals = TRUE,
plot_sd = TRUE,
pch = 1,
pointcol = 1,
lines = FALSE,
...
)
NULL
Either a matrix or data.frame
of posterior samples, or an
output object returned from jagsUI
and a supplied parameter name
The associated data vector
A character name, if a jagsUI
object is passed to ypp
The time measurements associated with time series y
. If the default
NULL
is accepted, associated plots will be suppressed.
A vector of which sets of plots to produce (that is, with
respect to which variables on the x-axis). See above for details. Defaults
to c(1, 2, 4)
.
Whether to produce plots associated with the data (y=
)
time series and untransformed posterior predictive distribution.
Defaults to TRUE
.
Whether to produce plots associated with the residual
time series and posterior predictive residuals.
Defaults to TRUE
.
Whether to produce plots of the moving-window standard deviation
of the residuals.
Defaults to TRUE
.
Plotting character for points, which will accept a vector input.
See points. Defaults to 1
.
Plotting color for points. Defaults to 1
.
Whether to add a line linking data time series points.
Defaults to FALSE
.
Additional arguments to envelope
Matt Tyers
qq_postpred, ts_postpred, check_Rhat, check_neff, traceworstRhat, plotRhats
# first, a quick look at the example data...
str(SS_data)
str(SS_out$sims.list$ypp)
# recommended usage
parmfrow <- par("mfrow") # storing graphics state
par(mfcol = c(3,3)) # a recommended setting to organize plots
plot_postpred(ypp=SS_out, p="ypp", y=SS_data$y, x=SS_data$x)
par(mfrow = parmfrow) # resetting graphics state
Run the code above in your browser using DataLab