R/F_estP0.R

Defines functions estP0

Documented in estP0

#'Estimate the fraction of true null hypotheses.
#'
#' @param statObs A vector of observed z-values
#' @param fitAll the estimated normal null
#' @param z0quantRange a number of quantiles between 0 and 0.5
#' @param smooth.df degrees of freedom for the spline smoother
#'
#' @return The estimated null fraction, the value of the spline evaluated
#'  at the first element of z0quantRange
#'
#' @details A natural spline is used over a range of intervals.
#' Based on the qvalue::qvalue() function and
#'Storey and Tibshirani, 2003
#'
#'@importFrom stats smooth.spline predict
estP0 = function(statObs, fitAll, z0quantRange, smooth.df){
    pi0 = vapply(z0quantRange, FUN.VALUE = double(1), function(z0Quant) {
    z0Quant = c(z0Quant, 1-z0Quant)
    centralBorders = qnorm(z0Quant, mean = fitAll["mean"], sd = fitAll["sd"])
    mean(statObs <= centralBorders[2] &
        statObs >= centralBorders[1])/diff(z0Quant)
    })
    smoothPi0 = smooth.spline(z0quantRange, pi0, df = smooth.df)
    pi0Smooth = predict(smoothPi0, x = z0quantRange[1])$y #Conservative
    min(pi0Smooth, 1)
}

Try the reconsi package in your browser

Any scripts or data that you put into this service are public.

reconsi documentation built on Nov. 8, 2020, 5:04 p.m.