Description Usage Format Details Methods Fields Examples
Generator class for creating new instances of the SBC R6 class.
1 |
An R6 object of type SBC
See vignette('intro-to-sbc', package = 'sbcrs') for an accessible introduction to simulation-based calibration.
$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.
NThe number of times to simulate parameters and recover via MCMC.
LThe number of MCMC samples to retain when calculating rank statistics.
keep_stan_fit = TRUEIf 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.
$calibrationsA list of N calibrations created by calling $calibrate. Each item is list with the following named elements:
Output from call to the data function.
Output from call to the params function.
Output from call to the modeled_data function.
A stanfit object returned from call to the sampling function if keep_stan_fit = TRUE, otherwise NULL.
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.
The smallest effective sample size for any parameter in any of the stan_fit objects.
The number of MCMC iterations (before thinning) in the stan_fit object.
The value of seed passed to the data, parameter, and sampling functions.
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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.