fit.med.zqtl.Rd
Variational inference of zQTL mediation
fit.med.zqtl(effect, effect.se, effect.m, effect.m.se, X.gwas)
Marginal effect size matrix (SNP x trait)
Marginal effect size standard error matrix (SNP x trait)
Marignal genetic effects of mediators (SNP x mediator)
SE of the marginal genetic effects (SNP x mediator)
Design matrix (reference Ind.GWAS x SNP)
Design matrix (reference Ind.MED x SNP)
sample size of GWAS data (will ignore if n = 0)
sample size of mediation data (will ignore if n.med = 0)
SNP confounding factors (SNP x confounder; default: NULL)#'
Fit factored model (default: FALSE)
A list of inference/optimization options.
Multivariate mediator QTL effect (default: FALSE)
Estimate direct effect by joint factorization (default: TRUE)
Factorization model; 0 = ind x factor, 1 = eigen x factor (default: 0)
Size of stratified sampling (default: 2)
Estimate direct effect (default: TRUE)
Fine-map direct effect SNPs (default: FALSE)
Number of bootstraps followed by finemapping (default: 0)
Number of bootstraps for variance estimation (default: 100)
Scaled variance calculation (default: FALSE)
variance calculation (default: FALSE)
Duplicate number of independent components (default: 1)
number of conditional models
size of each conditional model
Hyper parameter tuning (default: FALSE)
Rescale z-scores by standard deviation (default: FALSE)
Fixed value of tau
Fixed value of pi
Lower-bound of tau (default: -10)
Upper-bound of tau (default: -4)
Lower-bound of pi (default: -4)
Upper-bound of pi (default: -1)
Convergence criterion (default: 1e-4)
Maximum precision (default: 1000)
Update rate (default: 1e-2)
Update rate decay (default: 0)
SD of random jitter for mediation & factorization (default: 0.01)
Number of stochastic samples (default: 10)
Number of variational Bayes iterations (default: 2000)
Verbosity (default: TRUE)
Rank of the factored model (default: 1)
initialize by SVD (default: TRUE)
Printing interval (default: 10)
Number of threads during calculation (default: 1)
Error tolerance in Eigen decomposition (default: 0.01)
Regularization of Eigen decomposition (default: 0.0)
Standardize (default: TRUE)
estimate residual z-scores (default: FALSE)
Minimum level of SE (default: 1e-4)
Random seed
a list of variational inference results.
param.mediated: parameters for the mediated effects
param.unmediated: parameters for the unmediated effects
param.intercept: parameters for the intercept effect
param.covariate: parameters for the multivariate covariate
param.covariate.uni: parameters for the univariate covariate
bootstrap: bootstrapped mediated parameters (if nboot > 0)
llik: log-likelihood trace over the optimization
Mediation analysis
library(dplyr)
#>
#> Attaching package: ‘dplyr’
#> The following objects are masked from ‘package:stats’:
#>
#> filter, lag
#> The following objects are masked from ‘package:base’:
#>
#> intersect, setdiff, setequal, union
n = 500
p = 1000
n.genes = 10
h2 = 0.8
n.causal.direct = 1
n.causal.qtl = 3
n.causal.gene = 2
set.seed(13)
.rnorm <- function(a, b) matrix(rnorm(a * b), a, b)
X.raw = sapply(1:p, function(j) {
f = runif(1, min = 0.1, max = 0.9)
rbinom(n, 2, f)
})
X = scale(X.raw)
c.qtls = matrix(sapply(1:n.genes, function(j) matrix(sample(p, n.causal.qtl))), nrow = n.causal.qtl)
theta.snp.gene = .rnorm(n.causal.qtl, n.genes) / n.causal.qtl
gene.expr = lapply(1:dim(c.qtls)[2], function(j) X[, c.qtls[,j], drop = FALSE] %*% theta.snp.gene[, j, drop = FALSE] + 0.5 * rnorm(n) )
gene.expr = do.call(cbind, gene.expr)
theta.med = sample(c(-1,1), n.causal.gene, TRUE)
causal.direct = sample(p, n.causal.direct)
theta.dir = matrix(rnorm(n.causal.direct), n.causal.direct, 1) / n.causal.direct
y = gene.expr[,1:n.causal.gene,drop = FALSE] %*% theta.med # mediation
y = y + X[, causal.direct, drop = FALSE] %*% theta.dir # direct
y = y + rnorm(n) * c(sqrt(var(y) * (1/h2 - 1)))
eqtl.tab = calc.qtl.stat(X, gene.expr)
gwas.tab = calc.qtl.stat(X, y)
xg.beta = eqtl.tab %>%
dplyr::select(x.col, y.col, beta) %>%
tidyr::spread(key = y.col, value = beta) %>%
(function(x) as.matrix(x[1:p, -1]))
xg.se = eqtl.tab %>%
dplyr::select(x.col, y.col, se) %>%
tidyr::spread(key = y.col, value = se) %>%
(function(x) as.matrix(x[1:p, -1]))
xy.beta = gwas.tab %>%
dplyr::select(x.col, y.col, beta) %>%
tidyr::spread(key = y.col, value = beta) %>%
(function(x) as.matrix(x[1:p, -1]))
xy.se = gwas.tab %>%
dplyr::select(x.col, y.col, se) %>%
tidyr::spread(key = y.col, value = se) %>%
(function(x) as.matrix(x[1:p, -1]))
vb.opt = list(nsample = 10,
vbiter = 3000,
rate = 1e-2,
gammax = 1e3,
do.stdize = TRUE,
pi = -0, tau = -4,
do.hyper = FALSE,
eigen.tol = 1e-2,
tol = 1e-8,
verbose = TRUE,
print.interv = 200,
multivar.mediator = FALSE,
nthread = 8)
med.out = fit.med.zqtl(effect = xy.beta,
effect.se = xy.se,
effect.m = xg.beta,
effect.m.se = xg.se,
X.gwas = X,
options = vb.opt)
barplot(height = med.out$param.mediated$lodds[, 1],
names.arg = paste('g',1:n.genes),
horiz = TRUE, xlab = 'log-odds', ylab = 'mediators')