R/PCFisher.R

Defines functions PCFisher

Documented in PCFisher

#' @title To conduct PCFisher test
#' @param Z_score GWAS summary statistics
#' @param Sigma the correlation matrix
#' @return PC.Fisher.p
#' @importFrom stats pchisq
#' @export
#'
#'
PCFisher <- function(Z_score,Sigma){
    eigen.res = eigen(Sigma)
    lambdas = eigen.res$values
    eigen.vec = eigen.res$vectors

    z.tmp = as.matrix(Z_score)
    K = length(z.tmp)
    PC.vec = t(eigen.vec)%*%z.tmp
    PC.std = (PC.vec)^2/lambdas
    PC.p = pchisq(PC.std,df=1,lower.tail=FALSE)
    PC.Fisher.stat = -2*sum(log(PC.p))
    PC.Fisher.p = pchisq(PC.Fisher.stat,df=2*K,lower.tail = FALSE)
    return(PC.Fisher.p)
  }
Vivian-Liu-Wei64/EBMMT documentation built on Dec. 18, 2021, 6:20 p.m.