kpss_test: Run a Kwiatkowski-Phillips-Schmidt-Shin (KPSS) Test

View source: R/tseries-stationarity.R

kpss_testR Documentation

Run a Kwiatkowski-Phillips-Schmidt-Shin (KPSS) Test

Description

The hypotheses for this test are:

A wrapper around tseries::kpss.test() that standardizes the inputs and outputs.

Usage

kpss_test(object, null = "Level", ..., .alpha = 0.05)

## S3 method for class 'lm'
kpss_test(object, null = "Level", ..., .alpha = 0.05)

## S3 method for class ''_lm''
kpss_test(object, null = "Level", ..., .alpha = 0.05)

kpss_test_vec(x, null = "Level", ..., .alpha = 0.05)

Arguments

object

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

null

(Optional) The null hypothesis, either "Level" (default) or "Trend".

...

Further arguments passed to tseries::kpss.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

  • Null: Series is either Level or Trend stationary (user defined)

  • Alternative: Series has a unit root

Value

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

See Also

Other stationarity tests: aug_dickey_fuller_test(), phillips_perron_test()

Examples

library(tidytest)

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

kpss_test(mod_lm_fit)
kpss_test(mod_lm_fit, null = "Trend")


#> `linear_reg` Method
library(parsnip)

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

kpss_test(mod_linreg_fit)
kpss_test(mod_linreg_fit, null = "Trend")


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

kpss_test_vec(resids)
kpss_test_vec(resids, null = "Trend")


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