Skip to contents

Shared helper used by both mrmashWrapper (individual-level) and mrmashRssWeights (summary statistics). Constructs the S0 list of prior covariance matrices via the canonical mixture (mr.mashr::compute_canonical_covs) and optional data-driven matrices, expanded over a scaling grid via mr.mashr::expand_covs. The prior grid is derived from Bhat and Shat via computeGrid when not supplied.

Usage

buildMrmashPriorMatrices(
  Bhat,
  Shat,
  K = NULL,
  dataDrivenPriorMatrices = NULL,
  canonicalPriorMatrices = TRUE,
  priorGrid = NULL,
  hetgrid = c(0, 0.25, 0.5, 0.75, 1),
  singletons = TRUE
)

Arguments

Bhat

Numeric matrix of effect-size estimates (variants x conditions).

Shat

Numeric matrix of standard errors (variants x conditions).

K

Number of conditions. When NULL, inferred from ncol(Bhat).

dataDrivenPriorMatrices

Optional list with element U (list of raw covariance matrices) computed e.g. by computeCovFlash / computeCovDiag.

canonicalPriorMatrices

Logical. When TRUE (default for RSS), include the standard canonical mixture from mr.mashr::compute_canonical_covs(). When FALSE, dataDrivenPriorMatrices must be supplied.

priorGrid

Optional pre-computed scaling grid (numeric vector). When NULL, derived from Bhat, Shat via computeGrid().

hetgrid

Heterogeneity grid passed to mr.mashr::compute_canonical_covs(). Default c(0, 0.25, 0.5, 0.75, 1), matching the individual-level wrapper.

singletons

Whether to include single-condition prior components. Default TRUE.

Value

A list with components S0 (the expanded list of prior covariance matrices) and prior_grid (the scaling grid that was used).

Examples

