ljung_box_test: Run a Ljung-Box Test

View source: R/linreg-independence.R

ljung_box_testR Documentation

Run a Ljung-Box Test

Description

A wrapper around stats::Box.test() that standardizes the inputs and outputs.

Usage

ljung_box_test(object, ..., .alpha = 0.05)

## S3 method for class 'lm'
ljung_box_test(object, ..., .alpha = 0.05)

## S3 method for class ''_lm''
ljung_box_test(object, ..., .alpha = 0.05)

## S3 method for class ''_glm''
ljung_box_test(object, ..., .alpha = 0.05)

ljung_box_test_vec(x, ..., .alpha = 0.05)

Arguments

object

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

...

Further arguments passed to stats::Box.test().

.alpha

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

x

For ⁠_vec()⁠ functions, a numeric vector.

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: durbin_watson_test()

Examples

library(tidytest)

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

ljung_box_test(mod_lm_fit)

#> `linear_reg` Method
library(parsnip)

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

ljung_box_test(mod_linreg_fit)

#> Numeric Method
set.seed(1914)
resids <- rnorm(100)

ljung_box_test_vec(resids)

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