After collapsing ultra-rare variants, the per-variant B and PI values need to be aggregated for collapsed groups. This function uses the col_mapping from collapse_rare_variants() to aggregate B and PI.

aggregate_B_PI(B, PI, collapse_result)

Arguments

B

Numeric vector of per-variant B values (length p, original).

PI

Numeric vector of per-variant PI values (length p, original).

collapse_result

Output from collapse_rare_variants().

Value

List with B_collapsed and PI_collapsed (length p').

Examples

# Suppose we have 5 original variants with B and PI values
B <- c(0.5, 0.8, 0.9, 0.3, 0.7)
PI <- c(0.1, 0.4, 0.6, 0.2, 0.5)

# After collapsing, variants 2-3 and 5 were grouped (see collapse_rare_variants)
collapse_result <- list(
  col_mapping = list(1L, c(2L, 3L), 4L, 5L),
  is_collapsed = c(FALSE, TRUE, FALSE, FALSE),
  agg_method = "mean"
)
agg <- aggregate_B_PI(B, PI, collapse_result)
agg$B_collapsed   # c(0.5, mean(0.8,0.9), 0.3, 0.7)
#> [1] 0.50 0.85 0.30 0.70
agg$PI_collapsed  # c(0.1, mean(0.4,0.6), 0.2, 0.5)
#> [1] 0.1 0.5 0.2 0.5