#================== Sum of powered score (SPU) test # Y: disease lables; =0 for controls, =1 for cases; # X: genotype data; each row for a subject, and each column for an SNP; # the value of each element is the # of the copies for an allele; # Z: covariates (if any) # B: number of permutation #========================================================================= # Output is the p-values of the SPS test in the order of pow and aSPU #========================================================================= # The null distributino based on the parametric bootstrap aSPUboot <- function(Y, X, Z=NULL, pow=c(1:8, Inf), B=1000){ n <- length(Y) if (is.null(X) && length(X)>0) X=as.matrix(X, ncol=1) k <- ncol(X) if (is.null(Z)){ ## NO nuisance parameters: Xg <- X U<-t(Xg) %*% (Y-mean(Y)) } else { tdat1<-data.frame(trait=Y, Z) fit1<-glm(trait~.,family="binomial",data=tdat1) pis<-fitted.values(fit1) Us<-XUs<-matrix(0, nrow=n, ncol=k) Xmus = X for(i in 1:k){ tdat2<-data.frame(X1=X[,i], Z) fit2<-glm(X1~.,data=tdat2) Xmus[,i]<-fitted.values(fit2) XUs[, i]<-(X[,i] - Xmus[,i]) } U<-t(XUs) %*% (Y - pis) } ##observed statistics Ts=rep(NA,length(pow)) for (j in 1:length(pow)){ if (pow[j]P0s)]=P0s[which(minp0>P0s)] # cat("j=",j,"\n") } cat("P0s caculated","\n") Paspu<-(sum(minp0<=min(pPerm0))+1)/(B+1) pvs <- c(pPerm0, Paspu) return( pvs) }