invert.matrices.jointly: Joint inversion of many covariance matrices

Description Usage Arguments Details Value Note Author(s) Examples

Description

Invert p covariance matrices of dimension S by S, reprented in a single matrix of dimension p by (s^2) together. This is used to speed up MetaGLS computations, that are based on estimated effects across multiple strata, and their covariances.

Usage

1

Arguments

cov.mats

A p by s^2 matrix representing p s by s covariance matrices between SNP effects in s strata.

Details

This function is called by corMeta.GLS.invert.mats, which is called by MetaCor when testType is MetaGLS.

Value

A p by s^2 matrix representing p s by s inversees of the input covariance matrices.

Note

Called by corMeta.GLS.invert.mats

Author(s)

Tamar Sofer

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
n.strat <- 5
n.est <- 5
## create a positive definite matrix to be a covariance matrix
sigma.1 <- matrix(rnorm(n.strat^2), n.strat, n.strat)
sigma.1 <- t(sigma.1) 

vars <- matrix(rep(diag(sigma.1), n.est), nrow = n.est, ncol = n.strat, byrow = T)
colnames(vars) <- paste0("var.s", 1:n.strat)
covs <- matrix(rep(sigma.1[lower.tri(sigma.1)], n.est), nrow = n.est, byrow = T)
colnames(covs) <- c(paste0("cov.s1:", paste0("s", 2:n.strat)), paste0("cov.s2:", paste0("s", 3:n.strat)), paste0("cov.s3:", paste0("s", 4:n.strat)) , "cov.s4:s5")


### now change their representation:
full.covs.1 <- change.cov.mat.representation(vars, covs)



sigma.2 <- matrix(rnorm(n.strat^2), n.strat, n.strat)
sigma.2 <- t(sigma.2) 

vars <- matrix(rep(diag(sigma.2), n.est), nrow = n.est, ncol = n.strat, byrow = T)
colnames(vars) <- paste0("var.s", 1:n.strat)
covs <- matrix(rep(sigma.2[lower.tri(sigma.2)], n.est), nrow = n.est, byrow = T)
colnames(covs) <- c(paste0("cov.s1:", paste0("s", 2:n.strat)), paste0("cov.s2:", paste0("s", 3:n.strat)), paste0("cov.s3:", paste0("s", 4:n.strat)) , "cov.s4:s5")

### now change their representation:
full.covs.2 <- change.cov.mat.representation(vars, covs)

full.covs <- rbind(full.covs.1, full.covs.2)
full.inv.covs <- invert.matrices.jointly(full.covs)
all(abs(full.inv.covs[10,] - solve(sigma.2)[1:25]) < 1e-10)

tamartsi/MetaCor documentation built on May 31, 2019, 2:56 a.m.