ARDL package

noetsi

Fortran must die
#1
How does R know where the data is in this code

library(ARDL)
data(denmark)

First, we find the best ARDL specification. We search up to order 5.
models <- auto_ardl(LRM ~ LRY + IBO + IDE, data = denmark, max_order = 5)

Does it look for your WD for a file called Denmark?

I don't understand what the ~ means. Is this an actual symbol you code?

https://www.rdocumentation.org/packages/ARDL/versions/0.1.0
 

obh

Active Member
#2
Hi Noetsi :)

"denmark" already contains data, just example data for you to use. later you will use your own data instead of "denmark".

Try to write data(), and you will see all the already available datasets, for example: austres, cars, denmark

> denmark

LRM LRY LPY IBO IDE

1974 Q1 11.63255 5.903658 -0.618735936 0.1547356 0.09400000

1974 Q2 11.60415 5.873820 -0.580747868 0.1779912 0.09550000

1974 Q3 11.58152 5.837818 -0.542847846 0.1705647 0.09550000

1974 Q4 11.60185 5.812255 -0.504604068 0.1522273 0.09550000


So you don't need to write data(denmark).
Buy you may write it:

"There is no requirement for data(foo) to create an object named foo (nor to create one object), although it much reduces confusion if this convention is followed (and it is enforced if datasets are lazy-loaded)."

When you write: models <- auto_ardl(LRM ~ LRY + IBO + IDE, data = denmark, max_order = 5)
The "data = denmark" defines denmark as the data parameter to use

You may as well write :"models <- auto_ardl(LRM ~ LRY + IBO + IDE, denmark, 5)"

There is an advantage of stating the name of the parameter, if you skip parameter you won't get a mess ...
 

hlsmith

Less is more. Stay pure. Stay poor.
#3
In many r functions (e.g., models), you put the DV on the left hand side of the '~' and the IVs on the right hand side. So you are just defining your model.
 

noetsi

Fortran must die
#4
thanks. I guessed the data was in the file. I just copied and pasted the existing code in the link. I did not think I could link to the data in the Denmark file.

I did not know hlsmith that ~ does that. I was trying to figure out how they defined the model. But I don't think that there are exogenous variables in this form of ARDL so speaking of IV does not make sense to me. Its like VAR I think.
 

Dason

Ambassador to the humans
#6
Hi Noetsi,

I assume you mean R built in data set (you don't load it from a file, it is already part of the software)
Ackkkktulllyyyyy... It is loaded from a file. Typically lazy loaded and you don't need to specify the absolute path for the data file but... Yeah it's loaded from a file that gets installed when you install the package.
 

Dason

Ambassador to the humans
#8
Actually...

Haha. I do have an objection to your last post but don't really want to continue down this technical rabbit hole.
 

noetsi

Fortran must die
#11
I don't understand this error from the package ARDL.
model1<-auto_ardl(LRM~LRY+ IBO + IDE, data = denmark,c(12,12,12,12))
Warning message:
The `x` argument of `as_tibble.matrix()` must have column names if `.name_repair` is omitted as of tibble 2.0.0.
Using compatibility `.name_repair`.

When I run model1<-auto_ardl(LRM~LRY+ IBO + IDE, data = denmark,c(5,5,5,5))

it runs without error. Nothing in the code says that the number of lags, which this is looking for the optimal lag, is limited). For monthly data a lag of 12 is not that great (maybe the issue is with the Denmark data set which I did not create) :p


While I am at it I ran

model1<-auto_ardl(LRM~LRY+ IBO + IDE, data = denmark, c(5,5,5,5))
summary(model1)

and got
Length Class Mode
best_model 19 dynlm list
best_order 4 -none- numeric
top_orders 5 data.frame list

I expected it to select the best lag for each variable using AIC. But if it does that I don't see it here.

from the documentation best_model An object of class c("dynlm","lm","ardl")
best_order A numeric vector with the order of the best model selected

Does this mean in this case it selected 4 for the best lag for each variable? I expected to see variation by variable although this can occur.
 
Last edited:

obh

Active Member
#12
Hi Noetsi,

I didn't get any error

Code:
> library(ARDL)
To cite ARDL in publications use:
 
Kleanthis Natsiopoulos and Nickolaos Tzeremes (2020). ARDL: ARDL, ECM and Bounds-Test for Cointegration. R package version 0.1.0. University of Thessaly, Department of Economics. https://github.com/Natsiopoulos/ARDL.
Warning message:
package ‘ARDL’ was built under R version 3.5.3
>
> model1<-auto_ardl(LRM~LRY+ IBO + IDE, data = denmark,c(12,12,12,12))
> model1
$`best_model`

Time series regression with "zooreg" data:
Start = 1976 Q4, End = 1987 Q3

Call:
dynlm::dynlm(formula = full_formula, data = data, start = start,
    end = end)

