Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,26 @@ power_function <- function(x) {
10^(1:x)
}

# power_function <- function(x) {
# as.integer(outer(c(1), 10^(1:x)))
# }
#' Thin samples
#' Thin a large sample of sorted z-scores and stages for efficiency.
#' Retains 5,000 evenly-spaced points across the full range plus the last
#' 10,000 points for dense coverage at the extreme tail.
#'
#' @param n Total number of samples
#' @param z_sorted Sorted z-scores (ascending), length n
#' @param stage_sorted Sorted stage values (ascending), length n
#' @return A tibble with columns z_aep and stage
thin_samples <- function(n, z_sorted, stage_sorted) {

thin_idx <- unique(c(
round(seq(1, n, length.out = 5000)),
(n - 10000):n
))
thin_idx <- sort(unique(thin_idx))
thin_idx <- thin_idx[thin_idx >= 1 & thin_idx <= n]

data.frame(
z_aep = z_sorted[thin_idx],
stage = stage_sorted[thin_idx]
)
}
Loading