Hello, everyone here. I don't know how to find the number of lags from the VARselect when applying the Johansen's conintegration test in r. Does anyone help me to solve it?
library(vars)
library(tsDyn)
# Simulate the data
data <- runif(100)
# i. Select the number of lags in the VAR model with 'VARselect' from vars
lag_num <- VARselect(data, lag.max = 12, type = "const")
# ii. Estimate a VECM with 'VECOM' from tsDyn
vecm <- VECM(gbp, estim = "ML", lag = length(lag_num)-1)
I wont pretend to fully understand what you are trying to do; but how you are seeming to use the results of VARselect seem at a glance to be problematic.
VARselect always returns two things ; selection, and criteria, so if you check its length and subtract by 1, you will always get 1. i.e. when you call your VECM function, it is not in anyway informed by VARselect in any meaningful way; (putting aside that this gbp data has not been an input to VARselect)
Thanks for your reply. I now know that I need to check the selection from VARselect to decide the number of lags. I'd have used the data in VECM. Thanks again for your help.