Execute simulations defined in a optic_simulation object
Source:R/dispatch-simulations.R
dispatch_simulations.Rd
Execute simulations defined in a optic_simulation object
Arguments
- object
Simulation scenarios object created using optic_simulation
- seed
Specified as either NULL or a numeric. Sets a seed, which is becomes an index in results, for each independent set of simulations in optic_simulation.
- use_future
Runs simulation scenarios in parallel. Default FALSE, set to TRUE if you have already setup a future plan (e.g., multiprocess, cluster, etc) and would like for the iterations to be run in parallel.
- verbose
Default TRUE. IF TRUE, provides details on what's currently running.
- ...
additional parameters to be passed to future_apply. User can pass future.globals and future.packages if your code relies on additional packages
Value
A list of dataframes, where each list entry contains results for a set of simulation parameters, with dataframes containing estimated treatment effects and summary statistics by model and draw.
Examples
# Set up a basic model and simulation scenario:
data(overdoses)
eff <- 0.1*mean(overdoses$crude.rate, na.rm = TRUE)
form <- formula(crude.rate ~ state + year + population + treatment_level)
mod <- optic_model(name = 'lin',
type = 'reg',
call = 'lm',
formula = form,
se_adjust = 'none')
sim <- optic_simulation(x = overdoses,
models = list(mod),
method = 'no_confounding',
unit_var = 'state',
treat_var = 'state',
time_var = 'year',
effect_magnitude = list(eff),
n_units = 2,
effect_direction = 'pos',
iters = 2,
policy_speed = 'instant',
n_implementation_periods = 1)
#> Number of Simulations: 1
#> Number of Models: 1
#> Iteration per Simulation : 2
#> Total number of Iterations to Run: 2
# Finally, dispatch the simulation:
dispatch_simulations(sim)
#> [[1]]
#> outcome se_adjustment estimate se variance t_stat p_value
#> 1 crude.rate none -1.298367 1.239787 1.537071 -1.047250 0.295263492
#> 2 crude.rate none -3.775589 1.302310 1.696011 -2.899148 0.003832122
#> mse model_name model_call
#> 1 10.98252 lin lm
#> 2 10.85485 lin lm
#> model_formula policy_speed
#> 1 crude.rate ~ state + year + population + treatment_level instant
#> 2 crude.rate ~ state + year + population + treatment_level instant
#> n_implementation_periods prior_control effect_magnitude n_units
#> 1 1 level 1.265073 2
#> 2 1 level 1.265073 2
#> effect_direction n mean_es_prior max_es_prior mean_es_outcome max_es_outcome
#> 1 pos 2 -0.3928205 0.5397018 -0.07062395 0.6169953
#> 2 pos 2 -0.4702902 0.8307804 -0.47402847 0.8230322
#> n_unique_enact_years mu1_prior mu0_prior sd_prior mu1_prior_old mu0_prior_old
#> 1 2 11.93194 12.04081 5.098109 11.93194 12.04081
#> 2 2 12.61818 12.02951 5.098109 12.61818 12.02951
#> sd_prior_old mu1 mu0 sd iter
#> 1 5.098109 14.24479 12.64049 6.651443 1
#> 2 5.098109 14.02575 12.64879 6.647637 2
#>