Learn R Programming

smoothedIPW (version 0.1.0)

get_CI: Bootstrap-based confidence intervals

Description

This function applies nonparametric bootstrap to construct confidence intervals around the counterfactual mean/probability estimates obtained by ipw.

Usage

get_CI(
  ipw_res,
  data,
  n_boot,
  conf_level = 0.95,
  reference_z_value,
  contrast_type = "difference",
  show_progress = TRUE
)

Value

An object of class "ipw_ci". This object is a list that includes the following components:

res_boot

A list where each component corresponds to a different medication \(z\) level. Each component of the list is a data frame containing the estimates and confidence intervals for the counterfactual outcome mean/probability under the treatment regime indexed by \(z\).

res_boot_contrast

A list where each component corresponds to a different medication \(z\) level. Each component of the list is a data frame containing the estimates and confidence intervals for the contrast (difference or ratio) counterfactual outcome mean/probability under the treatment regime indexed by \(z\) compared to the counterfactual outcome mean/probability under the treatment regime indexed by the reference value.

res_boot_all

A three dimensional array containing all the bootstrap replicates. The first dimension corresponds to the bootstrap replicate; The second dimension corresponds to the time interval; The third dimension corresponds to the medication \(z\) level.

outcome_type

Character string indicating whether the outcome is "continuous" or "binary".

outcome_times

Numeric vector of outcome times.

n_boot

Number of bootstrap replicates used.

conf_level

Confidence level used.

reference_z_value

Reference value of Z used for contrasts.

contrast_type

Type of contrast ("difference" or "ratio").

Arguments

ipw_res

Output from the ipw function.

data

Data table containing the observed data

n_boot

Numeric scalar specifying the number of bootstrap replicates to use

conf_level

Numeric scalar specifying the confidence level for the confidence intervals. The default is 0.95.

reference_z_value

Scalar specifying the value of \(z\) considered as the reference level when forming contrasts. See also argument contrast_type.

contrast_type

Character string specifying the type of contrast. The options are "difference" (for the difference of means/probabilities) and "ratio" (for the ratio of means/probabilities).

show_progress

Logical scalar specifying whether to show a progress bar.

Details

This function applies nonparametric bootstrap resampling to construct confidence intervals around the counterfactual mean/probability estimates obtained by ipw. Bootstrap confidence intervals are constructed by resampling individuals (with replacement) from the original data set, applying the ipw function to each bootstrap sample, and computing percentile-based confidence intervals from the distribution of bootstrap estimates.

Examples

Run this code
# \donttest{
set.seed(1234)
data_null_processed <- prep_data(data = data_null, grace_period_length = 2,
                                 baseline_vars = 'L')
res_est <- ipw(data = data_null_processed,
               time_smoothed = TRUE,
               outcome_times = c(6, 12, 18, 24),
               A_model = A ~ L + Z,
               R_model_numerator = R ~ L_baseline + Z,
               R_model_denominator = R ~ L + A + Z,
               Y_model = Y ~ L_baseline * (time + Z))
res_ci <- get_CI(ipw_res = res_est, data = data_null_processed, n_boot = 10)
res_ci
# }


Run the code above in your browser using DataLab