I am new here, but I checked other threads and have not found solution so far. I am trying to make a VAR model in R, it looks like this:
library(vars)
library(lmtest)
# from loaded data I create model:
v1 <- data.frame(PRG, VYS, r, GDP)
lag_order <- VARselect(v1, lag = 2, type = "const")$selection[1]
model <- VAR(v1, p = lag_order, type = "const")
Then I try bgtest for checking serial autocorrelation:
res <- data.frame(residuals(model))
test_result <- bgtest(res, order = lag_order)
but I get this error message:
Error in x$terms %||% attr(x, "terms") %||% stop("no terms component nor attribute") : no terms component nor attribute
I tried to change data type of obtained residuals but this was not helpful. I also tried to fit
VAR(v1, p = lag_order, type = "const")
directly instad of formula, but that also had no impact