# generate data h2 = 0.3 N = 500; P = 3; S = 1000 X = 1.*(SP.rand(N,S)<0.2) beta = SP.randn(S,P) Yg = SP.dot(X,beta); Yg*=SP.sqrt(h2/Yg.var(0).mean()) Yn = SP.randn(N,P); Yn*=SP.sqrt((1-h2)/Yn.var(0).mean()) Y = Yg+Yn; Y-=Y.mean(0); Y/=Y.std(0) XX = SP.dot(X,X.T) XX/= XX.diagonal().mean() Xr = 1.*(SP.rand(N,10)<0.2) Xr*= SP.sqrt(N/(Xr**2).sum()) # define mean term mu = mean(Y) # add first fixed effect F = 1.*(SP.rand(N,2)<0.2); A = SP.eye(P) # add second fixed effect F2 = 1.*(SP.rand(N,3)<0.2); A2 = SP.ones((1,P)) mu.addFixedEffect(F=F,A=A) mu.addFixedEffect(F=F2,A=A2) if mtSet_present: mu1 = MEAN.mean(Y) mu1.addFixedEffect(F=F,A=A) mu1.addFixedEffect(F=F2,A=A2)
# generate data h2 = 0.3 N = 1000; P = 4; S = 1000 X = 1.*(SP.rand(N,S)<0.2) beta = SP.randn(S,P) Yg = SP.dot(X,beta); Yg*=SP.sqrt(h2/Yg.var(0).mean()) Yn = SP.randn(N,P); Yn*=SP.sqrt((1-h2)/Yn.var(0).mean()) Y = Yg+Yn; Y-=Y.mean(0); Y/=Y.std(0) XX = SP.dot(X,X.T) XX/= XX.diagonal().mean() Xr = 1.*(SP.rand(N,10)<0.2) Xr*= SP.sqrt(N/(Xr**2).sum()) # define mean term mean = mean(Y) print mean.Y # add first fixed effect F = 1.*(SP.rand(N,2)<0.2); A = SP.eye(P) mean.addFixedEffect(F=F,A=A) # add first fixed effect F = 1.*(SP.rand(N,3)<0.2); A = SP.ones((1,P)) mean.addFixedEffect(F=F,A=A) # rotate stuff by row and cols C = SP.cov(Y.T) Sc,Uc = LA.eigh(C) Sr,Ur = LA.eigh(XX) d = SP.kron(Sc,Sr) mean.d = d
P = 2 S = 1000 R = 1000 maf = 0.2 h2_S = 0.3 h2_R = 0.2 snps, X, Y = generate_data(N=N, S=S, R=R, P=P, h2_S=h2_S, h2_R=h2_R, maf=maf) # define mean term mu = mean(Y) # add any fixed effect including bias term F = 1. * (SP.rand(N, 3) < 0.2) A = SP.eye(P) F[:, 0] = 1.0 mu.addFixedEffect(F=F, A=A) # add common fixed effect F2 = 1. * (SP.rand(N, 4) < 0.2) A2 = SP.ones((1, P)) mu.addFixedEffect(F=F2, A=A2) # define covariance matrices Cg = freeform(P) Cn = freeform(P)
X = 1. * (SP.rand(N, S) < 0.2) beta = SP.randn(S, P) Yg = SP.dot(X, beta) Yg *= SP.sqrt(h2 / Yg.var(0).mean()) Yn = SP.randn(N, P) Yn *= SP.sqrt((1 - h2) / Yn.var(0).mean()) Y = Yg + Yn Y -= Y.mean(0) Y /= Y.std(0) XX = SP.dot(X, X.T) XX /= XX.diagonal().mean() Xr = 1. * (SP.rand(N, 10) < 0.2) Xr *= SP.sqrt(N / (Xr**2).sum()) # define mean term mean = mean(Y) print((mean.Y)) # add first fixed effect F = 1. * (SP.rand(N, 2) < 0.2) A = SP.eye(P) mean.addFixedEffect(F=F, A=A) # add first fixed effect F = 1. * (SP.rand(N, 3) < 0.2) A = SP.ones((1, P)) mean.addFixedEffect(F=F, A=A) # rotate stuff by row and cols C = SP.cov(Y.T) Sc, Uc = LA.eigh(C) Sr, Ur = LA.eigh(XX)
Yg = SP.dot(X, beta) Yg += SP.dot(snps, beta_snp) Yg *= SP.sqrt(h2 / Yg.var(0).mean()) Yn = SP.randn(N, P) Yn *= SP.sqrt((1 - h2)) Y = Yg + Yn Y -= Y.mean(0) Y /= Y.std(0) XX = SP.dot(X, X.T) XX /= XX.diagonal().mean() Xr = 1. * (SP.rand(N, 10) < 0.2) Xr *= SP.sqrt(N / (Xr**2).sum()) # define mean term mu = mean(Y) # add first fixed effect F = 1. * (SP.rand(N, 3) < 0.2) A = SP.eye(P) F[:, 0] = 1.0 # add second fixed effect F2 = 1. * (SP.rand(N, 4) < 0.2) A2 = SP.ones((1, P)) mu.addFixedEffect(F=F, A=A) mu.addFixedEffect(F=F2, A=A2) # define covariance matrices Cg = freeform(P)
beta_snp = SP.randn(S,P)*10000 #beta_snp[(SP.rand(beta_snp.shape[0],beta_snp.shape[1])<0.1)]=0.0 Yg = SP.dot(X,beta); Yg += SP.dot(snps,beta_snp); Yg*=SP.sqrt(h2/Yg.var(0).mean()) Yn = SP.randn(N,P); Yn*=SP.sqrt((1-h2)) Y = Yg+Yn; Y-=Y.mean(0); Y/=Y.std(0) XX = SP.dot(X,X.T) XX/= XX.diagonal().mean() Xr = 1.*(SP.rand(N,10)<0.2) Xr*= SP.sqrt(N/(Xr**2).sum()) # define mean term mu = mean(Y) # add first fixed effect F = 1.*(SP.rand(N,3)<0.2); A = SP.eye(P) F[:,0]=1.0 # add second fixed effect F2 = 1.*(SP.rand(N,4)<0.2); A2 = SP.ones((1,P)) mu.addFixedEffect(F=F,A=A) mu.addFixedEffect(F=F2,A=A2) # define covariance matrices Cg = freeform(P) Cn = freeform(P)