####generate simulated data: nSNP noise markers's latent Normal var #### with AR1(rho1) , nSNP0 causal ones with latent Normal var with #### AR1(rho0); the causal and noise SNPs are independent; #### n cases and n ctls; #### OR is the common OR for all causal SNPs; #### MAFlow=0.1, MAFup=0.4: common lower and upper bounds for all SNPs. #### WP, 6/8/11 simSNPs<-function(nSNP1=36, nSNP0=4, OR=1, n=200, rho1=0.8, rho0=0.8, MAFlow=0.1, MAFup=0.4){ q=nSNP=nSNP1+nSNP0 R<-matrix(0, nrow=q, ncol=q) for(i in 1:nSNP0) for(j in 1:nSNP0) R[i, j]<-rho^(abs(i-j)) for(i in (nSNP0+1):nSNP) for(j in (nSNP0+1):nSNP) R[i, j]<-rho^(abs(i-j)) svd.R<-svd(R) R1<-svd.R$u %*% diag(sqrt(svd.R$d)) #R2<- diag(sqrt(svd.R$d)) %*% t(svd.R$v) #Note above: R1 %*% t(R1)= R #R1<-svd.R$u %*% diag(1/sqrt(svd.R$d)) ##Note above: R1 %*% t(R1) = Inv(R) #R2<- diag(1/sqrt(svd.R$d)) %*% t(svd.R$v) ##background disease prev = 0.2 RR<-log(OR); b0<-log(0.2/0.8) MAFs<-runif(q, MAFlow, MAFup) cutoff<-qnorm(MAFs) #######first nSNP0 are causal ones: bs<-rep(0, q) loc0s<-(1:nSNP0) bs[loc0s]<-RR X<-matrix(0, nrow=n+n, ncol=q) Y<-rep(0, n+n); Y[(n+1):(2*n)]<-1 i<-1 #sampling controls: while ( i <= n){ X0<-rnorm(q, 0, 1) #: X0 ~ MVN(0, I) X1<-R1 %*% X0 #: X1 ~ MVN(0, R) X2<-ifelse(X1