simulate_decision_rule {oncomsm} | R Documentation |
Simulate results under a custom decision rule
Description
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 |
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 |
Details
The sampling is implementing using furrr::future_map()
and thus
supports parallel execution when specifying a future::plan()
.
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.
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)