Bhat <- matrix(rnorm(15), 5, 3)
Shat <- matrix(abs(rnorm(15)) + 0.1, 5, 3)
buildMrmashPriorMatrices(Bhat = Bhat, Shat = Shat)
#> $S0
#> $S0$null
#>      [,1] [,2] [,3]
#> [1,]    0    0    0
#> [2,]    0    0    0
#> [3,]    0    0    0
#> 
#> $S0$singleton1_grid1
#>            [,1] [,2] [,3]
#> [1,] 0.08303462    0    0
#> [2,] 0.00000000    0    0
#> [3,] 0.00000000    0    0
#> 
#> $S0$singleton1_grid2
#>           [,1] [,2] [,3]
#> [1,] 0.1660692    0    0
#> [2,] 0.0000000    0    0
#> [3,] 0.0000000    0    0
#> 
#> $S0$singleton1_grid3
#>           [,1] [,2] [,3]
#> [1,] 0.3321385    0    0
#> [2,] 0.0000000    0    0
#> [3,] 0.0000000    0    0
#> 
#> $S0$singleton1_grid4
#>          [,1] [,2] [,3]
#> [1,] 0.664277    0    0
#> [2,] 0.000000    0    0
#> [3,] 0.000000    0    0
#> 
#> $S0$singleton1_grid5
#>          [,1] [,2] [,3]
#> [1,] 1.328554    0    0
#> [2,] 0.000000    0    0
#> [3,] 0.000000    0    0
#> 
#> $S0$singleton1_grid6
#>          [,1] [,2] [,3]
#> [1,] 2.657108    0    0
#> [2,] 0.000000    0    0
#> [3,] 0.000000    0    0
#> 
#> $S0$singleton1_grid7
#>          [,1] [,2] [,3]
#> [1,] 5.314216    0    0
#> [2,] 0.000000    0    0
#> [3,] 0.000000    0    0
#> 
#> $S0$singleton1_grid8
#>          [,1] [,2] [,3]
#> [1,] 10.62843    0    0
#> [2,]  0.00000    0    0
#> [3,]  0.00000    0    0
#> 
#> $S0$singleton1_grid9
#>          [,1] [,2] [,3]
#> [1,] 21.25686    0    0
#> [2,]  0.00000    0    0
#> [3,]  0.00000    0    0
#> 
#> $S0$singleton2_grid1
#>      [,1]       [,2] [,3]
#> [1,]    0 0.00000000    0
#> [2,]    0 0.08303462    0
#> [3,]    0 0.00000000    0
#> 
#> $S0$singleton2_grid2
#>      [,1]      [,2] [,3]
#> [1,]    0 0.0000000    0
#> [2,]    0 0.1660692    0
#> [3,]    0 0.0000000    0
#> 
#> $S0$singleton2_grid3
#>      [,1]      [,2] [,3]
#> [1,]    0 0.0000000    0
#> [2,]    0 0.3321385    0
#> [3,]    0 0.0000000    0
#> 
#> $S0$singleton2_grid4
#>      [,1]     [,2] [,3]
#> [1,]    0 0.000000    0
#> [2,]    0 0.664277    0
#> [3,]    0 0.000000    0
#> 
#> $S0$singleton2_grid5
#>      [,1]     [,2] [,3]
#> [1,]    0 0.000000    0
#> [2,]    0 1.328554    0
#> [3,]    0 0.000000    0
#> 
#> $S0$singleton2_grid6
#>      [,1]     [,2] [,3]
#> [1,]    0 0.000000    0
#> [2,]    0 2.657108    0
#> [3,]    0 0.000000    0
#> 
#> $S0$singleton2_grid7
#>      [,1]     [,2] [,3]
#> [1,]    0 0.000000    0
#> [2,]    0 5.314216    0
#> [3,]    0 0.000000    0
#> 
#> $S0$singleton2_grid8
#>      [,1]     [,2] [,3]
#> [1,]    0  0.00000    0
#> [2,]    0 10.62843    0
#> [3,]    0  0.00000    0
#> 
#> $S0$singleton2_grid9
#>      [,1]     [,2] [,3]
#> [1,]    0  0.00000    0
#> [2,]    0 21.25686    0
#> [3,]    0  0.00000    0
#> 
#> $S0$singleton3_grid1
#>      [,1] [,2]       [,3]
#> [1,]    0    0 0.00000000
#> [2,]    0    0 0.00000000
#> [3,]    0    0 0.08303462
#> 
#> $S0$singleton3_grid2
#>      [,1] [,2]      [,3]
#> [1,]    0    0 0.0000000
#> [2,]    0    0 0.0000000
#> [3,]    0    0 0.1660692
#> 
#> $S0$singleton3_grid3
#>      [,1] [,2]      [,3]
#> [1,]    0    0 0.0000000
#> [2,]    0    0 0.0000000
#> [3,]    0    0 0.3321385
#> 
#> $S0$singleton3_grid4
#>      [,1] [,2]     [,3]
#> [1,]    0    0 0.000000
#> [2,]    0    0 0.000000
#> [3,]    0    0 0.664277
#> 
#> $S0$singleton3_grid5
#>      [,1] [,2]     [,3]
#> [1,]    0    0 0.000000
#> [2,]    0    0 0.000000
#> [3,]    0    0 1.328554
#> 
#> $S0$singleton3_grid6
#>      [,1] [,2]     [,3]
#> [1,]    0    0 0.000000
#> [2,]    0    0 0.000000
#> [3,]    0    0 2.657108
#> 
#> $S0$singleton3_grid7
#>      [,1] [,2]     [,3]
#> [1,]    0    0 0.000000
#> [2,]    0    0 0.000000
#> [3,]    0    0 5.314216
#> 
#> $S0$singleton3_grid8
#>      [,1] [,2]     [,3]
#> [1,]    0    0  0.00000
#> [2,]    0    0  0.00000
#> [3,]    0    0 10.62843
#> 
#> $S0$singleton3_grid9
#>      [,1] [,2]     [,3]
#> [1,]    0    0  0.00000
#> [2,]    0    0  0.00000
#> [3,]    0    0 21.25686
#> 
#> $S0$independent_grid1
#>            [,1]       [,2]       [,3]
#> [1,] 0.08303462 0.00000000 0.00000000
#> [2,] 0.00000000 0.08303462 0.00000000
#> [3,] 0.00000000 0.00000000 0.08303462
#> 
#> $S0$independent_grid2
#>           [,1]      [,2]      [,3]
#> [1,] 0.1660692 0.0000000 0.0000000
#> [2,] 0.0000000 0.1660692 0.0000000
#> [3,] 0.0000000 0.0000000 0.1660692
#> 
#> $S0$independent_grid3
#>           [,1]      [,2]      [,3]
#> [1,] 0.3321385 0.0000000 0.0000000
#> [2,] 0.0000000 0.3321385 0.0000000
#> [3,] 0.0000000 0.0000000 0.3321385
#> 
#> $S0$independent_grid4
#>          [,1]     [,2]     [,3]
#> [1,] 0.664277 0.000000 0.000000
#> [2,] 0.000000 0.664277 0.000000
#> [3,] 0.000000 0.000000 0.664277
#> 
#> $S0$independent_grid5
#>          [,1]     [,2]     [,3]
#> [1,] 1.328554 0.000000 0.000000
#> [2,] 0.000000 1.328554 0.000000
#> [3,] 0.000000 0.000000 1.328554
#> 
#> $S0$independent_grid6
#>          [,1]     [,2]     [,3]
#> [1,] 2.657108 0.000000 0.000000
#> [2,] 0.000000 2.657108 0.000000
#> [3,] 0.000000 0.000000 2.657108
#> 
#> $S0$independent_grid7
#>          [,1]     [,2]     [,3]
#> [1,] 5.314216 0.000000 0.000000
#> [2,] 0.000000 5.314216 0.000000
#> [3,] 0.000000 0.000000 5.314216
#> 
#> $S0$independent_grid8
#>          [,1]     [,2]     [,3]
#> [1,] 10.62843  0.00000  0.00000
#> [2,]  0.00000 10.62843  0.00000
#> [3,]  0.00000  0.00000 10.62843
#> 
#> $S0$independent_grid9
#>          [,1]     [,2]     [,3]
#> [1,] 21.25686  0.00000  0.00000
#> [2,]  0.00000 21.25686  0.00000
#> [3,]  0.00000  0.00000 21.25686
#> 
#> $S0$shared0.25_grid1
#>            [,1]       [,2]       [,3]
#> [1,] 0.08303462 0.02075866 0.02075866
#> [2,] 0.02075866 0.08303462 0.02075866
#> [3,] 0.02075866 0.02075866 0.08303462
#> 
#> $S0$shared0.25_grid2
#>            [,1]       [,2]       [,3]
#> [1,] 0.16606924 0.04151731 0.04151731
#> [2,] 0.04151731 0.16606924 0.04151731
#> [3,] 0.04151731 0.04151731 0.16606924
#> 
#> $S0$shared0.25_grid3
#>            [,1]       [,2]       [,3]
#> [1,] 0.33213848 0.08303462 0.08303462
#> [2,] 0.08303462 0.33213848 0.08303462
#> [3,] 0.08303462 0.08303462 0.33213848
#> 
#> $S0$shared0.25_grid4
#>           [,1]      [,2]      [,3]
#> [1,] 0.6642770 0.1660692 0.1660692
#> [2,] 0.1660692 0.6642770 0.1660692
#> [3,] 0.1660692 0.1660692 0.6642770
#> 
#> $S0$shared0.25_grid5
#>           [,1]      [,2]      [,3]
#> [1,] 1.3285539 0.3321385 0.3321385
#> [2,] 0.3321385 1.3285539 0.3321385
#> [3,] 0.3321385 0.3321385 1.3285539
#> 
#> $S0$shared0.25_grid6
#>          [,1]     [,2]     [,3]
#> [1,] 2.657108 0.664277 0.664277
#> [2,] 0.664277 2.657108 0.664277
#> [3,] 0.664277 0.664277 2.657108
#> 
#> $S0$shared0.25_grid7
#>          [,1]     [,2]     [,3]
#> [1,] 5.314216 1.328554 1.328554
#> [2,] 1.328554 5.314216 1.328554
#> [3,] 1.328554 1.328554 5.314216
#> 
#> $S0$shared0.25_grid8
#>           [,1]      [,2]      [,3]
#> [1,] 10.628431  2.657108  2.657108
#> [2,]  2.657108 10.628431  2.657108
#> [3,]  2.657108  2.657108 10.628431
#> 
#> $S0$shared0.25_grid9
#>           [,1]      [,2]      [,3]
#> [1,] 21.256863  5.314216  5.314216
#> [2,]  5.314216 21.256863  5.314216
#> [3,]  5.314216  5.314216 21.256863
#> 
#> $S0$shared0.5_grid1
#>            [,1]       [,2]       [,3]
#> [1,] 0.08303462 0.04151731 0.04151731
#> [2,] 0.04151731 0.08303462 0.04151731
#> [3,] 0.04151731 0.04151731 0.08303462
#> 
#> $S0$shared0.5_grid2
#>            [,1]       [,2]       [,3]
#> [1,] 0.16606924 0.08303462 0.08303462
#> [2,] 0.08303462 0.16606924 0.08303462
#> [3,] 0.08303462 0.08303462 0.16606924
#> 
#> $S0$shared0.5_grid3
#>           [,1]      [,2]      [,3]
#> [1,] 0.3321385 0.1660692 0.1660692
#> [2,] 0.1660692 0.3321385 0.1660692
#> [3,] 0.1660692 0.1660692 0.3321385
#> 
#> $S0$shared0.5_grid4
#>           [,1]      [,2]      [,3]
#> [1,] 0.6642770 0.3321385 0.3321385
#> [2,] 0.3321385 0.6642770 0.3321385
#> [3,] 0.3321385 0.3321385 0.6642770
#> 
#> $S0$shared0.5_grid5
#>          [,1]     [,2]     [,3]
#> [1,] 1.328554 0.664277 0.664277
#> [2,] 0.664277 1.328554 0.664277
#> [3,] 0.664277 0.664277 1.328554
#> 
#> $S0$shared0.5_grid6
#>          [,1]     [,2]     [,3]
#> [1,] 2.657108 1.328554 1.328554
#> [2,] 1.328554 2.657108 1.328554
#> [3,] 1.328554 1.328554 2.657108
#> 
#> $S0$shared0.5_grid7
#>          [,1]     [,2]     [,3]
#> [1,] 5.314216 2.657108 2.657108
#> [2,] 2.657108 5.314216 2.657108
#> [3,] 2.657108 2.657108 5.314216
#> 
#> $S0$shared0.5_grid8
#>           [,1]      [,2]      [,3]
#> [1,] 10.628431  5.314216  5.314216
#> [2,]  5.314216 10.628431  5.314216
#> [3,]  5.314216  5.314216 10.628431
#> 
#> $S0$shared0.5_grid9
#>          [,1]     [,2]     [,3]
#> [1,] 21.25686 10.62843 10.62843
#> [2,] 10.62843 21.25686 10.62843
#> [3,] 10.62843 10.62843 21.25686
#> 
#> $S0$shared0.75_grid1
#>            [,1]       [,2]       [,3]
#> [1,] 0.08303462 0.06227597 0.06227597
#> [2,] 0.06227597 0.08303462 0.06227597
#> [3,] 0.06227597 0.06227597 0.08303462
#> 
#> $S0$shared0.75_grid2
#>           [,1]      [,2]      [,3]
#> [1,] 0.1660692 0.1245519 0.1245519
#> [2,] 0.1245519 0.1660692 0.1245519
#> [3,] 0.1245519 0.1245519 0.1660692
#> 
#> $S0$shared0.75_grid3
#>           [,1]      [,2]      [,3]
#> [1,] 0.3321385 0.2491039 0.2491039
#> [2,] 0.2491039 0.3321385 0.2491039
#> [3,] 0.2491039 0.2491039 0.3321385
#> 
#> $S0$shared0.75_grid4
#>           [,1]      [,2]      [,3]
#> [1,] 0.6642770 0.4982077 0.4982077
#> [2,] 0.4982077 0.6642770 0.4982077
#> [3,] 0.4982077 0.4982077 0.6642770
#> 
#> $S0$shared0.75_grid5
#>           [,1]      [,2]      [,3]
#> [1,] 1.3285539 0.9964154 0.9964154
#> [2,] 0.9964154 1.3285539 0.9964154
#> [3,] 0.9964154 0.9964154 1.3285539
#> 
#> $S0$shared0.75_grid6
#>          [,1]     [,2]     [,3]
#> [1,] 2.657108 1.992831 1.992831
#> [2,] 1.992831 2.657108 1.992831
#> [3,] 1.992831 1.992831 2.657108
#> 
#> $S0$shared0.75_grid7
#>          [,1]     [,2]     [,3]
#> [1,] 5.314216 3.985662 3.985662
#> [2,] 3.985662 5.314216 3.985662
#> [3,] 3.985662 3.985662 5.314216
#> 
#> $S0$shared0.75_grid8
#>           [,1]      [,2]      [,3]
#> [1,] 10.628431  7.971324  7.971324
#> [2,]  7.971324 10.628431  7.971324
#> [3,]  7.971324  7.971324 10.628431
#> 
#> $S0$shared0.75_grid9
#>          [,1]     [,2]     [,3]
#> [1,] 21.25686 15.94265 15.94265
#> [2,] 15.94265 21.25686 15.94265
#> [3,] 15.94265 15.94265 21.25686
#> 
#> $S0$shared1_grid1
#>            [,1]       [,2]       [,3]
#> [1,] 0.08303462 0.08303462 0.08303462
#> [2,] 0.08303462 0.08303462 0.08303462
#> [3,] 0.08303462 0.08303462 0.08303462
#> 
#> $S0$shared1_grid2
#>           [,1]      [,2]      [,3]
#> [1,] 0.1660692 0.1660692 0.1660692
#> [2,] 0.1660692 0.1660692 0.1660692
#> [3,] 0.1660692 0.1660692 0.1660692
#> 
#> $S0$shared1_grid3
#>           [,1]      [,2]      [,3]
#> [1,] 0.3321385 0.3321385 0.3321385
#> [2,] 0.3321385 0.3321385 0.3321385
#> [3,] 0.3321385 0.3321385 0.3321385
#> 
#> $S0$shared1_grid4
#>          [,1]     [,2]     [,3]
#> [1,] 0.664277 0.664277 0.664277
#> [2,] 0.664277 0.664277 0.664277
#> [3,] 0.664277 0.664277 0.664277
#> 
#> $S0$shared1_grid5
#>          [,1]     [,2]     [,3]
#> [1,] 1.328554 1.328554 1.328554
#> [2,] 1.328554 1.328554 1.328554
#> [3,] 1.328554 1.328554 1.328554
#> 
#> $S0$shared1_grid6
#>          [,1]     [,2]     [,3]
#> [1,] 2.657108 2.657108 2.657108
#> [2,] 2.657108 2.657108 2.657108
#> [3,] 2.657108 2.657108 2.657108
#> 
#> $S0$shared1_grid7
#>          [,1]     [,2]     [,3]
#> [1,] 5.314216 5.314216 5.314216
#> [2,] 5.314216 5.314216 5.314216
#> [3,] 5.314216 5.314216 5.314216
#> 
#> $S0$shared1_grid8
#>          [,1]     [,2]     [,3]
#> [1,] 10.62843 10.62843 10.62843
#> [2,] 10.62843 10.62843 10.62843
#> [3,] 10.62843 10.62843 10.62843
#> 
#> $S0$shared1_grid9
#>          [,1]     [,2]     [,3]
#> [1,] 21.25686 21.25686 21.25686
#> [2,] 21.25686 21.25686 21.25686
#> [3,] 21.25686 21.25686 21.25686
#> 
#> 
#> $priorGrid
#> [1]  0.08303462  0.16606924  0.33213848  0.66427696  1.32855393  2.65710785
#> [7]  5.31421571 10.62843141 21.25686282
#>