run | R Documentation |
This is the workhorse function of SimEngine that actually
runs the simulation. This should be called after all functions that set
up the simulation (set_config
, set_script
, etc.) have been
called.
run(sim)
sim |
A simulation object of class |
The original simulation object but with the results attached (along
with any errors and warnings). Results are stored in sim$results
,
errors are stored in sim$errors
, and warnings are stored in
sim$warnings
.
sim <- new_sim()
create_data <- function(n) { rpois(n, lambda=5) }
est_mean <- function(dat, type) {
if (type=="M") { return(mean(dat)) }
if (type=="V") { return(var(dat)) }
}
sim %<>% set_levels(n=c(10,100,1000), est=c("M","V"))
sim %<>% set_config(num_sim=1)
sim %<>% set_script(function() {
dat <- create_data(L$n)
lambda_hat <- est_mean(dat=dat, type=L$est)
return (list("lambda_hat"=lambda_hat))
})
sim %<>% run()
sim$results %>% print()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.