R/EstimateAUC.QP.R

Defines functions EstimateAUC.QP

Documented in EstimateAUC.QP

#' Compute QP estimate for AUC
#' Basic function to obtain the quadratic programming deconvolution estimator of AUC,
#' from the supplied data and the measurement error standard deviations.
#'
#' @param diseased vector of positive class observations
#' @param healthy vector of negative class observations
#' @param MESD_X positive class measurement error standard deviation
#' @param MESD_Y negative class measurement error standard deviation in Y
#' @param K hyperparameter of 'QPdecon', defaults to automatic choice as in QPdecon
#' @export
#' @return AUC estimate
#' @examples
#' x <- rnorm(150,2,1) + rnorm(150,0,0.5) #positive class obs.
#' y <- rnorm(180,0,1) + rnorm(180,0,0.3) #negative class obs.
#' EstimateAUC.QP(diseased=x,healthy=y,MESD_X=0.5,MESD_Y=0.3)
EstimateAUC.QP <- function(diseased, healthy, MESD_X , MESD_Y, K = NULL){

  Y_decon_cdf <- QPdecon::QPdecon(healthy,f_Z = MESD_Y, Pdf = FALSE) # F_Y
  X_decon_pdf <- QPdecon::QPdecon(diseased,f_Z = MESD_X) # f_X

  x <- X_decon_pdf$x
  fx <- X_decon_pdf$f_X
  delta <- mean(diff(x)) #the values vary very slightly so we just take the mean


  SUM_FYx <- Decon2CDF(qpobj = Y_decon_cdf,quant = x)
  A.hat <- sum(fx * SUM_FYx*delta)
  return(A.hat)

}
blebedenko/thescript2 documentation built on Dec. 19, 2021, 9:53 a.m.