R/abf.R

Defines functions abf

##' Calculate approximate Bayes factors from p values and MAF
##'
##' this is a function to calculate approximate Bayes factors from p
##' values and MAF - for reference see Wakefield, J (2009) Bayes
##' factors for genome-wide association studies: comparison with
##' p-values. Genetic Epidemiology 33: 79–86.
##' @title abf
##' @param p p value
##' @param maf minor allele frequency
##' @param n0 number of controls
##' @param n1 number of cases
##' @param scale0 by default, =n0
##' @param scale1 by default, =n1
##' @return ABF
##' @export
##' @author Chris Wallace
abf <- function(p,maf, n0=9500, n1=6670, scale0=n0, scale1=n1) { # evidence for null - ie low ABF => support for alternative
z <- qnorm(p/2, lower.tail=FALSE)
x0 <- 0; x1 <- 1; x2 <- 2 # multiplicative model
d2 <- (1-maf)^2 * x0^2 + 2*maf*(1-maf)*x1 + maf^2 * x2^2
d1 <- (1-maf)^2 * x0 + 2*maf*(1-maf)*x1 + maf^2 * x2
V <- (n0 + n1) / ( n0 * n1 * (d2-d1) )
## scale
scale <- ((n0 + n1)/(scale0 + scale1)) * (scale0/n0) * (scale1/n1)
V <- V * scale
W <- ( log(1.5)/qnorm( 0.99, lower.tail=FALSE) )^2
VW <- V+W
2 * log(sqrt(VW/V) * exp( - z^2 * W / (2 * VW) ))
}
chr1swallace/random-functions documentation built on March 6, 2021, 10:56 a.m.