Simulate marginal z-scores (\(Z_m\)) from the joint z-scores (\(Z_j\)) using \(E(Z_m) = Z_j \times \Sigma\) and \(Z* \sim MVN(E(Z_m), \Sigma)\)

z_sim(Zj, Sigma, nrep)

Arguments

Zj

Vector of joint Z-scores (a vector of 0s except at the CV)

Sigma

SNP correlation matrix

nrep

Number of Z-score systems to simulate

Value

Matrix of simulated posterior probabilties, one simulation per row

Examples

set.seed(1) nsnps <- 100 # derive joint Z score vector Zj <- rep(0, nsnps) iCV <- 4 # index of CV mu <- 5 # true effect at CV Zj[iCV] <- mu ## generate example LD matrix library(mvtnorm) nsamples = 1000 simx <- function(nsnps, nsamples, S, maf=0.1) { mu <- rep(0,nsnps) rawvars <- rmvnorm(n=nsamples, mean=mu, sigma=S) pvars <- pnorm(rawvars) x <- qbinom(1-pvars, 1, maf) } S <- (1 - (abs(outer(1:nsnps,1:nsnps,`-`))/nsnps))^4 X <- simx(nsnps,nsamples,S) LD <- cor2(X) res <- z_sim(Zj, Sigma = LD, nrep = 100) res[c(1:5), c(1:5)]
#> [,1] [,2] [,3] [,4] [,5] #> [1,] 3.718183 3.690915 3.591499 4.885386 3.868505 #> [2,] 5.557154 5.020218 5.803891 5.429848 4.264808 #> [3,] 3.498198 3.556396 4.206735 5.507531 4.739869 #> [4,] 5.811572 5.143549 5.750160 6.988442 5.427503 #> [5,] 2.554965 2.720556 2.625123 4.353644 2.902586