durbin_watson_test: Run a Durbin-Watston Test

View source: R/linreg-independence.R

durbin_watson_testR Documentation

Run a Durbin-Watston Test

Description

A wrapper around lmtest::dwtest() that standardizes the inputs and outputs.

Usage

durbin_watson_test(object, alternative = "two.sided", ..., .alpha = 0.05)

## S3 method for class 'lm'
durbin_watson_test(object, alternative = "two.sided", ..., .alpha = 0.05)

## S3 method for class ''_lm''
durbin_watson_test(object, alternative = "two.sided", ..., .alpha = 0.05)

## S3 method for class ''_glm''
durbin_watson_test(object, alternative = "two.sided", ..., .alpha = 0.05)

Arguments

object

A model object (such as a fitted lm object).

alternative

Passed to the alternative argument of lmtest::dwtest() (one of "two.sided", "greater", or "less". Default is "two.sided").

...

Further arguments passed to lmtest::dwtest().

.alpha

(Optional) Critical p-value used to determine test conclusion. The default is 0.05 (5%).

Details

The hypotheses for this test are:

  • Null: No Autocorrelation

  • Alternative: Autocorrelation

Value

A tibble with columns test, statistic, p_value, result, outcome, and .notes with extra information.

See Also

Other independence tests: ljung_box_test()

Examples

library(tidytest)

#> `lm` Method
mod_lm_fit <- lm(mpg ~ disp + wt + hp, data = mtcars)

durbin_watson_test(mod_lm_fit)

#> `linear_reg` Method
library(parsnip)

mod_linreg_fit <- linear_reg() %>%
  set_engine("lm") %>%
  fit(mpg ~ disp + wt + hp, data = mtcars)

durbin_watson_test(mod_linreg_fit)

RobbyLankford/tidytest documentation built on Jan. 27, 2024, 7:36 a.m.