R/reg.dw.R

Defines functions reg.dw

Documented in reg.dw

###############################################################################################
##### DW Test
###############################################################################################

#' @name reg.dw
#' @aliases reg.dw
#' @title Durbin-Watson Test
#' @description Performs the Durbin-Watson Test for a regression model
#' @usage reg.dw(fit)
#' @param fit :a lm object
#' @examples fit <- lm(mpg~wt, mtcars, na.action = na.omit)
#' reg.dw(fit)


reg.dw <- function(fit){

  # hide warning message created by cv.lag()
  options(warn=-1)

  down <- sum(fit$residuals^2)
  up <- sum((fit$residuals - cv.lag(fit$residuals, 1))^2, na.rm = TRUE)

  return(up/down)

}

Try the PMmisc package in your browser

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

PMmisc documentation built on May 1, 2019, 9:57 p.m.