# The following is a toy example of a simulation, illustrating the use of
# the use_method function.
sim <- new_sim()
create_data <- function(n) { rpois(n, lambda=5) }
est_mean_1 <- function(dat) { mean(dat) }
est_mean_2 <- function(dat) { var(dat) }
sim %<>% set_levels(
"n" = c(10, 100, 1000),
"estimator" = c("est_mean_1", "est_mean_2")
)
sim %<>% set_config(num_sim=1)
sim %<>% set_script(function() {
dat <- create_data(L$n)
lambda_hat <- use_method(L$estimator, list(dat))
return (list("lambda_hat"=lambda_hat))
})
sim %<>% run()
sim$results
Run the code above in your browser using DataLab