A time series is said to be “stationary” if it has no trend, exhibits constant variance over time, and has a constant autocorrelation structure over time.
One way to test whether a time series is stationary is to perform an augmented Dickey-Fuller test, which uses the following null and alternative hypotheses:
H0: The time series is non-stationary. In other words, it has some time-dependent structure and does not have constant variance over time.
HA: The time series is stationary.
If the p-value from the test is less than some significance level (e.g. α = .05), then we can reject the null hypothesis and conclude that the time series is stationary.
The following step-by-step example shows how to perform an augmented Dickey-Fuller test in R for a given time series.
Example: Augmented Dickey-Fuller Test in R
Suppose we have the following time series data in R:
data <- c(3, 4, 4, 5, 6, 7, 6, 6, 7, 8, 9, 12, 10)
Before we perform an augmented Dickey-Fuller test on the data, we can create a quick plot to visualize the data:
To perform an augmented Dickey-Fuller test, we can use the adf.test() function from the tseries library.
The following code shows how to use this function:
library(tseries) #perform augmented Dickey-Fuller test adf.test(data) Augmented Dickey-Fuller Test data: data Dickey-Fuller = -2.2048, Lag order = 2, p-value = 0.4943 alternative hypothesis: stationary
Here’s how to interpret the most important values in the output:
- Test statistic: -2.2048
- P-value: 0.4943
Since the p-value is not less than .05, we fail to reject the null hypothesis.
This means the time series is non-stationary. In other words, it has some time-dependent structure and does not have constant variance over time.