-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathREADME.Rmd
200 lines (142 loc) · 7.24 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# ARDL <img src="man/figures/logo.png" align="right" width="120" />
<!-- badges: start -->
[](https://CRAN.R-project.org/package=ARDL)
[](https://CRAN.R-project.org/package=ARDL)
[](https://lifecycle.r-lib.org/articles/stages.html#stable)
[](https://app.codecov.io/gh/Natsiopoulos/ARDL)
<!-- badges: end -->
## Overview
`ARDL` creates complex autoregressive distributed lag (ARDL) models and constructs the underlying unrestricted and restricted error correction model (ECM) automatically, just by providing the order. It also performs the bounds-test for cointegration as described in [Pesaran et al. (2001)](https://onlinelibrary.wiley.com/doi/abs/10.1002/jae.616) and provides the multipliers and the cointegrating equation. The validity and the accuracy of this package have been verified by successfully replicating the results of Pesaran et al. (2001) in [Natsiopoulos and Tzeremes (2022)](https://onlinelibrary.wiley.com/doi/abs/10.1002/jae.2919).
## Why `ARDL`?
- Estimate complex ARDL models just providing the ARDL order
- Estimate the conditional ECM just providing the underlying ARDL model or the order
- Estimate the long-run, short-run, delay, and interim multipliers
- Apply the bound test for no cointegration (*Pesaran et al., 2001*)
- Both the *F-test* and the *t-test* are available
- The *p-value* is also available along with the *critical value bounds* for specific level of statistical significance
- Exact *p-values* and *critical value bounds* are available, along with the asymptotic ones
## Installation
```{r, eval = FALSE}
# You can install the released version of ARDL from CRAN:
install.packages("ARDL")
# Or the latest development version from GitHub:
install.packages("devtools")
devtools::install_github("Natsiopoulos/ARDL")
```
## Usage
This is a basic example which shows how to use the main functions of the `ARDL` package.
Assume that we want to model the `LRM` (logarithm of real money, M2) as a function of `LRY`, `IBO` and `IDE` (see `?denmark`). The problem is that applying an OLS regression on non-stationary data would result into a spurious regression. The estimated parameters would be consistent only if the series were cointegrated.
```{r include=FALSE}
library(ARDL)
```
```{r pkg-data}
library(ARDL)
data(denmark)
```
First, we find the best ARDL specification. We search up to order 5.
```{r auto-ardl}
models <- auto_ardl(LRM ~ LRY + IBO + IDE, data = denmark, max_order = 5)
# The top 20 models according to the AIC
models$top_orders
# The best model was found to be the ARDL(3,1,3,2)
ardl_3132 <- models$best_model
ardl_3132$order
summary(ardl_3132)
```
Then we can estimate the UECM (Unrestricted Error Correction Model) of the underlying ARDL(3,1,3,2).
```{r uecm}
uecm_3132 <- uecm(ardl_3132)
summary(uecm_3132)
```
And also the RECM (Restricted Error Correction Model) of the underlying ARDL(3,1,3,2), allowing the constant to join the long-run relationship (case 2), instead of the short-run (case 3).
```{r recm}
recm_3132 <- recm(uecm_3132, case = 2)
summary(recm_3132)
```
Let's test if there is a long-run levels relationship (cointegration) using the **bounds test** from *Pesaran et al. (2001)*.
```{r bounds-test}
# The bounds F-test (under the case 2) rejects the NULL hypothesis (let's say, assuming alpha = 0.01) with p-value = 0.004418.
bounds_f_test(ardl_3132, case = 2)
# The bounds t-test (under the case 3) rejects the NULL hypothesis (let's say, assuming alpha = 0.01) with p-value = 0.005538.
# We also provide the critical value bounds for alpha = 0.01.
tbounds <- bounds_t_test(uecm_3132, case = 3, alpha = 0.01)
tbounds
# Here is a more clear view of the main results.
tbounds$tab
```
Here we have the short-run and the long-run multipliers (with standard errors, t-statistics and p-values).
```{r mult}
multipliers(ardl_3132, type = "sr")
multipliers(ardl_3132)
```
We can also estimate and visualize the delay multipliers along with their standard errors.
```{r}
mult15 <- multipliers(ardl_3132, type = 15, se = TRUE)
plot_delay(mult15, interval = 0.95)
```
Now let's graphically check the estimated long-run relationship (cointegrating equation) against the dependent variable `LRM`.
```{r ce}
ce <- coint_eq(ardl_3132, case = 2)
```
```{r lr-plot}
plot_lr(ardl_3132, coint_eq = ce, show.legend = TRUE)
```
Forecasting and using an `ardl`, `uecm`, or `recm` model in other functions are easy as they can be converted in regular `lm` models.
```{r Convert-to-lm-and-forecast}
ardl_3132_lm <- to_lm(ardl_3132)
# Forecast using the in-sample data
insample_data <- ardl_3132$model
predicted_values <- predict(ardl_3132_lm, newdata = insample_data)
# Convert to ts class for the plot
predicted_values <- ts(predicted_values, start = c(1974,4), frequency=4)
plot(denmark$LRM, lwd=2) #The input dependent variable
lines(predicted_values, col="red", lwd=2) #The predicted values
```
## Ease of use
Let's see what it takes to build the above ARDL(3,1,3,2) model.
**Using the `ARDL` package (literally one line of code):**
```{r ease-of-use-ardl}
ardl_model <- ardl(LRM ~ LRY + IBO + IDE, data = denmark, order = c(3,1,3,2))
```
**Without the `ARDL` package:**</br>
*(Using the `dynlm` package, because striving with the `lm` function would require extra data transformation to behave like time-series)*
```{r dynlm-ardl}
library(dynlm)
dynlm_ardl_model <- dynlm(LRM ~ L(LRM, 1) + L(LRM, 2) + L(LRM, 3) + LRY + L(LRY, 1) +
IBO + L(IBO, 1) + L(IBO, 2) + L(IBO, 3) +
IDE + L(IDE, 1) + L(IDE, 2), data = denmark)
```
```{r}
identical(ardl_model$coefficients, dynlm_ardl_model$coefficients)
```
An ARDL model has a relatively simple structure, although the difference in typing effort is noticeable.
Not to mention the complex transformation for an ECM. The extra typing is the least of your problems trying to do this. First you would need to figure out the exact structure of the model!
**Using the `ARDL` package (literally one line of code):**
```{r ease-of-use-uecm}
uecm_model <- uecm(ardl_model)
```
**Without the `ARDL` package:**
```{r dynlm-uecm}
dynlm_uecm_model <- dynlm(d(LRM) ~ L(LRM, 1) + L(LRY, 1) + L(IBO, 1) +
L(IDE, 1) + d(L(LRM, 1)) + d(L(LRM, 2)) +
d(LRY) + d(IBO) + d(L(IBO, 1)) + d(L(IBO, 2)) +
d(IDE) + d(L(IDE, 1)), data = denmark)
```
```{r}
identical(uecm_model$coefficients, dynlm_uecm_model$coefficients)
```
## References
Natsiopoulos, Kleanthis, & Tzeremes, Nickolaos G. (2022). ARDL bounds test for cointegration: Replicating the Pesaran et al. (2001) results for the UK earnings equation using R. *Journal of Applied Econometrics*, 37(5), 1079-1090. https://doi.org/10.1002/jae.2919
Pesaran, M. H., Shin, Y., & Smith, R. J. (2001). Bounds testing approaches to the analysis of level relationships. *Journal of Applied Econometrics*, 16(3), 289-326