For a single variant (row index), computes deviation contrasts (each condition vs grand mean) and all pairwise contrasts from the mash posterior mean and covariance. Supports condition grouping for weighted contrasts.
Arguments
- index
Integer row index of the variant in the posterior matrices.
- origMean
Matrix of original effect sizes (variants x conditions). Used to determine which conditions are "tested" (non-zero).
- posteriorMean
Matrix of mash posterior means (variants x conditions).
- posteriorVcov
3D array of posterior covariance matrices (conditions x conditions x variants).
- grouping
Named integer vector mapping condition names to group IDs. Conditions with the same positive group ID are treated as replicates (e.g., multiple datasets for the same cell type). Use 0 for ungrouped. If NULL (default), all conditions are treated independently.
Value
A single-row data.frame with columns mean_contrast_*,
se_contrast_*, p_contrast_* for both deviation and pairwise
contrasts. Returns NULL if fewer than 2 tested conditions.
Examples
om <- matrix(c(0.1, 0.2, 0.3), 1, 3,
dimnames = list("chr1:100:A:G", c("a", "b", "c")))
pm <- matrix(c(0.5, 0.3, -0.2), 1, 3,
dimnames = list("chr1:100:A:G", c("a", "b", "c")))
pv <- array(diag(3) * 0.1, dim = c(3, 3, 1))
dimnames(pv) <- list(c("a", "b", "c"), c("a", "b", "c"), NULL)
fitMashContrast(1L, om, pm, pv)
#> # A tibble: 1 × 19
#> feature_id mean_contrast_a_deviation se_contrast_a_deviation
#> <chr> <dbl> <dbl>
#> 1 chr1:100:A:G 0.45 0.387
#> # ℹ 16 more variables: p_contrast_a_deviation <dbl>,
#> # mean_contrast_b_deviation <dbl>, se_contrast_b_deviation <dbl>,
#> # p_contrast_b_deviation <dbl>, mean_contrast_c_deviation <dbl>,
#> # se_contrast_c_deviation <dbl>, p_contrast_c_deviation <dbl>,
#> # mean_contrast_a_vs_b <dbl>, se_contrast_a_vs_b <dbl>,
#> # p_contrast_a_vs_b <dbl>, mean_contrast_a_vs_c <dbl>,
#> # se_contrast_a_vs_c <dbl>, p_contrast_a_vs_c <dbl>, …