As we have discussed last week we will focus on a certain type of unit root test namely Augmented Dickey Fuller test. There is two different functions for the Augmented Dickey Fuller test. First one of these tests are located in the urca package and the second one is located in the tseries package. We will install these packages with the following chunk.

install.packages("urca", repos = "https://cran.r-project.org/")
install.packages("tseries", repos = "https://cran.r-project.org/")
library(urca)
library(tseries)

First one of these functions is ur.df() command. We use this function by specifying the time series that we want to perform Dickey Fuller analysis on. Other arguments of the function are type which we can select from “none”, “drift”, and “trend” depending on the nature of our data. lags argument of the function allows us to determine the lag number to test for. By setting lags = 0 we perform Dickey Fuller test. As Augmented Dickey Fuller test is an augmented version of Dickey Fuller test for lags, any lag value other than 0 would perform Augmented Dickey Fuller test. Final argument of the ur.df() function is selectlags option and we can specify the lag selection algorithm. Now we can try this function with the following chunk. To do this we will utilize USMacroG dataset.

library(AER)
## Loading required package: car
## Loading required package: carData
## Loading required package: lmtest
## Loading required package: zoo
## 
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
## Loading required package: sandwich
## Loading required package: survival
library(urca)
data("USMacroG")
unemp_us <- USMacroG[2:204,9]
plot(unemp_us)

unemp_sum1 <- summary(ur.df(unemp_us))
unemp_sum2 <- summary(ur.df(unemp_us, type = "none", lags = 1))
unemp_sum3 <- summary(ur.df(unemp_us, type = "none", lags = 2))
unemp_sum4 <- summary(ur.df(log(unemp_us), type = "none", lags = 0))
unemp_sum5 <- summary(ur.df(log(unemp_us), type = "trend", lags = 0))
unemp_sum6 <- summary(ur.df(log(unemp_us), type = "drift", lags = 0))
unemp_sum7 <- summary(ur.df(diff(unemp_us), type = "none", lags = 0))
unemp_sum8 <- summary(ur.df(diff(unemp_us), type = "none", lags = 1))
unemp_sum9 <- summary(ur.df(diff(unemp_us), type = "none", lags = 2))
inflation_us <- USMacroG[2:204,11]
inf_sum1 <- summary(ur.df(inflation_us, type = "none", lags = 0))
inf_sum2 <- summary(ur.df(inflation_us, type = "none", lags = 1))
inf_sum3 <- summary(ur.df(inflation_us, type = "none", lags = 2))
money_supply <- USMacroG[,7]
plot(money_supply)

m1_sum1 <- summary(ur.df(money_supply))
m1_sum2 <- summary(ur.df(money_supply, type = "trend", lags = 0))
m1_sum3 <- summary(ur.df(money_supply, type = "trend", lags = 1))
m1_sum4 <- summary(ur.df(money_supply, type = "trend", lags = 2))
m1_sum5 <- summary(ur.df(diff(money_supply), type = "trend", lags = 0))

The second function we can use for ADF test is located in tseries package. Function can be used with adf.test() command. We can specify lag number with k = 0,1,2,3,… Unfortunately this function doesn’t allow us to select the nature of time series. One different thing in this command is that we can specify the alternative hypothesis.

library(tseries)
## Registered S3 method overwritten by 'xts':
##   method     from
##   as.zoo.xts zoo
## Registered S3 method overwritten by 'quantmod':
##   method            from
##   as.zoo.data.frame zoo
adf.test(unemp_us)
## 
##  Augmented Dickey-Fuller Test
## 
## data:  unemp_us
## Dickey-Fuller = -2.4984, Lag order = 5, p-value = 0.3673
## alternative hypothesis: stationary
adf.test(inflation_us)
## 
##  Augmented Dickey-Fuller Test
## 
## data:  inflation_us
## Dickey-Fuller = -2.9217, Lag order = 5, p-value = 0.1899
## alternative hypothesis: stationary
adf.test(money_supply)
## 
##  Augmented Dickey-Fuller Test
## 
## data:  money_supply
## Dickey-Fuller = -2.0744, Lag order = 5, p-value = 0.5449
## alternative hypothesis: stationary

Since we have defined two functions regarding ADF test, let’s try to obtain some inferences about the Quantity Theory of Money by setting up some regressions with the data on USMacroG dataset.