4
4
# helpers
5
5
6
6
check_includes_apparent <- function (x , call = caller_env()) {
7
- if (x % > % dplyr :: filter(id == " Apparent" ) % > % nrow() != 1 ) {
7
+ if (x | > dplyr :: filter(id == " Apparent" ) | > nrow() != 1 ) {
8
8
cli_abort(
9
9
c(
10
10
" The bootstrap resamples must include an apparent sample." ,
@@ -59,7 +59,7 @@ check_statistics <- function(x, std_col = FALSE, call = caller_env()) {
59
59
list_cols <- names(x )[map_lgl(x , is_list )]
60
60
x <- try(tidyr :: unnest(x , cols = all_of(list_cols )), silent = TRUE )
61
61
} else {
62
- x <- try(map(x , ~ .x ) % > % list_rbind(), silent = TRUE )
62
+ x <- try(map(x , \( .x ) .x ) | > list_rbind(), silent = TRUE )
63
63
}
64
64
65
65
if (inherits(x , " try-error" )) {
@@ -81,8 +81,8 @@ check_statistics <- function(x, std_col = FALSE, call = caller_env()) {
81
81
id ,
82
82
tidyselect :: one_of(std_candidates ),
83
83
dplyr :: starts_with(" ." )
84
- ) % > %
85
- mutate(orig = (id == " Apparent" )) % > %
84
+ ) | >
85
+ mutate(orig = (id == " Apparent" )) | >
86
86
dplyr :: rename(!!! re_name )
87
87
} else {
88
88
x <-
@@ -92,14 +92,14 @@ check_statistics <- function(x, std_col = FALSE, call = caller_env()) {
92
92
estimate ,
93
93
tidyselect :: one_of(std_candidates ),
94
94
dplyr :: starts_with(" ." )
95
- ) % > %
95
+ ) | >
96
96
dplyr :: rename(!!! re_name )
97
97
}
98
98
} else {
99
99
if (has_id ) {
100
100
x <-
101
- dplyr :: select(x , term , estimate , id , dplyr :: starts_with(" ." )) % > %
102
- mutate(orig = (id == " Apparent" )) % > %
101
+ dplyr :: select(x , term , estimate , id , dplyr :: starts_with(" ." )) | >
102
+ mutate(orig = (id == " Apparent" )) | >
103
103
dplyr :: select(- id )
104
104
} else {
105
105
x <- dplyr :: select(x , term , estimate , dplyr :: starts_with(" ." ))
@@ -113,16 +113,16 @@ check_statistics <- function(x, std_col = FALSE, call = caller_env()) {
113
113
get_p0 <- function (x , alpha = 0.05 , groups ) {
114
114
group_sym <- rlang :: syms(groups )
115
115
116
- orig <- x % > %
117
- group_by(!!! group_sym ) % > %
118
- dplyr :: filter(orig ) % > %
119
- dplyr :: select(!!! group_sym , theta_0 = estimate ) % > %
116
+ orig <- x | >
117
+ group_by(!!! group_sym ) | >
118
+ dplyr :: filter(orig ) | >
119
+ dplyr :: select(!!! group_sym , theta_0 = estimate ) | >
120
120
ungroup()
121
- x % > %
122
- dplyr :: filter(! orig ) % > %
123
- inner_join(orig , by = groups ) % > %
124
- group_by(!!! group_sym ) % > %
125
- summarize(p0 = mean(estimate < = theta_0 , na.rm = TRUE )) % > %
121
+ x | >
122
+ dplyr :: filter(! orig ) | >
123
+ inner_join(orig , by = groups ) | >
124
+ group_by(!!! group_sym ) | >
125
+ summarize(p0 = mean(estimate < = theta_0 , na.rm = TRUE )) | >
126
126
mutate(
127
127
Z0 = stats :: qnorm(p0 ),
128
128
Za = stats :: qnorm(1 - alpha / 2 )
@@ -148,9 +148,9 @@ check_has_dots <- function(x, call = caller_env()) {
148
148
149
149
check_num_resamples <- function (x , B = 1000 , call = caller_env()) {
150
150
x <-
151
- x % > %
152
- dplyr :: group_by(term ) % > %
153
- dplyr :: summarize(n = sum(! is.na(estimate ))) % > %
151
+ x | >
152
+ dplyr :: group_by(term ) | >
153
+ dplyr :: summarize(n = sum(! is.na(estimate ))) | >
154
154
dplyr :: filter(n < B )
155
155
156
156
if (nrow(x ) > 0 ) {
@@ -176,7 +176,7 @@ pctl_single <- function(stats, alpha = 0.05) {
176
176
}
177
177
178
178
# stats is a numeric vector of values
179
- ci <- stats % > % quantile(probs = c(alpha / 2 , 1 - alpha / 2 ), na.rm = TRUE )
179
+ ci <- stats | > quantile(probs = c(alpha / 2 , 1 - alpha / 2 ), na.rm = TRUE )
180
180
181
181
# return a tibble with .lower, .estimate, .upper
182
182
res <- tibble(
@@ -240,13 +240,13 @@ pctl_single <- function(stats, alpha = 0.05) {
240
240
# ' # ------------------------------------------------------------------------------
241
241
# '
242
242
# ' lm_est <- function(split, ...) {
243
- # ' lm(mpg ~ disp + hp, data = analysis(split)) %>%
243
+ # ' lm(mpg ~ disp + hp, data = analysis(split)) |>
244
244
# ' tidy()
245
245
# ' }
246
246
# '
247
247
# ' set.seed(52156)
248
248
# ' car_rs <-
249
- # ' bootstraps(mtcars, 500, apparent = TRUE) %>%
249
+ # ' bootstraps(mtcars, 500, apparent = TRUE) |>
250
250
# ' mutate(results = map(splits, lm_est))
251
251
# '
252
252
# ' int_pctl(car_rs, results)
@@ -268,8 +268,8 @@ pctl_single <- function(stats, alpha = 0.05) {
268
268
# '
269
269
# ' set.seed(69325)
270
270
# ' data(Sacramento, package = "modeldata")
271
- # ' bootstraps(Sacramento, 1000, apparent = TRUE) %>%
272
- # ' mutate(correlations = map(splits, rank_corr)) %>%
271
+ # ' bootstraps(Sacramento, 1000, apparent = TRUE) |>
272
+ # ' mutate(correlations = map(splits, rank_corr)) |>
273
273
# ' int_pctl(correlations)
274
274
# '
275
275
# ' # ------------------------------------------------------------------------------
@@ -278,21 +278,21 @@ pctl_single <- function(stats, alpha = 0.05) {
278
278
# '
279
279
# ' # Get regression estimates for each house type
280
280
# ' lm_est <- function(split, ...) {
281
- # ' analysis(split) %>%
282
- # ' tidyr::nest(.by = c(type)) %>%
281
+ # ' analysis(split) |>
282
+ # ' tidyr::nest(.by = c(type)) |>
283
283
# ' # Compute regression estimates for each house type
284
284
# ' mutate(
285
- # ' betas = purrr::map(data, ~ lm(log10(price) ~ sqft, data = .x) %>% tidy())
286
- # ' ) %>%
285
+ # ' betas = purrr::map(data, \(.x) lm(log10(price) ~ sqft, data = .x) |> tidy())
286
+ # ' ) |>
287
287
# ' # Convert the column name to begin with a period
288
- # ' rename(.type = type) %>%
289
- # ' select(.type, betas) %>%
288
+ # ' rename(.type = type) |>
289
+ # ' select(.type, betas) |>
290
290
# ' unnest(cols = betas)
291
291
# ' }
292
292
# '
293
293
# ' set.seed(52156)
294
294
# ' house_rs <-
295
- # ' bootstraps(Sacramento, 1000, apparent = TRUE) %>%
295
+ # ' bootstraps(Sacramento, 1000, apparent = TRUE) |>
296
296
# ' mutate(results = map(splits, lm_est))
297
297
# '
298
298
# ' int_pctl(house_rs, results)
@@ -317,7 +317,7 @@ int_pctl.bootstraps <- function(.data, statistics, alpha = 0.05, ...) {
317
317
check_dots_empty()
318
318
check_number_decimal(alpha , min = 0 , max = 1 )
319
319
320
- .data <- .data % > % dplyr :: filter(id != " Apparent" )
320
+ .data <- .data | > dplyr :: filter(id != " Apparent" )
321
321
322
322
column_name <- tidyselect :: vars_select(
323
323
names(.data ),
@@ -334,9 +334,9 @@ int_pctl.bootstraps <- function(.data, statistics, alpha = 0.05, ...) {
334
334
stat_groups <- c(" term" , grep(" ^\\ ." , names(stats ), value = TRUE ))
335
335
stat_groups <- rlang :: syms(stat_groups )
336
336
337
- vals <- stats % > %
338
- dplyr :: group_by(!!! stat_groups ) % > %
339
- dplyr :: do(pctl_single(. $ estimate , alpha = alpha )) % > %
337
+ vals <- stats | >
338
+ dplyr :: group_by(!!! stat_groups ) | >
339
+ dplyr :: do(pctl_single(. $ estimate , alpha = alpha )) | >
340
340
dplyr :: ungroup()
341
341
vals
342
342
}
@@ -416,16 +416,16 @@ int_t.bootstraps <- function(.data, statistics, alpha = 0.05, ...) {
416
416
if (length(column_name ) != 1 ) {
417
417
cli_abort(statistics_format_error )
418
418
}
419
- stats <- .data % > % dplyr :: select(!! column_name , id )
419
+ stats <- .data | > dplyr :: select(!! column_name , id )
420
420
stats <- check_statistics(stats , std_col = TRUE )
421
421
422
422
check_num_resamples(stats , B = 500 )
423
423
424
424
stat_groups <- c(" term" , grep(" ^\\ ." , names(stats ), value = TRUE ))
425
425
stat_groups <- rlang :: syms(stat_groups )
426
- vals <- stats % > %
427
- dplyr :: group_by(!!! stat_groups ) % > %
428
- dplyr :: do(t_single(. $ estimate , . $ std_err , . $ orig , alpha = alpha )) % > %
426
+ vals <- stats | >
427
+ dplyr :: group_by(!!! stat_groups ) | >
428
+ dplyr :: do(t_single(. $ estimate , . $ std_err , . $ orig , alpha = alpha )) | >
429
429
dplyr :: ungroup()
430
430
vals
431
431
}
@@ -464,20 +464,20 @@ bca_calc <- function(
464
464
cli_abort(" {.arg .fn} failed." , call = call )
465
465
}
466
466
467
- loo_res <- furrr :: future_map(loo_rs $ splits , .fn , ... ) % > % list_rbind()
467
+ loo_res <- furrr :: future_map(loo_rs $ splits , .fn , ... ) | > list_rbind()
468
468
469
469
loo_estimate <-
470
- loo_res % > %
471
- dplyr :: group_by(!!! stat_groups_sym ) % > %
472
- dplyr :: summarize(loo = mean(estimate , na.rm = TRUE )) % > %
473
- dplyr :: inner_join(loo_res , by = stat_groups_chr , multiple = " all" ) % > %
474
- dplyr :: group_by(!!! stat_groups_sym ) % > %
470
+ loo_res | >
471
+ dplyr :: group_by(!!! stat_groups_sym ) | >
472
+ dplyr :: summarize(loo = mean(estimate , na.rm = TRUE )) | >
473
+ dplyr :: inner_join(loo_res , by = stat_groups_chr , multiple = " all" ) | >
474
+ dplyr :: group_by(!!! stat_groups_sym ) | >
475
475
dplyr :: summarize(
476
476
cubed = sum((loo - estimate )^ 3 ),
477
477
squared = sum((loo - estimate )^ 2 )
478
- ) % > %
479
- dplyr :: ungroup() % > %
480
- dplyr :: inner_join(bias_corr_stats , by = stat_groups_chr ) % > %
478
+ ) | >
479
+ dplyr :: ungroup() | >
480
+ dplyr :: inner_join(bias_corr_stats , by = stat_groups_chr ) | >
481
481
dplyr :: mutate(
482
482
a = cubed / (6 * (squared ^ (3 / 2 ))),
483
483
Zu = (Z0 + Za ) / (1 - a * (Z0 + Za )) + Z0 ,
@@ -487,9 +487,9 @@ bca_calc <- function(
487
487
)
488
488
489
489
terms <- loo_estimate $ term
490
- stats <- stats % > % dplyr :: filter(! orig )
490
+ stats <- stats | > dplyr :: filter(! orig )
491
491
492
- keys <- stats % > % dplyr :: distinct(!!! stat_groups_sym )
492
+ keys <- stats | > dplyr :: distinct(!!! stat_groups_sym )
493
493
for (i in seq_len(nrow(keys ))) {
494
494
tmp_stats <- dplyr :: inner_join(stats , keys [i , ], by = stat_groups_chr )
495
495
tmp_loo <- dplyr :: inner_join(loo_estimate , keys [i , ], by = stat_groups_chr )
@@ -503,8 +503,8 @@ bca_calc <- function(
503
503
}
504
504
}
505
505
ci_bca <-
506
- ci_bca % > %
507
- dplyr :: select(!!! stat_groups_sym , .lower , .estimate , .upper ) % > %
506
+ ci_bca | >
507
+ dplyr :: select(!!! stat_groups_sym , .lower , .estimate , .upper ) | >
508
508
dplyr :: mutate(
509
509
.alpha = alpha ,
510
510
.method = " BCa"
@@ -538,7 +538,7 @@ int_bca.bootstraps <- function(.data, statistics, alpha = 0.05, .fn, ...) {
538
538
if (length(column_name ) != 1 ) {
539
539
cli_abort(statistics_format_error )
540
540
}
541
- stats <- .data % > % dplyr :: select(!! column_name , id , dplyr :: starts_with(" ." ))
541
+ stats <- .data | > dplyr :: select(!! column_name , id , dplyr :: starts_with(" ." ))
542
542
stats <- check_statistics(stats )
543
543
544
544
check_num_resamples(stats , B = 1000 )
0 commit comments