# Load the data
data <- lead_bmd
# prepare data
threshold <- log(0.74675)
match_info = data |> dplyr::group_by(matched_sets) |>
dplyr::summarise(below = sum(log_lead < threshold) > 0, disc = var(log_lead) > 0,
above = sum(log_lead > threshold) > 0)
below_indices <- match_info$matched_sets[match_info$below]
disc_indices <- match_info$matched_sets[match_info$disc]
above_indices <- match_info$matched_sets[match_info$above]
# outcome analysis using the stochastic intervention statistic, weak null
below_nbp <- data |> dplyr::filter(matched_sets %in% below_indices & matched_sets
%in% disc_indices)
above_below <- below_nbp |> dplyr::filter(matched_sets %in% above_indices)
extract_below_threshold_vs_baseline_function <- function(z, r) {
extract_below_threshold_vs_baseline(z, r, threshold)
}
# one-sided test that estimand defined by estimand_function is 0 at gamma = 0
result <- weak_null_test(Z = above_below$log_lead,
R = above_below$lumbar_spine_bmd,
index = above_below$matched_sets, gamma = 0, theta = 0,
estimand_function = extract_below_threshold_vs_baseline_function)
Run the code above in your browser using DataLab