Extrapolate coverage and width using sub-sampled bootstrap confidence intervals.
Source:R/calc_coverage.R
      extrapolate_coverage.RdGiven a set of bootstrap confidence intervals calculated across sub-samples with different numbers of replications, extrapolates confidence interval coverage and width of bootstrap confidence intervals to a specified (larger) number of bootstraps. The function also calculates the associated Monte Carlo standard errors. The confidence interval percentage is based on how you calculated the lower and upper bounds.
Usage
extrapolate_coverage(
  data,
  CI_subsamples,
  true_param,
  B_target = Inf,
  criteria = c("coverage", "width"),
  winz = Inf,
  nested = FALSE,
  format = "wide",
  width_trim = 0,
  cover_na_val = NA,
  width_na_val = NA
)Arguments
- data
 data frame or tibble containing the simulation results.
- CI_subsamples
 list or name of column from
datacontaining list of confidence intervals calculated based on sub-samples with different numbers of replications.- true_param
 vector or name of column from
datacontaining corresponding true parameters.- B_target
 number of bootstrap replications to which the criteria should be extrapolated, with a default of
B = Inf.- criteria
 character or character vector indicating the performance criteria to be calculated, with possible options
"coverage"and"width".- winz
 numeric value for winsorization constant. If set to a finite value, estimates will be winsorized at the constant multiple of the inter-quartile range below the 25th percentile or above the 75th percentile of the distribution. For instance, setting
winz = 3will truncate estimates that fall below P25 - 3 * IQR or above P75 + 3 * IQR.- nested
 logical value controlling the format of the output. If
FALSE(the default), then the results will be returned as a data frame with rows for each distinct number of bootstraps. IfTRUE, then the results will be returned as a data frame with a single row, with each performance criterion containing a nested data frame.- format
 character string controlling the format of the output when
CI_subsampleshas results for more than one type of confidence interval. If"wide"(the default), then each performance criterion will have a separate column for each CI type. If"long", then each performance criterion will be a single variable, with separate rows for each CI type.- width_trim
 numeric value specifying the trimming percentage to use when summarizing CI widths across replications from a single set of bootstraps, with a default of 0.0 (i.e., use the regular arithmetic mean).
- cover_na_val
 numeric value to use for calculating coverage if bootstrap CI end-points are missing. Default is
NA.- width_na_val
 numeric value to use for calculating width if bootstrap CI end-points are missing. Default is
