Skip to contents

simulate_decision_rule() simulates from the prior or posterior predictive distribution of a model and applies a custom decision rule to each simulated data set.

Usage

simulate_decision_rule(
  model,
  n_per_group,
  decision_rule,
  data = NULL,
  parameter_sample = NULL,
  seed = NULL,
  nsim = 1L
)

Arguments

model

model to use for sampling

n_per_group

group size

decision_rule

a function with signature rule(mdl, data, ...) returning a data frame with results from a applying the decision rule to data setdata, typically contains a column group_id and a one column per decision/result.

data

a data frame with visit data to condition on

parameter_sample

an optional parameter sample to reuse

seed

optional fixed seed

nsim

the number of resamples to draw from the predictive distribution

Value

A data frame with columns iter (the resample index) and any columns returned by decision_rule applied to each of the nsim datasets sampled from the predictive distribution.

Details

The sampling is implementing using furrr::future_map() and thus supports parallel execution when specifying a future::plan().

Examples

mdl <- create_srpmodel(A = define_srp_prior())
rule <- function(model, data) {
  tibble::tibble(decision = sample(c(0,1), 1))
}
simulate_decision_rule(mdl, 5, rule, nsim = 3)
#> # A tibble: 3 × 2
#>    iter decision
#>   <int>    <dbl>
#> 1     1        0
#> 2     2        0
#> 3     3        0