This is continuation of notebook two_snps_dispute.ipynb
.
Here I:
Y
I'd expect to see almost identical result indicating my implementation are correct.
%cd /home/gaow/tmp/13-May-2019
genotype = readRDS('Multi_Tissues.ENSG00000145214.RDS')$X
ld = cor(genotype)
idx = which(ld > -0.855 & ld < -0.85, arr.ind = T)
head(idx)
So let's check out 184 and 354:
cor(genotype[,184], genotype[,354])
colnames(genotype)[184]
colnames(genotype)[354]
P = ncol(genotype)
R = 6
eff_factor = 1.5
set.seed(1)
b = matrix(0, P, R)
sharing = matrix(0.75, 3, 3)
diag(sharing) = 1
b[184, 1:3] = abs(MASS::mvrnorm(1, rep(0,3), sharing)) / eff_factor
b[354, 4:6] = -abs(MASS::mvrnorm(1, rep(0,3), sharing)) / eff_factor
print(b[184, 1:3])
print(b[354, 4:6])
g = genotype %*% b
apply(g,2,sd) * eff_factor
e = MASS::mvrnorm(nrow(g), rep(0,R), diag(R) * 1)
Y = g + e
U1 = matrix(0,R,R)
U1[1:3,1:3] = sharing
U2 = matrix(0,R,R)
U2[4:6,4:6] = sharing
Ulist = list(U1=U1, U2=U2)
scaling = c(0.5,1) / eff_factor
mash_init = mvsusieR:::MashInitializer$new(Ulist, scaling, alpha = 1)
Notice here I'm using the EZ model by setting alpha = 1
.
With / without precomputed inverse matrices we compare the running time on this $R=6$ example,
start_time <- Sys.time()
res = mvsusieR::mvsusie(genotype,Y,
L=10,prior_variance=mash_init,
precompute_covariances=FALSE,
compute_objective=FALSE)
end_time <- Sys.time()
print(end_time - start_time)
start_time <- Sys.time()
res = mvsusieR::mvsusie(genotype,Y,
L=10,prior_variance=mash_init,
precompute_covariances=TRUE,
compute_objective=FALSE)
end_time <- Sys.time()
print(end_time - start_time)
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
Above looks all good. Notice here I'm using the precompute covariances routine.
For each Y
I want 5% data missing,
Y2 = Y
for (i in 1:ncol(Y)) {
Y2[sample(1:nrow(Y), ceiling(nrow(Y) * 0.05)), i] = NA
}
And run the procedure again,
res = mvsusieR::mvsusie(genotype,Y2,
L=10,prior_variance=mash_init,
compute_objective=FALSE)
snps = sub("_[A-Z]*_[A-Z]*_b38", "", colnames(genotype))
rownames(res$coef) = c('intercept', snps)
pdf('susie_plot_toy_missing.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_missing.pdf', width = 8, height = 4)
print(p$plot)
dev.off()
%preview susie_plot_toy_missing.pdf -s png --dpi 150
%preview mvsusie_plot_toy_missing.pdf -s png --dpi 150