R/vif.censReg.R

Defines functions vif.censReg

Documented in vif.censReg

#' @title Variance Inflation Factors
#'
#' @description Extracts the variance inflation factors (Helsel and Hirsch, 2002)
#'from a censored regression object: method for "censReg" object.
#'
#' @param model an object of class "censReg"---output from \code{censReg}.
#' @param \dots not used, further arguments passed to or from other methods.
#' @return  A named numeric vector containing the variance inflation factor 
#'for each variable.
#' @seealso \code{\link{censReg}}
#' @references Helsel, D.R. and Hirsch, R.M., 2002, Statistical methods in 
#' water resources: U.S. Geological Survey Techniques of Water-Resources 
#' Investigations, book 4, chap. A3, 522 p.
#' @keywords regression
#' @importFrom smwrStats vif
#' @export
#' @method vif censReg
vif.censReg <- function(model, ...) {
  ## Coding history:
  ##    2012Dec31 DLLorenz Initial Coding
  ##
  lm.x <- model$XLCAL[, -1L, drop=FALSE] # drop the intercept
  if(ncol(lm.x) == 1L)
    VIFs <- 1
  else {
    if(is.null(model$weights))
      VIFs <- diag(solve(cor(lm.x)))
    else
      VIFs <- diag(solve(cov.wt(lm.x, wt=model$weights, cor=TRUE)$cor))
  }
  names(VIFs) <- colnames(lm.x)
  return(VIFs)
}
USGS-R/smwrQW documentation built on Oct. 11, 2022, 6:13 a.m.