Skip to contents

Build the mash prior covariance list U and mixture weights w from a {strong[, random, null]} SumStats collection. Split out of mashPipeline so the covariance-estimation chain lives in one place. The default builds every non-udr covariance component (canonical + pca + flash + flash_nonneg) and refines them with mashr extreme deconvolution (cov_ed).

Usage

mashPriorCovariances(
  sumStatsList,
  alpha,
  vhat = NULL,
  components = c("canonical", "pca", "flash", "flash_nonneg"),
  engine = c("cov_ed", "ud", "ud_ted"),
  nPcs = NULL,
  priorCovariances = NULL,
  priorComponents = NULL,
  udControl = list(),
  inputScale = c("auto", "beta", "z"),
  setSeed = 999
)

Arguments

sumStatsList

Named list (or S4Vectors::SimpleList) with at least "strong" (the discovery set the covariances are learned on).

alpha

mash alpha.

vhat

Residual correlation matrix (V); typically from mashResidualCorrelation. NULL -> identity.

components

Data-driven covariance components, any of "canonical", "pca", "flash" (default cov_flash), "flash_nonneg" (cov_flash(factors = "nonneg")). Built in that fixed order. Ignored by the "ud" / "ud_ted" engines.

engine

Covariance-refinement engine. "cov_ed" (default; mashr's exported cov_ed() extreme deconvolution, whose default algorithm = "bovy" IS the Bovy et al. 2011 method – weights from a final mash()); "ud" / "ud_ted" (udr ED / TED updates, returning weights directly – OPT-IN, known numerical issues, so not the default; "ud_ted" additionally needs i.i.d. (z-scale) data).

nPcs

PCs seeded into cov_pca. Default ncol(Bhat) - 1.

priorCovariances

Optional caller-supplied prior U: a non-empty named list of nCond x nCond matrices. When supplied, the covariance chain is bypassed and only the mixture-weight fit runs.

priorComponents

Optional caller-supplied raw covariance components (a non-empty named list, e.g. the concatenated mashCovarianceComponents outputs). When supplied, these are refined by engine instead of being rebuilt internally – the mixture-prior pipeline where separate steps built the components. components / nPcs are then ignored. Distinct from priorCovariances, which bypasses the engine entirely.

udControl

Named list overriding the udr controls for the "ud" / "ud_ted" engines: n_unconstrained (data-driven matrices to fit; default 50 – the dominant cost, so reduce it for few-condition data), maxiter (default 1000), tol, tol.lik. Ignored by cov_ed.

inputScale

SumStats -> matrix conversion scale.

setSeed

Integer seed, or NULL to leave the ambient RNG untouched.

Value

list(U, w, loglik): the covariance list, the mashr::get_estimated_pi() mixture weights, and the fit log-likelihood (NULL for the cov_ed engine).

Examples

data(qtlSumStatsMulticontextExample)
ss <- qtlSumStatsMulticontextExample
sumStatsList <- list(strong = ss, random = ss)
mashPriorCovariances(sumStatsList, alpha = 0)
#> Adding factor 1 to flash object...
#> Adding factor 2 to flash object...
#> Adding factor 3 to flash object...
#> Factor doesn't significantly increase objective and won't be added.
#> Wrapping up...
#> Done.
#> Backfitting 2 factors (tolerance: 8.94e-06)...
#>   Difference between iterations is within 1.0e+00...
#>   Difference between iterations is within 1.0e-01...
#>   Difference between iterations is within 1.0e-02...
#>   Difference between iterations is within 1.0e-03...
#>   Difference between iterations is within 1.0e-04...
#> Wrapping up...
#> Done.
#> Adding factor 1 to flash object...
#> Adding factor 2 to flash object...
#> Adding factor 3 to flash object...
#> Factor doesn't significantly increase objective and won't be added.
#> Wrapping up...
#> Done.
#> Backfitting 2 factors (tolerance: 8.94e-06)...
#>   Difference between iterations is within 1.0e+00...
#>   Difference between iterations is within 1.0e-01...
#>   Difference between iterations is within 1.0e-02...
#>   Difference between iterations is within 1.0e-03...
#> Wrapping up...
#> Done.
#>  - Computing 200 x 545 likelihood matrix.
#>  - Likelihood calculations took 0.02 seconds.
#>  - Fitting model with 545 mixture components.
#>  - Model fitting took 1.30 seconds.
#> $U
#> $U$identity
#>      [,1] [,2] [,3]
#> [1,]    1    0    0
#> [2,]    0    1    0
#> [3,]    0    0    1
#> 
#> $U$brain
#>      [,1] [,2] [,3]
#> [1,]    1    0    0
#> [2,]    0    0    0
#> [3,]    0    0    0
#> 
#> $U$blood
#>      [,1] [,2] [,3]
#> [1,]    0    0    0
#> [2,]    0    1    0
#> [3,]    0    0    0
#> 
#> $U$muscle
#>      [,1] [,2] [,3]
#> [1,]    0    0    0
#> [2,]    0    0    0
#> [3,]    0    0    1
#> 
#> $U$equal_effects
#>      [,1] [,2] [,3]
#> [1,]    1    1    1
#> [2,]    1    1    1
#> [3,]    1    1    1
#> 
#> $U$simple_het_1
#>      [,1] [,2] [,3]
#> [1,] 1.00 0.25 0.25
#> [2,] 0.25 1.00 0.25
#> [3,] 0.25 0.25 1.00
#> 
#> $U$simple_het_2
#>      [,1] [,2] [,3]
#> [1,]  1.0  0.5  0.5
#> [2,]  0.5  1.0  0.5
#> [3,]  0.5  0.5  1.0
#> 
#> $U$simple_het_3
#>      [,1] [,2] [,3]
#> [1,] 1.00 0.75 0.75
#> [2,] 0.75 1.00 0.75
#> [3,] 0.75 0.75 1.00
#> 
#> $U$PCA_1
#>            brain     blood    muscle
#> brain  0.2031844 0.3340120 0.2243579
#> blood  0.3340120 0.5490777 0.3688188
#> muscle 0.2243579 0.3688188 0.2477379
#> 
#> $U$PCA_2
#>               brain       blood      muscle
#> brain   0.003729395  0.03240844 -0.05162538
#> blood   0.032408439  0.28162928 -0.44862448
#> muscle -0.051625382 -0.44862448  0.71464133
#> 
#> $U$tPCA
#>             brain      blood     muscle
#> brain  0.03035490 0.05053652 0.03216785
#> blood  0.05053652 0.08860772 0.04406890
#> muscle 0.03216785 0.04406890 0.05421172
#> 
#> $U$tFLASH_default
#>             brain      blood     muscle
#> brain  0.02925699 0.04153723 0.02668673
#> blood  0.04153723 0.05976538 0.04117086
#> muscle 0.02668673 0.04117086 0.03792385
#> 
#> $U$FLASH_default_1
#>            brain     blood    muscle
#> brain  0.2369678 0.3444523 0.2493325
#> blood  0.3444523 0.5006899 0.3624253
#> muscle 0.2493325 0.3624253 0.2623423
#> 
#> $U$FLASH_default_2
#>             brain      blood     muscle
#> brain   0.2390964  0.1950579 -0.3793174
#> blood   0.1950579  0.1591308 -0.3094521
#> muscle -0.3793174 -0.3094521  0.6017728
#> 
#> $U$tFLASH_nonneg
#>             brain      blood     muscle
#> brain  0.02858018 0.04225972 0.02669381
#> blood  0.04225972 0.06248734 0.03955125
#> muscle 0.02669381 0.03955125 0.03703607
#> 
#> $U$FLASH_nonneg_1
#>            brain     blood    muscle
#> brain  0.2370147 0.3505876 0.2406804
#> blood  0.3505876 0.5185825 0.3560099
#> muscle 0.2406804 0.3560099 0.2444028
#> 
#> $U$FLASH_nonneg_2
#>               brain        blood       muscle
#> brain  8.739128e-07 7.525978e-06 0.0009348023
#> blood  7.525978e-06 6.481236e-05 0.0080503477
#> muscle 9.348023e-04 8.050348e-03 0.9999343137
#> 
#> $U$ED_identity
#>            brain     blood    muscle
#> brain  0.1603756 0.1394984 0.0964617
#> blood  0.1394984 0.2879458 0.1501503
#> muscle 0.0964617 0.1501503 0.1745825
#> 
#> $U$ED_brain
#>             brain      blood     muscle
#> brain  0.07075703 0.00000000 0.00000000
#> blood  0.00000000 0.07071068 0.00000000
#> muscle 0.00000000 0.00000000 0.07071068
#> 
#> $U$ED_blood
#>             brain      blood     muscle
#> brain  0.07071068 0.00000000 0.00000000
#> blood  0.00000000 0.07169349 0.00000000
#> muscle 0.00000000 0.00000000 0.07071068
#> 
#> $U$ED_muscle
#>             brain      blood     muscle
#> brain  0.07071068 0.00000000 0.00000000
#> blood  0.00000000 0.07071068 0.00000000
#> muscle 0.00000000 0.00000000 0.07101281
#> 
#> $U$ED_equal_effects
#>            brain     blood    muscle
#> brain  0.1920864 0.1213757 0.1213757
#> blood  0.1213757 0.1920864 0.1213757
#> muscle 0.1213757 0.1213757 0.1920864
#> 
#> $U$ED_simple_het_1
#>             brain     blood     muscle
#> brain  0.16038325 0.1395023 0.09646718
#> blood  0.13950227 0.2879394 0.15015016
#> muscle 0.09646718 0.1501502 0.17458542
#> 
#> $U$ED_simple_het_2
#>             brain     blood     muscle
#> brain  0.16038636 0.1395039 0.09646933
#> blood  0.13950390 0.2879370 0.15015005
#> muscle 0.09646933 0.1501500 0.17458642
#> 
#> $U$ED_simple_het_3
#>            brain     blood    muscle
#> brain  0.1603905 0.1395060 0.0964723
#> blood  0.1395060 0.2879335 0.1501500
#> muscle 0.0964723 0.1501500 0.1745880
#> 
#> $U$ED_PCA_1
#>             brain     blood     muscle
#> brain  0.15288789 0.1350900 0.09074076
#> blood  0.13508996 0.2927832 0.14916745
#> muscle 0.09074076 0.1491674 0.17090737
#> 
#> $U$ED_PCA_2
#>                brain         blood        muscle
#> brain   7.071112e-02  3.824621e-06 -6.092473e-06
#> blood   3.824621e-06  7.074391e-02 -5.294358e-05
#> muscle -6.092473e-06 -5.294358e-05  7.079502e-02
#> 
#> $U$ED_tPCA
#>              brain       blood      muscle
#> brain  0.072757257 0.003237185 0.002529590
#> blood  0.003237185 0.075854855 0.003950818
#> muscle 0.002529590 0.003950818 0.073944129
#> 
#> $U$ED_tFLASH_default
#>              brain       blood      muscle
#> brain  0.071877251 0.001951201 0.002284485
#> blood  0.001951201 0.073990563 0.003888538
#> muscle 0.002284485 0.003888538 0.075463727
#> 
#> $U$ED_FLASH_default_1
#>            brain     blood    muscle
#> brain  0.1684463 0.1420668 0.1028353
#> blood  0.1420668 0.2772165 0.1494796
#> muscle 0.1028353 0.1494796 0.1789118
#> 
#> $U$ED_FLASH_default_2
#>                brain         blood        muscle
#> brain   7.072839e-02  1.444927e-05 -2.809862e-05
#> blood   1.444927e-05  7.072247e-02 -2.292322e-05
#> muscle -2.809862e-05 -2.292322e-05  7.075526e-02
#> 
#> $U$ED_tFLASH_nonneg
#>              brain       blood      muscle
#> brain  0.072148940 0.002133603 0.002382392
#> blood  0.002133603 0.073875800 0.003535582
#> muscle 0.002382392 0.003535582 0.074866869
#> 
#> $U$ED_FLASH_nonneg_1
#>             brain     blood     muscle
#> brain  0.16797262 0.1438680 0.09876623
#> blood  0.14386802 0.2835175 0.14609312
#> muscle 0.09876623 0.1460931 0.17100445
#> 
#> $U$ED_FLASH_nonneg_2
#>               brain        blood       muscle
#> brain  7.071068e-02 2.367752e-09 2.940987e-07
#> blood  2.367752e-09 7.071070e-02 2.532724e-06
#> muscle 2.940987e-07 2.532724e-06 7.102527e-02
#> 
#> 
#> $w
#>               null           identity              brain              blood 
#>         0.64907026         0.00000000         0.00000000         0.00000000 
#>             muscle      equal_effects       simple_het_1       simple_het_2 
#>         0.00000000         0.00000000         0.00000000         0.00000000 
#>       simple_het_3              PCA_1              PCA_2               tPCA 
#>         0.00000000         0.21480191         0.00000000         0.00000000 
#>     tFLASH_default    FLASH_default_1    FLASH_default_2      tFLASH_nonneg 
#>         0.00000000         0.11443497         0.00000000         0.00000000 
#>     FLASH_nonneg_1     FLASH_nonneg_2        ED_identity           ED_brain 
#>         0.00000000         0.02169286         0.00000000         0.00000000 
#>           ED_blood          ED_muscle   ED_equal_effects    ED_simple_het_1 
#>         0.00000000         0.00000000         0.00000000         0.00000000 
#>    ED_simple_het_2    ED_simple_het_3           ED_PCA_1           ED_PCA_2 
#>         0.00000000         0.00000000         0.00000000         0.00000000 
#>            ED_tPCA  ED_tFLASH_default ED_FLASH_default_1 ED_FLASH_default_2 
#>         0.00000000         0.00000000         0.00000000         0.00000000 
#>   ED_tFLASH_nonneg  ED_FLASH_nonneg_1  ED_FLASH_nonneg_2 
#>         0.00000000         0.00000000         0.00000000 
#> 
#> $loglik
#> NULL
#>