Learn R Programming

DPCD (version 0.0.1)

post_predictive: Posterior Predictive Check

Description

This function simulates dissimilarities from the posterior predictive distribution of a specified DPCD model and optionally plots the density of the simulated dissimilarities against the observed dissimilarities.

Usage

post_predictive(
  mcmc_samples,
  dis_matrix,
  nsim = 1000,
  scale = TRUE,
  plot = TRUE
)

Value

A matrix of simulated dissimilarities from the posterior predictive distribution with nsim rows and n * (n-1) / 2 columns, where n is the number of objects (i.e. the number of rows/columns of dis_matrix).

Arguments

mcmc_samples

An object of class mcmc or mcmc.list containing posterior samples from a DPCD model fit using run_dpcd(). Both the latent positions x and the error variance sigma_sq must be included in mcmc_samples.

dis_matrix

A distance structure such as that returned by stats::dist or a full symmetric matrix containing the dissimilarities.

nsim

Number of datasets to simulate from the posterior predictive distribution.

scale

Logical argument indicating whether to scale the dissimilarities so that the maximum value is 1.

plot

Logical argument indicating whether to plot the simulated dissimilarities against the observed dissimilarities. See details for more information.

Details

A posterior predictive check is used to assess if datasets drawn from the posterior predictive distribution are consistent with the observed data. Posterior predictive checks differ from prior predictive checks in that they incorporate information from the observed data. If the model fits the data well, the observed dissimilarities should look similar to dissimilarities simulated from the posterior predictive distribution.

If plot = TRUE, a plot is created to compare the density of the observed dissimilarities to the densities of the dissimilarities simulated from the posterior predictive distribution using bayesplot::ppc_dens_overlay().

See run_dpcd() for details on the DPCD models and hyperparameters.

References

Gabry, J., Simpson, D., Vehtari, A., Betancourt, M., & Gelman, A. (2019). Visualization in Bayesian workflow. Journal of the Royal Statistical Society A, 182(2), 389–402. https://doi.org/10.1111/rssa.12378

See Also

run_dpcd()

Examples

Run this code
ppc <- post_predictive(mcmc_example, dis_mat_example, nsim = 100, plot = TRUE)

Run the code above in your browser using DataLab