Here we simulate effect size from mixture gaussian.
cwd = path('/home/gaow/Documents/GTExV8/MNM')
import numpy as np
np.random.seed(10086)
P1 = (dict([('identity', np.identity(2)), ('single_1', np.array([[1,0],[0,0]])), ('single_2', np.array([[0,0], [0,1]])), ('all_in', np.ones((2,2)))]),
[0.5,1],
[0.9,0.01,0.01,0.01,0.01,0.01,0.01,0.02,0.02],
False
)
# independent effects
P2 = (dict([('identity', np.identity(2))]), [1], [1], False)
# correlated effects
P3 = (dict([('all', np.ones((2,2)) + np.identity(2) / 2)]), [1], [1], False)
S3 = np.ones((2,2))
dat = readRDS('/home/gaow/Documents/GTExV8/Thyroid.Lung.FMO2.filled.rds')
attach(dat)
%get X Y --from R
Y = Y.as_matrix()
from libgaow.regression_simulate import MMRegressionSimulator as SIM
data = SIM(X)
#data.get_xcorr('/home/gaow/Documents/GTExV8/FMO2.ld.npy')
data.set_xcorr(np.load('/home/gaow/Documents/GTExV8/FMO2.ld.npy'))
data.set_prior(*P3)
data.U = dict([(idx, data.U[key]) for idx, key in enumerate(data.U.keys())])
data.U
data.pi
data.generate_B(number_nonzero = 3)
# Separate effects into different LD blocks
indep_snps = data.select_independent_snps()
np.random.shuffle(indep_snps)
data.swap_B(indep_snps)
%expand
%preview {cwd}/sim1.b1.png
data.plot_B(data.B[:,0], '{cwd}/sim1.b1.png')
%expand
%preview {cwd}/sim1.b2.png
data.plot_B(data.B[:,1], '{cwd}/sim1.b2.png')
data.generate_Y(np.ones((2,2)))
import warnings
warnings.filterwarnings('error')
from libgaow.regression_data import MNMASH
model = MNMASH(X=data.X,Y=data.Y)
model.set_prior(*P3)
model.fit(niter=5)
%expand
%preview {cwd}/sim1.bpost1.png
data.plot_B(model.post_mean_mat[:,0], '{cwd}/sim1.bpost1.png')
%expand
%preview {cwd}/sim1.bpost2.png
data.plot_B(model.post_mean_mat[:,1], '{cwd}/sim1.bpost2.png')
varbvs
¶X = data.X
Y = data.Y
%get X Y --from python3
n <- nrow(X)
p <- ncol(X)
set.seed(1)
varbvs_fit1 <- varbvs::varbvs(X,NULL, Y[,1],verbose = FALSE)
varbvs_bhat1 = rowSums(varbvs_fit1$alpha*varbvs_fit1$mu)
varbvs_fit2 <- varbvs::varbvs(X,NULL, Y[,2],verbose = FALSE)
varbvs_bhat2 = rowSums(varbvs_fit2$alpha*varbvs_fit2$mu)
varbvs_bhat1 = as.vector(varbvs_bhat1)
varbvs_bhat2 = as.vector(varbvs_bhat2)
%get varbvs_bhat1 varbvs_bhat2 --from R
%expand
%preview {cwd}/sim1.varbvs1.png
data.plot_B(varbvs_bhat1, '{cwd}/sim1.varbvs1.png')
%expand
%preview {cwd}/sim1.varbvs2.png
data.plot_B(varbvs_bhat2, '{cwd}/sim1.varbvs2.png')