Skip to content

Add a bootstrap CI method #189

@ddsjoberg

Description

@ddsjoberg

Below is an example, but we will need to rename the function to align with the other CI functions. We will also need to generalize this a bit to account for different boot.ci(type) arguments and perhaps even boot(stype) arguments.

The other CI functions also include N in the results, so we should do the same with this one.

Also account for the special case with N = 1, when boot::boot.ci() doesn't error but doesn't return results: we want to the same structure of the returned named list each time.

boot_mean_ci <- function(x, conf.level = 0.95, R = 2000) {
  result <- list(estimate = NULL, conf.low = NULL, conf.high = NULL, conf.level = conf.level, R = R)
  boot <- boot::boot(data = x, statistic = \(x, i) mean(x[i], na.rm = TRUE), R = R, stype = "i")
  boot.ci <- boot::boot.ci(boot, conf = conf.level, type = "perc")
  result$estimate <- boot$t0
  result$conf.low <- boot.ci$percent[1, 4] |> unname()
  result$conf.high <- boot.ci$percent[1, 5] |> unname()

  result
}

cards::ard_continuous(ADSL, variables = AGE, statistic = everything() ~ boot_mean_ci)

I am torn on whether we should add this as an option to ard_continuous_ci(), because we would need to expose the type and stype arguments, if we do this then where would we stop? For now, let's not add...any other thoughts?

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions