Skip to content

Commit 4f89bfb

Browse files
authored
Feature/thin samples utils (#31)
* Update Authors@R with contributors and reviewers * Correct reviewer email addresses * add thin_samples() to utils * fix tibble NOTE in thin_samples
1 parent f178799 commit 4f89bfb

1 file changed

Lines changed: 23 additions & 3 deletions

File tree

R/utils.R

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,26 @@ power_function <- function(x) {
88
10^(1:x)
99
}
1010

11-
# power_function <- function(x) {
12-
# as.integer(outer(c(1), 10^(1:x)))
13-
# }
11+
#' Thin samples
12+
#' Thin a large sample of sorted z-scores and stages for efficiency.
13+
#' Retains 5,000 evenly-spaced points across the full range plus the last
14+
#' 10,000 points for dense coverage at the extreme tail.
15+
#'
16+
#' @param n Total number of samples
17+
#' @param z_sorted Sorted z-scores (ascending), length n
18+
#' @param stage_sorted Sorted stage values (ascending), length n
19+
#' @return A tibble with columns z_aep and stage
20+
thin_samples <- function(n, z_sorted, stage_sorted) {
21+
22+
thin_idx <- unique(c(
23+
round(seq(1, n, length.out = 5000)),
24+
(n - 10000):n
25+
))
26+
thin_idx <- sort(unique(thin_idx))
27+
thin_idx <- thin_idx[thin_idx >= 1 & thin_idx <= n]
28+
29+
data.frame(
30+
z_aep = z_sorted[thin_idx],
31+
stage = stage_sorted[thin_idx]
32+
)
33+
}

0 commit comments

Comments
 (0)