###################################################################### ## AFC is an association test to test genetic associations ## ## between multiple phenotypes and a genetic variant. ## ## ## ## In the function AFC, ## ## x: represents the genotype (number of minor alleles) vector. ## ## y: represents the trait value matrix. Each row represents ## ## an individual and each column represents a phenotype. ## ## numper: represents the number of permutations to ## ## obtain the p-value of the test statistic AFC. ## ###################################################################### AFC=function(x,y,numper) { m=ncol(y) n=nrow(y) yvar=apply(y,2,var) Tstat=n*cov(y,x)/sqrt(n*yvar*var(x)) P0=1-pchisq(Tstat^2,1) pv=sort(P0) T0=-cumsum(log(pv)) Tper=matrix(NA,numper,m) for(l in 1:numper){ x.new=sample(x,size=n,replace=FALSE) Tstat=n*cov(y,x.new)/sqrt(n*yvar*var(x.new)) P0=1-pchisq(Tstat^2,1) pvper=sort(P0) Tper[l,]=-cumsum(log(pvper)) } TT=rbind(T0,Tper) T1=apply(TT,2,rank) T2=apply(T1,1,max) pvalue=sum(T2[-1]>T2[1])/numper+sum(T2[-1]==T2[1])/numper/2 return(pvalue) }