SBC: SBC class

Description Usage Format Details Methods Fields Examples

Description

Generator class for creating new instances of the SBC R6 class.

Usage

1

Format

An R6 object of type SBC

Details

See vignette('intro-to-sbc', package = 'sbcrs') for an accessible introduction to simulation-based calibration.

Methods

$new(data, params, modeled_data, sampling)

Create a new SBC object, passing in functions to generate data and parameters, and draw samples.

data = function(seed) {}

A function with signature function(seed) that returns a named list.

params = function(seed, data) {}

A function with signature function(seed, data) that returns a named list.

modeled_data = function(seed, data, params) {}

A function with signature function(seed, data, params) that returns a named list.

sampling = function(seed, data, params, modeled_data, iters) {}

A function with signature function(seed, data, params, modeled_data, iters) that returns a stanfit object run for iters sampling iterations.

$calibrate(N, L, keep_stan_fit = TRUE)

Run the calibration procedure.

N

The number of times to simulate parameters and recover via MCMC.

L

The number of MCMC samples to retain when calculating rank statistics.

keep_stan_fit = TRUE

If TRUE (the default), then the stan_fit objects returned by the sampling function are retained.

$summary(var = NULL)

Summarize results of a previous calibration. Optionally specify a parameter var.

$plot(var = NULL)

Plot a histogram of ranks from a previous calibration. Optionally specify a parameter var.

Fields

$calibrations

A list of N calibrations created by calling $calibrate. Each item is list with the following named elements:

data

Output from call to the data function.

params

Output from call to the params function.

modeled_data

Output from call to the modeled_data function.

samples

A stanfit object returned from call to the sampling function if keep_stan_fit = TRUE, otherwise NULL.

ranks

A named list matching items in params. Values express the number of samples out of a maximum L with sampled$var < param$var, where sampled$var indicates a vector of L samples of parameter var.

n_eff

The smallest effective sample size for any parameter in any of the stan_fit objects.

iters

The number of MCMC iterations (before thinning) in the stan_fit object.

seed

The value of seed passed to the data, parameter, and sampling functions.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
## Not run: 
sbc <- SBC$new(
  data = function(seed) {
    list(n = 10)
  },
  params = function(seed, data) {
    list(mu = rnorm(1))
  },
  modeled_data = function(seed, data, params) {
    list(y = rnorm(data$n, mu, 1))
  },
  sampling = function(seed, data, params, modeled_data) {
    stan_object <- NULL # usually a call to rstan::sampling()
    stan_object
  }
)

## End(Not run)

jasonmtroos/sbcrs documentation built on Nov. 4, 2019, 2:20 p.m.