-
Notifications
You must be signed in to change notification settings - Fork 0
/
sens.R
689 lines (648 loc) · 21.5 KB
/
sens.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
#' Perform sensitivity analysis on a risk-adjusted regression
#'
#' `sens()` performs sensitivity analysis on a risk-adjusted regression by
#' computing the maximum and minimum regression coefficients consistent with the
#' data and the analyst's prior knowledge, expressed through `epsilon`, the
#' bound on the mean absolute difference between the true and estimated risks.
#' It additionally can provide bootstrapped pointwise confidence intervals for
#' the regression coefficients.
#'
#' @section Details:
#'
#' The sensitivity analysis assumes that every group contains at least one
#' observed and one unobserved individual, and that the estimated risks and
#' upper and lower bounds are "sortable," i.e., that there exists a permutation
#' of the rows such that the estimated risks and upper and lower bounds are all
#' non-decreasing within each group and observation status. If these conditions
#' are not met, the function will throw an error.
#'
#' To ensure that these conditions continue to hold, the bootstrap resamples are
#' stratified by group and observation status. As a result, in small samples,
#' the confidence intervals may be slightly narrowed, since they do not account
#' for uncertainty in the number of individuals in each group, and the number of
#' observed and unobserved individuals within each group.
#'
#' @param df The data frame containing the data.
#' @param group_col The name of the column containing the group labels. This
#' column should be a factor or coercible to a factor.
#' @param obs_col The name of the column containing whether or not the outcome
#' was observed. This column should be a logical or coercible to a logical.
#' @param p_col The name of the column containing the estimated risks. These
#' risks should be expressed on the probability scale, i.e., be between 0 and 1.
#' @param base_group The name of the base group. This group will be used as the
#' reference group in the regression.
#' @param epsilon The bound on the mean absolute difference between the true and
#' estimated risks.
#' @param lwr_col The name of the column containing the lower bounds on the true
#' risk. (Defaults to 0 for all observations.)
#' @param upr_col The name of the column containing the upper bounds on the true
#' risk. (Defaults to 1 for all observations.)
#' @param eta The step size for the grid search. Note that while steps are
#' taken at the group level, the step size is expressed at the level of change
#' in average risk *across the entire population*. In other words, smaller
#' groups will have proportionally larger steps. (Defaults to 0.01.)
#' @param m The grid size for the maximization approximation. (Defaults to
#' `101`.)
#' @param N The number of bootstrap resamples to use to compute pointwise
#' confidence intervals. (Defaults to 0, which performs no bootstrap.)
#' @param alpha The confidence level for the pointwise confidence intervals.
#' (Defaults to 0.05.)
#' @param chunk_size The number of repetitions to perform in each chunk when run
#' in parallel. Larger chunk sizes make it less likely that separate threads
#' will block on each other, but also make it more likely that the threads will
#' finish at different times. (Defaults to 100.)
#' @param n_threads The number of threads to use when running in parallel.
#' (Defaults to 1, i.e., serial execution.)
#' @return A data frame containing the following columns:
#' * `epsilon`: Values of epsilon ranging from 0 to the input value of `epsilon`
#' in `m` steps.
#' * `beta_min_{group}`: The minimum value of the regression coefficient for the
#' group `group`. (Note that the base group is not included in this list.)
#' * `beta_max_{group}`: The maximum value of the regression coefficient for the
#' group `group`. (Note that the base group is not included in this list.)
#' * (**If `N > 0`**) `beta_min_{group}_{alpha/2}`: The `alpha/2` quantile of
#' the bootstrap distribution of the minimum value of the regression coefficient
#' for group `group`. (Note that the base group is not included in this list.)
#' * (**If `N > 0`**) `beta_min_{group}_{1 - alpha/2}`: The `1 - alpha/2`
#' quantile of the bootstrap distribution of the minimum value of the regression
#' coefficient for group `group`. (Note that the base group is not included in
#' this list.)
#' * (**If `N > 0`**) `beta_max_{group}_{alpha/2}`: The `alpha/2` quantile of
#' the bootstrap distribution of the maximum value of the regression coefficient
#' for group `group`. (Note that the base group is not included in this list.)
#' * (**If `N > 0`**) `beta_max_{group}_{1 - alpha/2}`: The `1 - alpha/2`
#' quantile of the bootstrap distribution of the maximum value of the regression
#' coefficient for group `group`. (Note that the base group is not included in
#' this list.)
#' @examples
#' # Generate some data
#' set.seed(1)
#' df <- tibble::tibble(
#' group = factor(
#' sample(c("a", "b"), 1000, replace = TRUE),
#' levels = c("a", "b")
#' ),
#' p = runif(1000)^2,
#' frisked = runif(1000) < p + 0.1 * (group != "a")
#' )
#'
#' # Compute the sensitivity analysis
#' sens(df, group, frisked, p, "a", 0.1)
#'
#' # Search over a finer grid
#' sens(df, group, frisked, p, "a", 0.1, eta = 0.001)
#'
#' # Increase the accuracy of the maximization approximation
#' sens(df, group, frisked, p, "a", 0.1, m = 1001)
#'
#' \donttest{
#' # Calculate 90% pointwise confidence intervals
#' sens(df, group, frisked, p, "a", 0.1, N = 1000, alpha = 0.1)
#'
#' # Run in parallel, adjusting the chunk size to avoid blocking
#' sens(df, group, frisked, p, "a", 0.1, n_threads = 2, eta = 0.0001,
#' chunk_size = 1000)
#' }
#' @importFrom dplyr rename mutate select arrange n_distinct anti_join summarize
#' group_by filter bind_cols slice_sample pull
#' @importFrom rlang enquo as_name abort quo_is_null quo_text warn set_names
#' @importFrom glue glue
#' @importFrom purrr map_dfr
#' @importFrom tidyr expand_grid
#' @importFrom vctrs vec_is
#' @importFrom tibble tibble
#' @export
sens <- function(df, group_col, obs_col, p_col, base_group, epsilon,
lwr_col = NULL, upr_col = NULL, eta = 0.01,
m = 101L, N = 0L, alpha = 0.05, chunk_size = 100L,
n_threads = 1L) {
# Get the user-provided columns.
group_col <- rlang::enquo(group_col)
obs_col <- rlang::enquo(obs_col)
p_col <- rlang::enquo(p_col)
lwr_col <- rlang::enquo(lwr_col)
upr_col <- rlang::enquo(upr_col)
# Check that the user-provided columns can be coerced to strings, if they are
# not null.
tryCatch(
{
rlang::as_name(group_col)
},
error = function(e) {
rlang::abort(glue::glue(
"Invalid column name in `group_col`.",
.sep = " "
))
}
)
tryCatch(
{
rlang::as_name(obs_col)
},
error = function(e) {
rlang::abort(glue::glue(
"Invalid column name in `obs_col`.",
.sep = " "
))
}
)
tryCatch(
{
rlang::as_name(p_col)
},
error = function(e) {
rlang::abort(glue::glue(
"Invalid column name in `p_col`.",
.sep = " "
))
}
)
if (!rlang::quo_is_null(lwr_col)) {
tryCatch(
{
rlang::as_name(lwr_col)
},
error = function(e) {
rlang::abort(glue::glue(
"Invalid column name in `lwr_col`.",
.sep = " "
))
}
)
}
if (!rlang::quo_is_null(upr_col)) {
tryCatch(
{
rlang::as_name(upr_col)
},
error = function(e) {
rlang::abort(glue::glue(
"Invalid column name in `upr_col`.",
.sep = " "
))
}
)
}
# Check that `df` is a data frame
if (!is.data.frame(df)) {
rlang::abort("Argument `df` must be a data frame.")
}
# Check that all of the columns are in the dataframe
if (any(!c(
rlang::as_name(group_col),
rlang::as_name(obs_col),
rlang::as_name(p_col)
) %in% colnames(df))) {
rlang::abort(glue::glue(
"Columns `group_col` ({ rlang::as_name(group_col)}),",
"`obs_col` ({ rlang::as_name(obs_col)}),",
"and `p_col` ({ rlang::as_name(p_col)})",
"must be present in `df`",
"(cols: { paste(colnames(df), collapse = ', ') }).",
.sep = " "
))
}
# If specified, lwr_col and upr_col must be in the dataframe
if (
!rlang::quo_is_null(lwr_col) && !rlang::as_name(lwr_col) %in% colnames(df)
) {
rlang::abort(glue::glue(
"Column `lwr_col` ({ rlang::as_name(lwr_col) }) must be present in `df`",
"(cols: { paste(colnames(df), collapse = ', ') }) if specified.",
.sep = " "
))
}
if (
!rlang::quo_is_null(upr_col) && !rlang::as_name(upr_col) %in% colnames(df)
) {
rlang::abort(glue::glue(
"Column `upr_col` ({ rlang::as_name(upr_col) }) must be present in `df`",
"(cols: { paste(colnames(df), collapse = ', ') }) if specified.",
.sep = " "
))
}
df <- df %>%
dplyr::rename(
group = !!group_col,
obs = !!obs_col,
p = !!p_col
)
# Add in lwr and upper if not present
if (!rlang::quo_is_null(lwr_col)) {
df <- df %>%
dplyr::rename(lwr = !!lwr_col)
} else {
df <- df %>%
dplyr::mutate(lwr = rep(0, nrow(df)))
}
if (!rlang::quo_is_null(upr_col)) {
df <- df %>%
dplyr::rename(upr = !!upr_col)
} else {
df <- df %>%
dplyr::mutate(upr = rep(1, nrow(df)))
}
df <- df %>%
dplyr::select(group, obs, p, lwr, upr)
################################# TYPE CHECKS ################################
# Check that there are no missing values.
if (any(is.na(df))) {
rlang::abort(c(
"There are missing values in the data frame.",
"x" = glue::glue(
"No risk estimate, group, or observation status, or lower or upper",
"bound (if provided) can be missing.",
.sep = " "
)
))
}
# Check that group is coercible to factor (i.e., factor, character, numeric,
# logical)
if (with(
df,
!is.factor(group) &&
!vctrs::vec_is(group, character()) &&
!vctrs::vec_is(group, numeric()) &&
!vctrs::vec_is(group, integer()) &&
!vctrs::vec_is(group, logical())
)) {
rlang::abort(c(
glue::glue("Invalid group column '{ rlang::quo_text(group_col) }'."),
"x" = "Column must be a factor, character, numeric, or logical vector."
))
}
# Check that base group occurs in the group column.
if (length(base_group) != 1 || with(df, !base_group %in% group)) {
rlang::abort(glue::glue(
"Base group must occur in the group column."
))
} else {
base_group <- as.character(base_group)
}
# Check that there are at least two groups.
if (with(df, length(unique(group)) <= 1)) {
rlang::abort(glue::glue(
"There must be at least two distinct groups in the group column."
))
}
# Check that obs is logical or coercible
if (with(
df,
!vctrs::vec_is(obs, logical()) && (
!vctrs::vec_is(obs, numeric()) || !all(obs %in% c(0, 1))
)
)) {
rlang::abort(c(
glue::glue(
"Invalid observation column '{ rlang::quo_text(obs_col) }'."
),
"x" = paste(
"Column must be a logical vector, or a numeric or character",
"vector taking only the values 0 and 1."
)
))
}
# Check that p is numeric and between 0 and 1.
if (with(df, !vctrs::vec_is(p, numeric()) || any(p < 0 | p > 1))) {
rlang::abort(c(
glue::glue("Invalid risk column '{ rlang::quo_text(p_col) }'."),
"x" = paste(
"column must be a numeric vector taking only values between 0 and",
"1, inclusive."
)
))
}
# Check that lwr is numeric and between 0 and 1.
if (with(df, !vctrs::vec_is(lwr, numeric()) || any(lwr < 0 | lwr > 1))) {
rlang::abort(c(
glue::glue("Invalid lower bound column '{ rlang::quo_text(lwr_col) }'."),
"x" = paste(
"column must be a numeric vector taking only values between 0 and",
"1, inclusive."
)
))
}
# Check that upr is numeric and between 0 and 1.
if (with(df, !vctrs::vec_is(upr, numeric()) || any(upr < 0 | upr > 1))) {
rlang::abort(c(
glue::glue("Invalid upper bound column '{ rlang::quo_text(upr_col) }'."),
"x" = paste(
"column must be a numeric vector taking only values between 0 and",
"1, inclusive."
)
))
}
# Check that epsilon is numeric and positive.
if (
!vctrs::vec_is(epsilon, numeric()) || length(epsilon) != 1 || epsilon <= 0
) {
rlang::abort(c(
glue::glue("Invalid epsilon ({ epsilon })."),
"x" = "Argument `epsilon` must be a single, positive numeric constant."
))
} else {
if (epsilon > 1) {
rlang::warn(c(
glue::glue("Argument `epsilon` ({ epsilon }) was greater than 1."),
"i" = "`epsilon` will be set to 1, its maximum meaningful value."
))
epsilon <- 1
}
epsilon <- as.double(epsilon)
}
# Check that eta is numeric and positive, and less than epsilon.
if (!vctrs::vec_is(eta, numeric()) || length(eta) != 1 || eta <= 0) {
rlang::abort(c(
glue::glue("Invalid eta ({ eta })."),
"x" = paste(
"Argument `eta` must be a single, positive numeric constant less than",
"`epsilon`."
)
))
} else {
if (eta > epsilon / 3) {
rlang::warn(c(
glue::glue(
"Argument `eta` ({ eta }) is large relative to `epsilon`",
"({ epsilon }).",
.sep = " "
),
"i" = "Results may be unreliable."
))
eta <- epsilon
}
eta <- as.double(eta)
}
# Check that `m` is a positive whole number and at least two.
if (
!(
vctrs::vec_is(m, numeric())
|| vctrs::vec_is(m, integer())
)
|| length(m) != 1
|| m < 2
) {
rlang::abort(c(
glue::glue("Invalid `m` ({ m })."),
"x" = "Argument `m` must be a single positive integer, at least two."
))
} else {
if (m != floor(m)) {
rlang::warn(c(
glue::glue("Argument `m` ({ m }) was not a whole number."),
"i" = "Argument `m` will be rounded down to the nearest whole number."
))
}
m <- as.integer(m)
}
# Check that `n_threads` is a positive whole number.
if (
!(
vctrs::vec_is(n_threads, numeric())
|| vctrs::vec_is(n_threads, integer())
)
|| length(n_threads) != 1
|| n_threads < 1
) {
rlang::abort(c(
glue::glue("Invalid `n_threads` ({ n_threads })."),
"x" = "Argument `n_threads` must be a single positive integer."
))
} else {
if (n_threads != floor(n_threads)) {
rlang::warn(c(
glue::glue(
"Argument `n_threads` ({ n_threads }) was not a whole number."
),
"i" = paste(
"Argument `n_threads` will be rounded down to the nearest whole",
"number."
)
))
}
if (n_threads > parallel::detectCores()) {
rlang::warn(c(
glue::glue(
"Argument `n_threads` ({ n_threads }) was greater than the number",
"of cores.",
.sep = " "
),
"i" = "Argument `n_threads` will be set to the number of cores."
))
n_threads <- parallel::detectCores()
}
n_threads <- as.integer(n_threads)
}
# Check that `chunk_size` is a positive whole number.
if (
!(
vctrs::vec_is(chunk_size, numeric())
|| vctrs::vec_is(chunk_size, integer())
)
|| length(chunk_size) != 1
|| chunk_size < 1
) {
rlang::abort(c(
glue::glue("Invalid `chunk_size` ({ chunk_size })."),
"x" = "Argument `chunk_size` must be a single positive integer."
))
} else {
if (chunk_size != floor(chunk_size)) {
rlang::warn(c(
glue::glue(
"Argument `chunk_size` ({ chunk_size }) was not a whole number."
),
"i" = paste(
"Argument `chunk_size` will be rounded down to the nearest whole",
"number."
)
))
}
chunk_size <- as.integer(chunk_size)
}
# Check that `N` is a non-negative whole number.
if (
!(vctrs::vec_is(N, numeric()) || vctrs::vec_is(N, integer()))
|| length(N) != 1
|| N < 0
) {
rlang::abort(c(
glue::glue("Invalid `N` ({ N })."),
"x" = "Argument `N` must be a single non-negative integer."
))
} else {
if (N != floor(N)) {
rlang::warn(c(
glue::glue("Argument `N` ({ N }) was not a whole number."),
"i" = "Argument `N` will be rounded down to the nearest whole number."
))
}
N <- as.integer(N)
}
# Check that `alpha is numeric and between 0 and 1.
if (
!vctrs::vec_is(alpha, numeric())
|| length(alpha) != 1
|| alpha <= 0
|| alpha >= 1
) {
rlang::abort(c(
glue::glue("Invalid alpha ({ alpha })."),
"x" = paste(
"Argument `alpha` must be a single numeric constant between zero and",
"one."
)
))
} else {
if (N > 0 && alpha * N < 1) {
rlang::abort(c(
glue::glue(
"Argument `alpha` ({ alpha }) is too small to produce any confidence",
"intervals.",
.sep = " "
),
"i" = "Argument `alpha` should be at least 1 / N."
))
}
if (N > 0 && alpha * N < 5) {
rlang::warn(c(
glue::glue(
"Argument `alpha` ({ alpha }) is small relative to `N` ({ N })."
),
"i" = "Confidence intervals may be unreliable."
))
}
alpha <- as.double(alpha)
}
########################### DATA INTEGRITY CHECKS ############################
df <- df %>%
dplyr::mutate(
group = forcats::fct_relevel(forcats::as_factor(group), {{ base_group }}),
obs = as.logical(obs),
p = as.numeric(p),
) %>%
dplyr::arrange(obs, group, p, upr, lwr)
# Check if there are any unused levels and drop them.
if (any(!levels(df$group) %in% levels(forcats::fct_drop(df$group)))) {
rlang::warn(glue::glue(
"Some groups had no observations. Those groups will be dropped from",
"the analysis.",
.sep = " "
))
df <- df %>%
dplyr::mutate(group = forcats::fct_drop(group))
}
# Record the number of groups
G <- with(df, dplyr::n_distinct(group))
# Check if every group has at least one observed and one unobserved individual
strata <- with(
df,
tidyr::expand_grid(group = levels(group), obs = c(TRUE, FALSE))
)
if (nrow(dplyr::anti_join(strata, df, by = c("group", "obs"))) > 0) {
rlang::abort(glue::glue(
"Every group must have at least one observed and one unobserved",
"individual.",
.sep = " "
))
}
# Check if the risk estimates are between zero and one
if (with(df, !all(lwr <= p & p <= upr))) {
rlang::abort(c(
glue::glue("The estimated risks (p) are invalid.",
"*" = "Some values were not between lwr and upr."
)
))
}
# Check if the bounds are correctly sorted
valid <- df %>%
dplyr::group_by(group, obs) %>%
dplyr::summarize(
valid = c(
all(lwr == cummax(lwr)) & all(p == cummax(p)) & all(upr == cummax(upr))
)
) %>%
dplyr::pull(valid)
if (!all(valid)) {
rlang::abort(c(
glue::glue("The bounds (lwr, p, upr) are not sortable."),
"* The bounds and risks cannot be sorted in the same order."
))
}
############################### CALL C++ CODE ################################
# Calculate the upper and lower bounds for the iterator in each group.
iter_bounds <- df %>%
dplyr::filter(!obs) %>%
dplyr::group_by(group) %>%
dplyr::summarize(
lwr = mean(lwr) - mean(p),
upr = max(upr) - mean(p)
)
# Generate the estimated betas.
raw_betas <- with(
df,
sens_(
p, lwr, upr, iter_bounds$lwr, iter_bounds$upr, group, obs, epsilon,
eta, m, chunk_size, n_threads
)
)
# Restructure the betas as a data frame.
groups <- with(df, levels(group))
res <- dplyr::bind_cols(
epsilon = seq(0, epsilon, length.out = m),
rlang::set_names(raw_betas[[1]], paste0("beta_min_", groups[2:G])),
rlang::set_names(raw_betas[[2]], paste0("beta_max_", groups[2:G]))
)
# If N > 0, generate the bootstrap resampled confidence intervals.
if (N > 0) {
boot_res <- purrr::map_dfr(1:N, .progress = "Resamples", ~ {
# Generate the bootstrap resample.
boot_df <- df %>%
dplyr::group_by(group, obs) %>%
dplyr::slice_sample(prop = 1, replace = TRUE) %>%
dplyr::ungroup()
# Calculate the upper and lower bounds for the iterator in each group.
boot_iter_bounds <- boot_df %>%
dplyr::filter(!obs) %>%
dplyr::group_by(group) %>%
dplyr::summarize(
lwr = mean(lwr) - mean(p),
upr = max(upr) - mean(p)
)
# Generate the estimated betas.
boot_raw_betas <- with(
boot_df,
sens_(
p, lwr, upr, boot_iter_bounds$lwr, boot_iter_bounds$upr, group, obs,
epsilon, eta, m, chunk_size, n_threads
)
)
# Restructure the betas as a data frame.
dplyr::bind_cols(
i = .x,
epsilon = seq(0, epsilon, length.out = m),
rlang::set_names(boot_raw_betas[[1]], paste0("beta_min_", groups[2:G])),
rlang::set_names(boot_raw_betas[[2]], paste0("beta_max_", groups[2:G]))
)
})
# Take the quantiles of the bootstrap resamples and recombine with the
# original results.
fns <- list(
~ quantile(., probs = alpha / 2),
~ quantile(., probs = 1 - alpha / 2)
)
fns <- rlang::set_names(fns, c(
sprintf("%04.1f", 100 * alpha / 2),
sprintf("%04.1f", 100 * (1 - alpha / 2))
))
res <- boot_res %>%
dplyr::group_by(epsilon) %>%
dplyr::reframe(dplyr::across(tidyselect::starts_with("beta_"), fns)) %>%
dplyr::left_join(res, by = "epsilon")
}
# Return the results.
res
}
if (getRversion() >= "2.15.1") {
utils::globalVariables(c("group", "obs", "p", "lwr", "upr"))
}