summarize_sim: Summarize Simulations Results

Description Usage Arguments Examples

View source: R/simulation_tools.R

Description

Summarize Simulations Results

Usage

1
summarize_sim(simulation_results, truth, ci_level = 0.95)

Arguments

simulation_results

A data.frame, tibble or similar with exactly two columns named "param_est" and "param_var" giving the estimate of a parameter of interest and estimate of its variance (based on a valid variance estimator specific to that parameter).Each row of this data structure corresponds to the parameter estimate and variance for a single iteration of several simulations.

truth

A numeric value giving the true value of the parameter of interest in the simulation setting.

ci_level

A numeric value giving the level of the confidence intervals to be generated around the parameter estimates and statistics computed to summarize the simulation.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
n_sim <- 1000
n_obs <- c(100, 10000)
mu <- 2
sim_results <- lapply(n_obs, function(sample_size) {
  estimator_sim <- lapply(seq_len(n_sim), function(iter) {
    y_obs <- rnorm(sample_size, mu)
    est_param <- mean(y_obs)
    est_var <- var(y_obs) / sample_size
    estimate <- tibble::as_tibble(list(
      param_est = est_param,
      param_var = est_var
    ))
    return(estimate)
  })
  estimates <- do.call(rbind, estimator_sim)
  return(estimates)
})
sim_summary <- lapply(sim_results, summarize_sim, truth = mu)

nhejazi/nima documentation built on March 10, 2020, 1:10 a.m.