z_sim: Simulate marginal Z-scores from joint Z-score vector

Description Usage Arguments Value Author(s) Examples

View source: R/z_simulation_functions.R

Description

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

Usage

1
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

Author(s)

Anna Hutchinson

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
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)]

corrcoverage documentation built on Dec. 7, 2019, 1:07 a.m.