NA.
Value
A tibble containing the number of simulation iterations, performance criteria estimate(s) and the associated MCSE.
Examples
dgp <- function(N, mu, nu) {
  mu + rt(N, df = nu)
}
estimator <- function(
   dat,
    B_vals = c(49,59,89,99),
    m = 4,
    trim = 0.1
) {
  # compute estimate and standard error
  N <- length(dat)
  est <- mean(dat, trim = trim)
  se <- sd(dat) / sqrt(N)
  # compute booties
  booties <- replicate(max(B_vals), {
    x <- sample(dat, size = N, replace = TRUE)
    data.frame(
      M = mean(x, trim = trim),
      SE = sd(x) / sqrt(N)
    )
  }, simplify = FALSE) |>
    dplyr::bind_rows()
  # confidence intervals for each B_vals
  CIs <- bootstrap_CIs(
    boot_est = booties$M,
    boot_se = booties$SE,
    est = est,
    se = se,
    CI_type = c("normal","basic","student","percentile"),
    B_vals = B_vals,
    reps = m,
    format = "wide-list"
  )
  res <- data.frame(
    est = est,
    se = se
  )
  res$CIs <- CIs
  res
}
#' build a simulation driver function
simulate_bootCIs <- bundle_sim(
  f_generate = dgp,
  f_analyze = estimator
)
boot_results <- simulate_bootCIs(
  reps = 50, N = 20, mu = 2, nu = 3,
  B_vals = seq(49, 199, 50),
)
extrapolate_coverage(
  data = boot_results,
  CI_subsamples = CIs,
  true_param = 2
)
#>     K_boot_coverage bootstraps boot_coverage_normal boot_coverage_basic
#> 49               50         49            0.9400000           0.9100000
#> 99               50         99            0.9650000           0.9500000
#> 149              50        149            0.9650000           0.9500000
#> 199              50        199            0.9600000           0.9600000
#> Inf              50        Inf            0.9736769           0.9757615
#>     boot_coverage_student boot_coverage_percentile boot_coverage_mcse_normal
#> 49               0.925000                0.9000000                0.03159049
#> 99               0.970000                0.9350000                0.02259899
#> 149              0.975000                0.9400000                0.02475389
#> 199              0.980000                0.9600000                0.02799417
#> Inf              1.000832                0.9709402                0.02545305
#>     boot_coverage_mcse_basic boot_coverage_mcse_student
#> 49                0.03695005                 0.02879378
#> 99                0.02945075                 0.02099563
#> 149               0.02945075                 0.02051630
#> 199               0.02799417                 0.02000000
#> Inf               0.02960679                 0.02210396
#>     boot_coverage_mcse_percentile boot_width_normal boot_width_basic
#> 49                     0.03642157          1.159929         1.097624
#> 99                     0.02928571          1.175052         1.179431
#> 149                    0.03077237          1.172648         1.189995
#> 199                    0.02799417          1.172968         1.203743
#> Inf                    0.03129752          1.179635         1.240317
#>     boot_width_student boot_width_percentile boot_width_mcse_normal
#> 49            1.207373              1.097624             0.04274222
#> 99            1.293900              1.179431             0.04157175
#> 149           1.308743              1.189995             0.04106793
#> 199           1.326554              1.203743             0.04092786
#> Inf           1.364842              1.240317             0.04096643
#>     boot_width_mcse_basic boot_width_mcse_student boot_width_mcse_percentile
#> 49             0.04132434              0.05558316                 0.04132434
#> 99             0.04417547              0.05336817                 0.04417547
#> 149            0.04281224              0.05197211                 0.04281224
#> 199            0.04438734              0.05198207                 0.04438734
#> Inf            0.04601933              0.05176776                 0.04601933
extrapolate_coverage(
  data = boot_results,
  CI_subsamples = CIs,
  true_param = 2,
  B_target = 999,
  format = "long"
)
#>    K_boot_coverage bootstraps    CI_type boot_coverage boot_coverage_mcse
#> 1               50         49     normal     0.9400000         0.03159049
#> 2               50         99     normal     0.9650000         0.02259899
#> 3               50        149     normal     0.9650000         0.02475389
#> 4               50        199     normal     0.9600000         0.02799417
#> 5               50        999     normal     0.9721437         0.02527111
#> 6               50         49      basic     0.9100000         0.03695005
#> 7               50         99      basic     0.9500000         0.02945075
#> 8               50        149      basic     0.9500000         0.02945075
#> 9               50        199      basic     0.9600000         0.02799417
#> 10              50        999      basic     0.9726090         0.02919867
#> 11              50         49    student     0.9250000         0.02879378
#> 12              50         99    student     0.9700000         0.02099563
#> 13              50        149    student     0.9750000         0.02051630
#> 14              50        199    student     0.9800000         0.02000000
#> 15              50        999    student     0.9971990         0.02153827
#> 16              50         49 percentile     0.9000000         0.03642157
#> 17              50         99 percentile     0.9350000         0.02928571
#> 18              50        149 percentile     0.9400000         0.03077237
#> 19              50        199 percentile     0.9600000         0.02799417
#> 20              50        999 percentile     0.9674153         0.03050594
#>    boot_width boot_width_mcse
#> 1    1.159929      0.04274222
#> 2    1.175052      0.04157175
#> 3    1.172648      0.04106793
#> 4    1.172968      0.04092786
#> 5    1.178736      0.04095320
#> 6    1.097624      0.04132434
#> 7    1.179431      0.04417547
#> 8    1.189995      0.04281224
#> 9    1.203743      0.04438734
#> 10   1.233434      0.04563260
#> 11   1.207373      0.05558316
#> 12   1.293900      0.05336817
#> 13   1.308743      0.05197211
#> 14   1.326554      0.05198207
#> 15   1.357194      0.05177026
#> 16   1.097624      0.04132434
#> 17   1.179431      0.04417547
#> 18   1.189995      0.04281224
#> 19   1.203743      0.04438734
#> 20   1.233434      0.04563260