Stationarity of Time Series Data using R
Load and check the times series data
R
# Load necessary packages install.packages ( c ( "tseries" , "zoo" )) library (tseries) library (zoo) # Load lh dataset (already stationary) data ( "lh" ) # 1. Visual Inspection plot (lh, main = "Guinea Pigs Tibia Lengths" ) # 2. Summary Statistics summary (lh) |
Output:
Min. 1st Qu. Median Mean 3rd Qu. Max.
1.40 2.00 2.30 2.40 2.75 3.50
Check Stationarity of Time Series Data
1. Augmented Dickey-Fuller (ADF) Test
R
# 4. Augmented Dickey-Fuller (ADF) Test adf_test <- adf.test (lh) print ( "ADF Test:" ) print (adf_test) |
Output:
[1] "ADF Test:"
Augmented Dickey-Fuller Test
data: lh
Dickey-Fuller = -3.558, Lag order = 3, p-value = 0.04624
alternative hypothesis: stationary
The Augmented Dickey-Fuller (ADF) test was applied to the lh dataset, yielding a test statistic of -3.558 with a lag order of 3. The associated p-value is 0.04624. With a significance level of 0.05, the p-value is below the threshold, leading to the rejection of the null hypothesis. Consequently, there is evidence to suggest that the lh dataset is stationary. This result aligns with the expected behavior, confirming the absence of a unit root and supporting the stationary nature of the time series.
2. Kwiatkowski-Phillips-Schmidt-Shin (KPSS) Test
R
# 5. Kwiatkowski-Phillips-Schmidt-Shin (KPSS) Test kpss_test <- kpss.test (lh) print ( "KPSS Test:" ) print (kpss_test) |
Output:
[1] "KPSS Test:"
KPSS Test for Level Stationarity
data: lh
KPSS Level = 0.29382, Truncation lag parameter = 3, p-value = 0.1
The KPSS (Kwiatkowski-Phillips-Schmidt-Shin) test was conducted on the lh dataset, resulting in a KPSS Level statistic of 0.29382 with a truncation lag parameter of 3. The associated p-value is 0.1. In the context of the test for level stationarity, a p-value greater than the significance level (commonly 0.05) suggests that we fail to reject the null hypothesis. Therefore, based on the KPSS test, the lh dataset provides evidence in favor of level stationarity. It is important to note that the ADF and KPSS tests assess different aspects of stationarity, and their complementary results can enhance the confidence in the overall stationarity assessment.
Stationarity of Time Series Data using R
In this article, we will discuss about Stationarity of Time Series Data, its characteristics, and types, why stationarity matters, and How to test it using R.
Contact Us