R/calculate_lambda.R

Defines functions calculate_lambda

Documented in calculate_lambda

#' Calculate lambda
#'
#' Calculate the genomic inflation factor from a vector of p-values
#'
#' @param stat A vector of p-values
#' @param df Degrees of freedom
#'
#' @export

calculate_lambda <- function(stat, df) {
    if (any(sum(stat < 0, na.rm=TRUE)))
        stop("No negative values allowed in stat (does beta/se need to be squared?)")
    stats::median(stat, na.rm = TRUE) / stats::qchisq(0.5, df = df)
}
Blue-Lab/blPipeline documentation built on May 12, 2022, 5:10 a.m.