posterior_check: Tests accuracy of posterior distribution

Description Usage Arguments Value Examples

View source: R/bayes.R

Description

Given black-box functions prior_draw, data_draw, and posterior_draw, checks that the joint distribution of the prior and data match the joint distribution of the posterior and data. Draws a number of (parameter, data, posterior) triplets and then partitions data into clusters. Checks that the first two moments of the parameter are consistent with the first two moments of the posterior within each cluster.

Usage

1
2
posterior_check(prior_draw, data_draw, posterior_draw, n = 1000, k = 10,
  mc.cores = 1)

Arguments

prior_draw

function() which produces a parameter vector theta

data_draw

function(theta) which produces data vector x

posterior_draw

function(x) which produces theta_hat from the posterior conditional on x and the supplied prior

n

Number of (theta, x) samples to draw

k

Number of clusters to split the data

mc.cores

Number of parallel cores to use

Value

List with global p-value for equality of posterior and prior in each of k clusters, as well as generated data and clusters

Examples

1
2
3
4
5
p <- 3
prior_draw <- function() rnorm(p)
data_draw <- function(theta) theta + rnorm(p)
posterior_draw <- function(x) (x + rnorm(p))/2
res <- posterior_check(prior_draw, data_draw, posterior_draw)

snarles/testUtils documentation built on May 30, 2019, 5:05 a.m.