I discovered while working on the example of "two SNP dispute" that for Exchangable Effect (EE) model, that is, setting MASH alpha=0
,
there seems convergence issues with the algorithm, for the specific simulation below. I cannot reproduce the problem with alpha=1
or with the 2nd block having positive sign of effect size ...
%cd /home/gaow/tmp/13-May-2019
genotype = readRDS('Multi_Tissues.ENSG00000145214.RDS')$X
P = ncol(genotype)
R = 6
eff_factor = 1.5
snp1 = 184
snp2 = 354
cor(genotype[,snp1], genotype[,snp2])
The two SNPs are negatively correlated.
set.seed(1)
b = matrix(0, P, R)
sharing = matrix(0.75, (R/2), (R/2))
diag(sharing) = 1
print(sharing)
Here above I have a matrix block. I'm going to create a blocky structure next such that the two halves of traits are drawn from this sharing pattern, but there is no sharing in between them.
Notice here I set the effect size of the 2nd block to be negative.
b[snp1, 1:(R/2)] = abs(MASS::mvrnorm(1, rep(0,(R/2)), sharing)) / eff_factor
b[snp2, (R/2+1):R] = -abs(MASS::mvrnorm(1, rep(0,(R/2)), sharing)) / eff_factor
print(b[snp1, 1:(R/2)])
print(b[snp2, (R/2+1):R])
g = genotype %*% b
e = MASS::mvrnorm(1, rep(0,R), diag(R) * 1)
Y = g + e
U1 = matrix(0,R,R)
U1[1:(R/2),1:(R/2)] = sharing
U2 = matrix(0,R,R)
U2[(R/2+1):R,(R/2+1):R] = sharing
Ulist = list(U1=U1, U2=U2)
scaling = c(0.5,1) / eff_factor
mash_init = mvsusieR:::MashInitializer$new(Ulist, scaling, alpha = 0)
Notice here I'm using the EE model by setting alpha = 0
.
Using EE model it takes quite a while to converge,
start_time <- Sys.time()
res = mvsusieR::susie(genotype,Y,
L=10,V=mash_init,
precompute_covariances=FALSE,
compute_objective=FALSE)
end_time <- Sys.time()
print(end_time - start_time)
Number of iterations,
res$niter
snps = sub("_[A-Z]*_[A-Z]*_b38", "", colnames(genotype))
rownames(res$coef) = c('intercept', snps)
pdf('susie_plot_toy.pdf', width=8, height=4)
susieR::susie_plot(res,y='PIP', main = 'Cross-condition Posterior Inclusion Probability', xlab = 'SNP positions', add_legend = F)
dev.off()
p = mvsusieR::mvsusie_plot(res)
pdf('mvsusie_plot_toy.pdf', width = 8, height = 4)
print(p$plot)
dev.off()
%preview susie_plot_toy.pdf -s png --dpi 150
%preview mvsusie_plot_toy.pdf -s png --dpi 150
While it seems capable (see below) of capturing the two simulated causal SNPs, there are a few more others also detected and show different signs of effect in different conditions. This is not a problem with EZ model, though.
colnames(genotype)[snp1]
colnames(genotype)[snp2]
Since I have simulated the data I can try initializat it from the truth,
coef_value = b[which(apply(b,1,sum)!=0),]
coef_value
That is, two effects are non-zero and all other effects are zeros.
start_time <- Sys.time()
res = mvsusieR::susie(genotype,Y,
L=10,V=mash_init,
s_init = list(coef_value = coef_value, coef_index = c(snp1, snp2)),
precompute_covariances=FALSE,
compute_objective=FALSE)
end_time <- Sys.time()
print(end_time - start_time)
res$niter
snps = sub("_[A-Z]*_[A-Z]*_b38", "", colnames(genotype))
rownames(res$coef) = c('intercept', snps)
pdf('susie_plot_toy.pdf', width=8, height=4)
susieR::susie_plot(res,y='PIP', main = 'Cross-condition Posterior Inclusion Probability', xlab = 'SNP positions', add_legend = F)
dev.off()
%preview susie_plot_toy.pdf -s png --dpi 150