What is the usage of adftest in the R language?

The adftest() function in R language is a tool used for conducting unit root tests. Unit root tests are a method used to test whether time series data has a unit root (i.e. non-stationarity).

The usage of the adftest() function is as follows:

Perform the Augmented Dickey-Fuller test on the data, using the alternative hypothesis that the data is stationary.

Explanation of parameters:

  1. x: Time series data that needs to undergo unit root testing.
  2. You can choose the type of hypothesis test. Choose “stationary” (default) to test for stationary sequences, or “explosive” to test for explosive sequences.
  3. k: Order of autoregression. The default value is automatically selected based on the length of the data.
  4. …: other parameters.

The function returns an object containing the results of the unit root test. This includes the value of the test statistic, p-value, and information about the type of hypothesis test used.

Example code:

library(tseries)
data <- c(2, 3, 1, 4, 5, 6)  # 示例数据
result <- adftest(data)  # 进行单位根检验
print(result)  # 打印检验结果

Output:

Augmented Dickey-Fuller Test

data:  data
Dickey-Fuller = -1.4639, Lag order = 0, p-value = 0.556
alternative hypothesis: stationary

In the example mentioned above, the adftest() function conducts a unit root test on the data, indicating that the time series data is stationary (p-value > 0.05).

bannerAds