summarize | R Documentation |
This function calculates summary statistics for simulation results, including descriptive statistics (e.g. measures of center or spread) and inferential statistics (e.g. bias or confidence interval coverage). All summary statistics are calculated over simulation replicates within a single simulation level.
summarize(sim, ..., mc_se = FALSE)
sim |
A simulation object of class |
... |
One or more lists, separated by commas, specifying desired
summaries of the
|
mc_se |
A logical argument indicating whether to compute Monte Carlo
standard error and associated confidence interval for inferential summary
statistics. This applies only to the |
For all inferential summaries there are three ways to specify
truth
: (1) a single number, meaning the estimand is the same
across all simulation replicates and levels, (2) a numeric vector of the
same length as the number of rows in sim$results
, or (3) the name
of a variable in sim$results
containing the estimand of interest.
There are two ways to specify the confidence interval bounds for
coverage
. The first is to provide an estimate
and its
associated se
(standard error). These should both be variables in
sim$results
. The function constructs a 95% Wald-type confidence
interval of the form (estimate-1.96*se, estimate+1.96*se)
. The
alternative is to provide lower
and upper
bounds, which
should also be variables in sim$results
. In this case, the
confidence interval is (lower
, upper
). The coverage is the
proportion of simulation replicates for a given level combination in
which truth
lies within the interval.
A data frame containing the result of each specified summary function
as a column, for each of the simulation levels. The column n_reps
returns the number of successful simulation replicates within each level.
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=5)
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 %>% summarize(
list(stat = "mean", name="mean_lambda_hat", x="lambda_hat"),
list(stat = "mse", name="lambda_mse", estimate="lambda_hat", truth=5)
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.