R/adaptive_knockoff.R

Defines functions adaptive_knockoff

Documented in adaptive_knockoff

#' Adaptive knockoff
#'
#' This function takes W as an input and outpus the selection set generated by the adaptive knockoff procedure
#'
#' @param W a p-dimensional vector of the feature importance statistics.
#' @param U p-by-r vector of the side information.
#' @param fdr The target FDR level(s). The default is 0.1.
#' @param offset 0 or 1 (default: 1).
#' @param method The method used for evaluating the probability of being null. The default is random forest.
#'
#' @export



adaptive_knockoff <- function(W, U, fdr = 0.1, offset= 1, 
                              method = filter_gam,
                              reveal_prop = 0.1, mute = TRUE){

  #Loading necessary packages
  packages <- c("gam","glmnet","randomForest","doMC")
  lapply(packages, require, character.only = TRUE)

  #Check input format
  if(is.numeric(W)){
    W <- as.vector(W)
    p <- length(W)
  }else{
    stop('W is not a numeric vector.')
  }

  if(is.numeric(U)){
      stop("U is not a numeric matrix.")
  }else{
    U <- as.matrix(U)
  }

  if(dim(U)[1] != p){
    if(dim(U)[2] == p){
      U = t(U)
    }else{
      stop("Please check the dimesion of U.")
    }
  }

 #Run the adaptive knockoff with the specified filter
 res = method(W, U, alpha = fdr, offset = offset, 
              reveal_prop = reveal_prop, mute = mute)
 return(res)
}
zhimeir/adaptiveKnockoffs documentation built on Oct. 6, 2021, 9:41 p.m.