library(boot) library(MASS) library(base) library(stats) corr=function(y,x) { a=var(y)*var(x) if(a==0) co=0 else co=cov(y,x)/sqrt(a) co } ################################################################## ## AW1 is an association test to test association ## ## between a phenotype and a group of variants (can ## ## be rare and common) in a genomic region by using an ## ## adaptive weighting method. AW1 is designed for the ## ## case of no or small proportion of protective variants. ## ## y represents trait values(a vector). x represents ## ## genotype (number of minor allele) matrix. Each row ## ## represents an individual and each column represents ## ## a SNP. ## ################################################################## AW1=function(y,x,numper) { n=length(y) Tper=rep(0,numper) if(n==length(x)) { T=corr(y,x) T=T*(T>0) for (i in 1:numper) { yper=sample(y) Tper[i]=corr(yper,x) Tper[i]=Tper[i]*(Tper[i]>0) } } ################################ else { m=ncol(x) q=(colSums(x)+1)/(n*2+2) w=1/sqrt(q*(1-q)) ww=cor(y,x) w1=as.numeric(w*ww*(ww>0)) x1=t(w1*t(x)) x1=rowSums(x1) T=corr(y,x1) for(i in 1:numper) { yper=sample(y) ww=cor(yper,x) w1=as.numeric(w*ww*(ww>0)) x1=t(w1*t(x)) x1=rowSums(x1) Tper[i]=corr(yper,x1) } } pvalue=sum(Tper>T)/numper } ################################################################## ## AW2 is an association test to test association ## ## between a phenotype and a group of variants (can ## ## be rare and common) in a genomic region by using an ## ## adaptive weighting method. AW2 is designed for the ## ## case when both risk and protective variants are ## ## presented. ## ## y represents trait values(a vector). x represents ## ## genotype (number of minor allele) matrix. Each row ## ## represents an individual and each column represents ## ## a SNP. ## ################################################################## AW2=function(y,x,numper) { n=length(y) Tper=rep(0,numper) if(n==length(x)) { T=corr(y,x) T=T^2 for (i in 1:numper) { yper=sample(y) Tper[i]=corr(yper,x) Tper[i]=Tper[i]^2 } } ################################ else { m=ncol(x) q=(colSums(x)+1)/(n*2+2) w=1/sqrt(q*(1-q)) ww=cor(y,x) w1=as.numeric(w*ww) x1=t(w1*t(x)) x1=rowSums(x1) T=corr(y,x1) for(i in 1:numper) { yper=sample(y) ww=cor(yper,x) w1=as.numeric(w*ww) x1=t(w1*t(x)) x1=rowSums(x1) Tper[i]=corr(yper,x1) } } pvalue=sum(Tper>T)/numper }