R/checkX.R

Defines functions checkX_VIF checkX_cor

#' @importFrom stats cor
#' @keywords internal
checkX_cor <- function(X){
  suppressWarnings(corX <- cor(X))
  diag(corX) <- NA
  corX
}

#' @importFrom car vif
#' @importFrom stats lm rnorm
#' @keywords internal
checkX_VIF <- function(X){
  nT <- nrow(X)
  nK <- ncol(X)
  
  y <- rnorm(nT) #add fake y variable, has no influence
  Xnames <- paste0("X", seq(nK))
  df <- as.data.frame(cbind(X, y)); names(df) <- c(Xnames,"y")
  f <- as.formula(paste0('y ~ ',paste(Xnames, collapse = " + ")))
  suppressWarnings(try(car::vif(try(lm(f, data = df)))))
}

Try the hrf package in your browser

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

hrf documentation built on April 3, 2025, 10:36 p.m.