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 + flashNonneg) and refines them with mashr extreme deconvolution (cov_ed).

Usage

mashPriorCovariances(
  sumStatsList,
  alpha,
  vhat = NULL,
  components = c("canonical", "pca", "flash", "flashNonneg"),
  engine = c("covEd", "covUdr", "none"),
  nPcs = NULL,
  priorCovariances = NULL,
  priorComponents = NULL,
  inputScale = c("auto", "beta", "z"),
  mashDataArgs = MashDataOptions(),
  mashArgs = MashOptions(),
  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), "flashNonneg" (cov_flash(factors = "nonneg")). Built in that fixed order. May instead be a MashComponentParam record, which names the components and carries each one's options.

engine

Covariance-refinement engine, either a name or the matching constructor carrying that engine's settings. "covEd" (default; CovEdOptions – mashr's exported cov_ed() extreme deconvolution, whose default algorithm = "bovy" IS the Bovy et al. 2011 method, weights from a final mash()); "covUdr" (CovUdrOptions – udr ED / TED updates, returning weights directly – OPT-IN, known numerical issues, so not the default; UdFitOptions(unconstrained.update = "ted") additionally needs i.i.d. (z-scale) data); "none" to skip refinement.

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, or a mashPriorCovariances result, which is unwrapped to its U. 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, or a mashPriorCovariances result, which is unwrapped to its U). 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.

inputScale

SumStats -> matrix conversion scale.

mashDataArgs

Extra arguments for mashr::mash_set_data(), built with MashDataOptions – for example zero_Bhat_Shat_reset or zero_Shat_reset. Bhat, Shat, alpha and V are supplied by pecotmr and are refused by the constructor.

mashArgs

Extra arguments for mashr::mash(), built with MashOptions – for example nullweight, optmethod or verbose. data, Ulist, outputlevel and seed are owned by pecotmr and are refused by the constructor.

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 273 likelihood matrix.
#>  - Likelihood calculations took 0.02 seconds.
#>  - Fitting model with 273 mixture components.
#>  - Model fitting took 0.41 seconds.
#> $U
#> $U$ED_PCA_1
#>             brain     blood     muscle
#> brain  0.15289673 0.1351045 0.09075052
#> blood  0.13510450 0.2928071 0.14918350
#> muscle 0.09075052 0.1491835 0.17091815
#> 
#> $U$ED_PCA_2
#>                brain         blood        muscle
#> brain   7.071112e-02  3.869435e-06 -6.163860e-06
#> blood   3.869435e-06  7.074430e-02 -5.356393e-05
#> muscle -6.163860e-06 -5.356393e-05  7.079600e-02
#> 
#> $U$ED_tPCA
#>              brain       blood      muscle
#> brain  0.072756163 0.003235763 0.002527583
#> blood  0.003235763 0.075853371 0.003947439
#> muscle 0.002527583 0.003947439 0.073942083
#> 
#> $U$ED_tFLASH_default
#>              brain       blood      muscle
#> brain  0.071877036 0.001950940 0.002284472
#> blood  0.001950940 0.073990396 0.003889138
#> muscle 0.002284472 0.003889138 0.075466277
#> 
#> $U$ED_FLASH_default_1
#>            brain     blood    muscle
#> brain  0.1684507 0.1420732 0.1028400
#> blood  0.1420732 0.2772258 0.1494864
#> muscle 0.1028400 0.1494864 0.1789167
#> 
#> $U$ED_FLASH_default_2
#>                brain         blood        muscle
#> brain   7.072856e-02  1.459131e-05 -2.837483e-05
#> blood   1.459131e-05  7.072258e-02 -2.314856e-05
#> muscle -2.837483e-05 -2.314856e-05  7.075569e-02
#> 
#> $U$ED_tFLASH_nonneg
#>              brain       blood      muscle
#> brain  0.072149086 0.002133816 0.002382316
#> blood  0.002133816 0.073876114 0.003535475
#> muscle 0.002382316 0.003535475 0.074867554
#> 
#> $U$ED_FLASH_nonneg_1
#>             brain     blood     muscle
#> brain  0.16797922 0.1438778 0.09877292
#> blood  0.14387777 0.2835319 0.14610302
#> muscle 0.09877292 0.1461030 0.17101125
#> 
#> $U$ED_FLASH_nonneg_2
#>               brain        blood       muscle
#> brain  7.071068e-02 2.264767e-09 2.813069e-07
#> blood  2.264767e-09 7.071070e-02 2.422564e-06
#> muscle 2.813069e-07 2.422564e-06 7.101158e-02
#> 
#> $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
#> 
#> 
#> $w
#>               null           ED_PCA_1           ED_PCA_2            ED_tPCA 
#>         0.67084039         0.00000000         0.00000000         0.00000000 
#>  ED_tFLASH_default ED_FLASH_default_1 ED_FLASH_default_2   ED_tFLASH_nonneg 
#>         0.00000000         0.00000000         0.00000000         0.00000000 
#>  ED_FLASH_nonneg_1  ED_FLASH_nonneg_2           identity              brain 
#>         0.00000000         0.00000000         0.00000000         0.00000000 
#>              blood             muscle      equal_effects       simple_het_1 
#>         0.00000000         0.01470376         0.31445585         0.00000000 
#>       simple_het_2       simple_het_3 
#>         0.00000000         0.00000000 
#> 
#> $loglik
#> NULL
#>