When the observed random variable is multivariate, one individual plot per dimension will be drawn (i.e. the analysis will be carried out marginally). As with all visualizations from this package, colors are fully customizable via a theme. Note that this method is only available for full Bayesian estimation run via Markov-chain Monte Carlo.

plot_ppredictive(stanfit, type = "", r = NULL, subset = NULL,
  chain = 1, fun = NULL, fun1 = NULL, fun2 = NULL,
  boxplotControl = NULL, cumulativeControl = NULL,
  densityControl = NULL, funControl = NULL, fun1Control = NULL,
  fun2Control = NULL, ksControl = NULL, klControl = NULL,
  main = NULL)

Arguments

stanfit

An object returned by either fit or draw_samples.

type

An optional vector of character strings with the names of the analysis to include in the plot. These may be density (kernel density curves of the observation variable), cumulative (kernel cumulative density curves of the observation variable), boxplot (boxplots of the observation variable), histogram (histogram of the values returned by fun), scatterplot (scatterplot of the values returned by fun1 and fun2), kl (histogram of the empirical Kullback-Leibler divergence), ks (histogram of the Kolmogorov-Smirnov statistic). All plots show the actual sample and many draws from the posterior predictive density. Note that more than one type may be plotted at the same time. It allows for partial matching. It defaults to none.

r

An optional numeric vector with the numbers of the dimensions of the observation vector to be plotted. It defaults to plotting all variables.

subset

An optional boolean vector indicating with TRUE which elements of the observation vector should be included in the analysis (some plots may become slow with large datasets). It defaults to NULL, meaning all the sample units.

chain

An optional integer number between 1 and the number of chains M. Only the samples generated by the selected chain are considered. It defaults to the first chain.

fun

An optional function summarizing the whole sample into a single value (e.g. median). This function is applied ot each sample (actual and generated) and the values returned are plotted in the histogram.

fun1

An optional function summarizing the whole sample into a single value (e.g. mean). This function is applied ot each sample (actual and generated) and the values returned are plotted in the horizontal axis of the scatterplot.

fun2

An optional function summarizing the whole sample into a single value (e.g. sd). This function is applied ot each sample (actual and generated) and the values returned are plotted in the vertical axis of the scatterplot.

boxplotControl

Arguments to be passed to boxplot if the argument type includes "boxplot".

cumulativeControl

Arguments to be passed to quantile if the argument type includes "cumulative" (e.g. use `probs` to set a range if the default is innapropiate).

densityControl

Arguments to be passed to density if the argument type includes "density".

funControl

Arguments to be passed to `fun` if the argument type includes "histogram".

fun1Control

Arguments to be passed to `fun1` if the argument type includes "scatterplot".

fun2Control

Arguments to be passed to `fun2` if the argument type includes "scatterplot".

ksControl

Arguments to be passed to ks.test if the argument type includes "ks".

klControl

Arguments to compute the empirical Kullback-Leibler divergence if the argument type includes "kl". It may include two-sized vectors with the lower and upper bounds of the discretization range (`yRange` and `yPredRange`) and the number of bins (`yNBins` and `yPredNBins`).

main

An optional character string with the overall title for the plot.

Note

If the user was surprised to find the Kolmogorov-Smirnov statistic in a Bayesian software, simply note that we use it as a measure of similarity between two samples from continuous distributions. Data analysis and modeling decissions do not rely on hypothesis testing.

See also

Examples

# NOT RUN {
plot_ppredictive(
  myFit,
  type = c("density", "cumulative", "boxplot",
           "histogram", "scatterplot", "ks"),
  fun = mean, fun1 = mean, fun2 = sd
)

plot_ppredictive(
  myFit,
  type = c("density", "cumulative", "ks", "kl"),
  klControl = list(yNBins = 20, yPredNBins = 20)
)
# }