Skip to contents

Orchestrates fitMashContrast across every feature (variant) of a mash posterior: aligns the original effect matrix to the posterior columns, runs the per-feature deviation + pairwise contrast, row-binds the results (aligning the union of contrast columns), and orders them (mean/se/p, deviation before pairwise). Features with fewer than two tested conditions are dropped.

Usage

mashPosteriorContrast(posteriorMean, posteriorVcov, origMean, grouping = NULL)

Arguments

posteriorMean

Numeric matrix (features x conditions) of posterior means (PosteriorMean from mashPosterior).

posteriorVcov

Numeric array (conditions x conditions x features) of posterior covariances (PosteriorCov).

origMean

Numeric matrix (features x conditions) of the original effect estimates (e.g. bhat); used to decide which conditions were tested per feature. Aligned to posteriorMean's columns by name; NaN is treated as 0 (untested).

grouping

Optional named integer vector assigning conditions to groups (0 = independent); forwarded to fitMashContrast so replicate populations of one cell type share weight. Names are condition labels.

Value

A tibble (features x contrasts) with a feature_id column followed by mean_contrast_*, se_contrast_*, p_contrast_* columns. Empty when nothing is testable.

Examples

pm <- matrix(c(0.5, 0.3, -0.2), 1, 3,
  dimnames = list("chr1:100:A:G", c("a", "b", "c")))
om <- matrix(c(0.1, 0.2, 0.3), 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)
mashPosteriorContrast(pm, pv, om)
#> # A tibble: 1 × 19
#>   feature_id   mean_contrast_a_deviation mean_contrast_b_deviation
#>   <chr>                            <dbl>                     <dbl>
#> 1 chr1:100:A:G                      0.45                      0.15
#> # ℹ 16 more variables: mean_contrast_c_deviation <dbl>,
#> #   mean_contrast_a_vs_b <dbl>, mean_contrast_a_vs_c <dbl>,
#> #   mean_contrast_b_vs_c <dbl>, se_contrast_a_deviation <dbl>,
#> #   se_contrast_b_deviation <dbl>, se_contrast_c_deviation <dbl>,
#> #   se_contrast_a_vs_b <dbl>, se_contrast_a_vs_c <dbl>,
#> #   se_contrast_b_vs_c <dbl>, p_contrast_a_deviation <dbl>,
#> #   p_contrast_b_deviation <dbl>, p_contrast_c_deviation <dbl>, …