R/total.effect.master.R

Defines functions total.effect.master

Documented in total.effect.master

#' A master function for total effect estimation 
#' @param y A numeric vector
#' @param x A matrix for covariates
#' @param target A character for estimation target
#' @export
total.effect.master <- function(x, y, inter = FALSE, 
                                decorrelation.method = c("none", "historical", "glasso")[1], 
                                rho = NA,
                                thr = NA,
                                emp.sigma = NA, 
                                total.effect.method, 
                                total.effect.args.list){
  # 1. standardized the x 
  x <- std.fn(x)
  n <- nrow(x)
  p <- ncol(x)
  
  # 1.1 add inter terms
  if(inter == TRUE){
    x <- std.fn((add.inter(x)))
  }
  
  # 2 decorrelation 
  if(decorrelation.method == "historical"){
    if(!is.na(emp.sigma)){
      x <- empirical.cov.method(x = x, emp.sigma = emp.sigma)$uncorr.data  
    } else if(is.na(emp.sigma) & (n < p)){
      stop("decorrelation with an empirical covariance matrix requires use provide an emperical sigma or the x is n > p")
    } else if(is.na(emp.sigma) & (n >= p)){
      x <- empirical.cov.method(x = x)$uncorr.data  
    } 
  } else if (decorrelation.method == "glasso") {
    x <- GLASSO.method(x = x, rho = rho)$uncorr.data
  } else if (decorrelation.method == "none") {
    x <- x
  }
  
  # 3 total.effect calculation 
  args <- append(list(x = x, y = y), total.effect.args.list)
  total.effect.res <- do.call(total.effect.method, args)
  
  # 4 return the final result
  res <- list(total.effect.res = total.effect.res,
              decorrelation.method = decorrelation.method)
  res
}
wal615/prime.total.effect documentation built on April 29, 2020, 2:05 p.m.