Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Predict function VARX #12

Open
alexsuarez94 opened this issue Apr 18, 2019 · 13 comments
Open

Predict function VARX #12

alexsuarez94 opened this issue Apr 18, 2019 · 13 comments

Comments

@alexsuarez94
Copy link

I have a penalized VARX model after applying cv.BigVAR() function and I want to perform a 10 -step forecast but the function predict returns the following error: "Error in 2:nrow(Z) : argument of length 0".

I have, 30 endogenous variables and 15 exogenous variables so I am specifying:
predict(Model_results, n.ahead = 10, newxreg = exogenous_variables[1:10, 1:15])
There is no problem when I launch forecast with n.ahead = 1.

Any suggestion of what could be the problem?

Thank you so much!

@wbnicholson
Copy link
Owner

Could you post the specifications that you passed to cv.BigVAR?

@alexsuarez94
Copy link
Author

Could you post the specifications that you passed to cv.BigVAR?

Model <- constructModel(Y = as.matrix(train), p=1, struct="Basic", gran=c(50, 10), verbose=TRUE, RVAR = FALSE, h = 1, MN = TRUE, VARX=list(k = 30, s = 2), intercept = TRUE, C = mn_prior, recursive = FALSE)
cv.BigVAR(Model)

where Y is a 45x144 matrix, and mn_prior is a vector of 30 values [0, 1]. The rest of the arguments are in their default values.

Thank you so much!

@wbnicholson
Copy link
Owner

It appears that there was an issue with the Minnesota Prior component of the multi-step forecast. I just pushed an update that should fix it.

@kaijennissen
Copy link

How do I create forecasts for a VARX?
When I try to predict a VARX I get the following error message:

Error in if (contemp) { : argument is of length zero

The model was created using the following code:

mod1 <- constructModel(Y = Y, p = 12, struct = "Basic", gran = c(50, 10), verbose = TRUE, h = 3, cv = "Rolling", VARX = list(k = 4, s = 1), intercept = TRUE)
results <- cv.BigVAR(mod1)
predict(results, n.ahead = 3, newxreg = new_X)

Y is a 226x15 matrix with 4 endogeneous and 11 exogeneous variable (i.e. monthly dummies).
For new_X I've tried to supply a 3x11 matrix containing only the dummy variables as well as a 3x15 matrix where the values for the endogenous variables are NA. In both cases, the above mentioned error occured.

@wbnicholson
Copy link
Owner

This issue should have been fixed in the latest development version. Let me know if it still persists or if you encounter other issues. I will submit the updated package to cran shortly.

@wbnicholson wbnicholson reopened this Dec 10, 2019
@kaijennissen
Copy link

You're right. The error does no longer exist in development version. Thanks

@lenkiefer
Copy link

When I try to run predict with n.ahead >1 I get an error:

Error in predictMS(matrix(fcst, nrow = 1), Y[(nrow(Y) - p + 1):nrow(Y), : object 'g' not found

If I look at BigVARSupportFunctions.R at line 2257 there appears to be a misplaced g that is causing the error.

@wbnicholson
Copy link
Owner

Thanks, this has been fixed

@jonlachmann
Copy link
Contributor

I am getting the same error as @kaijennissen when creating a model as follows

T1 <- floor(nrow(Y)/3)
T2 <- floor(2*nrow(Y)/3)

VARX <- list()
VARX$k <- 2 # indicates that the first two series are modeled
VARX$s <- 2 # sets 2 as the maximal lag order for exogenous series

model <- constructModel(Y, p=4, struct="Basic", gran=c(50,10), verbose=FALSE, VARX=VARX, T1=T1-3, T2=T2, h=3)
bigvar <- cv.BigVAR(model)
predict(bigvar, n.ahead = 1)

The matrix Y has the structure

str(Y)
 Time-Series [1:227, 1:3] from 1957 to 2014: -0.888 3.877 -4.121 -10.506 2.631 ...
 - attr(*, "dimnames")=List of 2
  ..$ : NULL
  ..$ : chr [1:3] "GDPGrowth" "TSpread[-1]" "TB10YS[-1]"

The last row with predict gives the error

Error in if (contemp) { (main.R#109): argument is of length zero

It might be that I am doing something wrong, but if that is the case I cant see what.

@wbnicholson
Copy link
Owner

Do you still encounter this issue in the github build? I will correct this issue in the cran version in the very near future.

@jonlachmann
Copy link
Contributor

jonlachmann commented Dec 18, 2020

Do you still encounter this issue in the github build? I will correct this issue in the cran version in the very near future.

Hi! I tried building the package from source from the files here at github, works like a charm! Thanks!

@leosaenger
Copy link

leosaenger commented May 7, 2021

Hi -- I am not having the above issue with Error in if (contemp) { (main.R#109): argument is of length zero (downloading from the GitHub worked great to resolve this!), but I am getting the error Error in rbind(Y, pred) : number of columns of matrices must match (see arg 2). I am running

predict(results, n.ahead = 2, newxreg = as.matrix.data.frame(holdout))

Where I have 12 endogenous variables and 2 exogenous variables. Running this with n.ahead = 1 works great. Varying n.ahead and ensuring holdout is formatted correctly doesn't seem to help much. I'm not sure what's going on here -- very sorry if it's an obvious mistake, and thanks for your work on this package!

@wbnicholson
Copy link
Owner

Could you post a reproducible example (including your specification in constructModel)? I can't seem to replicate your error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants