KPSS Test in R With Examples

KPSS Test in R, the KPSS test (Kwiatkowski-Phillips-Schmidt-Shin) is a statistical test used to determine whether a time series has a unit root or not.

A unit root indicates that the time series is non-stationary, meaning that the mean and/or the variance of the series changes over time.

The KPSS test is often used in econometrics to test for stationarity in financial time series data.

In this article, we will demonstrate how to perform a KPSS test in R using inbuilt datasets.

Implementation of KPSS Test:

To perform the KPSS test in R, we can use the “ur.kpss” function from the “urca” package. The function takes as input a time series and returns the test statistic along with its p-value.

Example 1: Testing Stationarity of the AirPassengers Dataset

The “AirPassengers” dataset in R contains information on the monthly number of airline passengers from 1949 to 1960. We can test whether this time series is stationary using the KPSS test.

The Multinomial Distribution in R » Data Science Tutorials

First, we need to load the dataset:

data("AirPassengers")

Next, we can plot the time series to visualize the data:

plot(AirPassengers)

From the plot, it seems that the time series is not stationary and has an increasing trend. We can now use the KPSS test to confirm the same:

library(urca)
kpss_test <- ur.kpss(AirPassengers)
kpss_test
The value of the test statistic is: 2.7395
kpss.test(AirPassengers)
KPSS Test for Level Stationarity

data:  AirPassengers
KPSS Level = 2.7395, Truncation lag parameter = 4, p-value = 0.01

The output will display the test statistic, degrees of freedom, the p-value, and a conclusion based on the test results.

In this case, since the p-value is less than 0.05, we reject the null hypothesis and conclude that the AirPassengers dataset is not stationary.

Example 2: Testing Stationarity of the Nile Dataset

The “Nile” dataset in R contains information on the annual river flow measurements of the Nile river from 1871 to 1970.

We can test whether this time series is stationary using the KPSS test.

First, we need to load the dataset:

data("Nile")
library(tseries)

Next, we can plot the time series to visualize the data:

plot(Nile)

From the plot, it seems that the time series is stationary. We can now use the KPSS test to confirm the same:

kpss_test <- kpss.test(Nile)
kpss_test
KPSS Test for Level Stationarity

data:  Nile
KPSS Level = 0.96543, Truncation lag parameter = 4, p-value = 0.01

The output will display the test statistic, degrees of freedom, the p-value, and a conclusion based on the test results.

In this case, since the p-value is greater than 0.05, we fail to reject the null hypothesis and conclude that the Nile dataset is stationary.

Conclusion:

In this article, we demonstrated how to perform a KPSS test in R using inbuilt datasets.

By using the KPSS test, researchers can determine whether a time series is stationary or not, which can help in developing stationary and reliable financial models.

Business Analyst »

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

eighteen + 8 =