Coefficients:
(Intercept)    L(LRM, 1)    L(LRM, 2)    L(LRM, 3)    L(LRM, 4)    L(LRM, 5) 
    13.2708      -0.3373      -3.3531       0.6041       0.6965       2.0990 
  L(LRM, 6)    L(LRM, 7)    L(LRM, 8)    L(LRM, 9)          LRY    L(LRY, 1) 
     2.0103       0.1450       1.1687      -3.4715       1.3860       0.3083 
  L(LRY, 2)    L(LRY, 3)    L(LRY, 4)    L(LRY, 5)    L(LRY, 6)    L(LRY, 7) 
    -0.8055      -1.1635       1.0926      -0.0366       1.3717      -3.2830 
  L(LRY, 8)    L(LRY, 9)   L(LRY, 10)   L(LRY, 11)          IBO    L(IBO, 1) 
     0.7877       0.5564      -0.5068       1.0369      -5.6451      -3.1939 
  L(IBO, 2)    L(IBO, 3)    L(IBO, 4)    L(IBO, 5)    L(IBO, 6)    L(IBO, 7) 
     3.6056      -3.9990       0.1311      -4.6058       4.0662      -1.1983 
  L(IBO, 8)    L(IBO, 9)          IDE    L(IDE, 1)    L(IDE, 2)    L(IDE, 3) 
    10.0167      -2.5917      10.3494      -2.8335      -6.5646       0.3809 
  L(IDE, 4)    L(IDE, 5)    L(IDE, 6)    L(IDE, 7)    L(IDE, 8)    L(IDE, 9) 
    -3.3850       7.5455       3.5291      -6.4006       0.3504      -3.2875 
 L(IDE, 10)   L(IDE, 11) 
    -1.1122      -1.4755 


$best_order
[1]  9 11  9 11

$top_orders
   LRM LRY IBO IDE       AIC
1    9  11   9  11      -Inf
2    9  12   9  11      -Inf
3    9  11  10  11      -Inf
4    9  11   9  12      -Inf
5   10  11  10  10      -Inf
6   10  11   9  10      -Inf
7   10  11  10   9      -Inf
8   10  12  10  10      -Inf
9   11  11  11  11      -Inf
10  11  10  11  11      -Inf
11  11  11  10  11      -Inf
12  11  11  11  10      -Inf
13  12  12  12  12      -Inf
14   9  11   9  10 -506.2717
15  10  10  10  10 -373.9267
16   9  11   8  10 -348.5484
17   9  10   8  10 -329.5281
18   9  10   8   9 -318.6756
19   9  10   9   9 -317.9162
20   9   9   9   9 -310.6831
 

noetsi

Fortran must die
#13
I did not get that error when I ran it again. I apologize for the confusion (I am not sure what happened last time except some times I get strange errors).

On a more substantive point, the purpose of that code is to pull in the optimal lags using AIC.
The results of the above yield
$best_order
which is
[1] 9 11 9 11

I don't understand what the - inf means for AIC. Nothing I have read in AIC or ARDL addresses this. I would have thought the section I bolded is the best lag because it has the lowest actual value.

[ code]
LRM LRY IBO IDE AIC
1 9 11 9 11 -Inf
2 9 12 9 11 -Inf
3 9 11 10 11 -Inf
4 9 11 9 12 -Inf
5 10 11 10 10 -Inf
6 10 11 9 10 -Inf
7 10 11 10 9 -Inf
8 10 12 10 10 -Inf
9 11 11 11 11 -Inf
10 11 10 11 11 -Inf
11 11 11 10 11 -Inf
12 11 11 11 10 -Inf
13 12 12 12 12 -Inf
14 9 11 9 10 -506.2717
15 10 10 10 10 -373.9267
16 9 11 8 10 -348.5484
17 9 10 8 10 -329.5281
18 9 10 8 9 -318.6756
19 9 10 9 9 -317.9162
20 9 9 9 9 -310.6831
[/code]
 
Last edited:

noetsi

Fortran must die
#15
Then why would the algorithm say 9 11 9 11 is better (higher up in the order is supposed to be better) than a 9 11 9 12 both of which have negative infinity. Is this parsimony coming into effect (the documentation does not mention that for the algorithm).

I don't really understand how you can have perfect fit for this data, but I guess it must be possible.
 

obh

Active Member
#16
I did not get that error when I ran it again. I apologize for the confusion (I am not sure what happened last time except some times I get strange errors).
[/code]
I can only assume you did something in a different way... may be you defined something else in "data"?
You may always try to clean the workspace: Sessions => Clear Workspace
Or write : "rm(list = ls())"
ls() is the list of variables
for example:

> ls()

[1] "model1" "x"

so rm remove the list of variables.
 

noetsi

Fortran must die
#19
I ran the same exact code twice. Once I got that error and once I did not. This happens with SAS when we are having server issues which is why I assumed it was this.

But I know you know a heck of a lot more than I do. :p Since it does not happen any more I guess it does not matter why it occurred before. Maybe I typed something wrong.