Learn R Programming

modernBoot (version 0.1.1)

compare_methods_sim: Simulation Study: Compare Bootstrap Methods

Description

Runs a simulation study comparing different bootstrap and permutation methods. Useful for empirical evaluation of method performance and coverage.

Usage

compare_methods_sim(data_generator, Rsim = 100, Rboot = 1000, parallel = TRUE)

Value

A list of length Rsim. Each element is a list with two components:

bs

result from bs_mean applied to simulated dataset. Is NA if generation or computation failed.

bca

result from bca_ci applied to same dataset. Is NA if generation or computation failed.

Use to assess coverage rates: did true parameter fall within returned CIs? Interval width variation indicates method stability.

Arguments

data_generator

function taking no arguments and returning numeric vector of data. Called Rsim times to generate independent datasets. Example: function() rnorm(50, mean=5, sd=2) generates normal data. Function must not have side effects; should be deterministic given seed.

Rsim

integer number of simulated datasets to generate (default 100). Larger values (500+) provide more stable coverage rate estimates but increase computation time. Each simulation applies both bs_mean and bca_ci methods independently. Must be >= 1.

Rboot

integer number of bootstrap replicates used within each method per dataset (default 1000). Matches R parameter passed to bs_mean and bca_ci. Larger values (2000-5000) improve interval accuracy but increase total computation (total bootstrap samples = Rsim * Rboot). Must be >= 1.

parallel

logical enable parallel computation across simulations (default TRUE). Uses multisession plan to distribute simulations across available cores. User can override with plan(future::sequential) before calling for sequential execution.

Details

This function repeatedly generates data from data_generator and applies bs_mean and bca_ci methods. Results can be used to study coverage rates, interval width, and method robustness.

Examples

Run this code
# Fast example (runs in < 5 sec) - UNWRAPPED
set.seed(42)
generator <- function() rnorm(20)
# Very small simulation for demonstration
results_fast <- compare_methods_sim(generator, Rsim = 5, Rboot = 100)

# \donttest{
# Realistic simulation (takes > 5 sec) - WRAPPED in \donttest
set.seed(42)
generator <- function() rnorm(50, mean = 5, sd = 2)
sim_results <- compare_methods_sim(generator, Rsim = 50, Rboot = 500)

# Analyze coverage: does true mean (5) fall in each CI?
coverage_bs <- mean(sapply(sim_results, function(res) {
  res$bs$ci[1] <= 5 && 5 <= res$bs$ci[2]
}))
coverage_bs
# }

Run the code above in your browser using DataLab