wbnicholson/BigVAR

Predict only returns last n.ahead prediction

Closed this issue · 5 comments

Hi @wbnicholson,
I've noticed that the predict function only returns the last point forecast for all endogenous variables in a multistep forecast.

I have tried to locate the problem and I think it's in the predictMS / predictMSX function where the pred variable isn't stored before running the next n.ahead iteration. One solution could be to return Y which stores all predictions and filters out rows with historic data.
predictMS return(rbind(Y, pred)[-(1:p), ] )
predictMSX return(rbind(Y, pred)[-(1:max(p,s)), ] )

And then skip the matrix limitation (ncol=1) in predict class function
fcst <- predictMS(matrix(fcst,nrow=1),Y[(nrow(Y)-p+1):nrow(Y),],n.ahead-1,betaPred,p,MN)

fcst <- predictMSX(matrix(fcst,nrow=1),as.matrix(Y[(nrow(Y)-C+1):nrow(Y),1:(k)]),n.ahead-1,betaPred,p,newxreg,matrix(Y[(nrow(Y)-C+1):nrow(Y),(ncol(Y)-m+1):ncol(Y)],ncol=m),m,s,1,MN,contemp)

I have verified the prediction result by translating the BigVar class to a varest class and run their prediction function

Example output without this fix (predict.BigVAR, n.ahead=6, number of endogenous variables 7)

[,1] [,2] [,3] [,4] [,5] [,6] [,7]
-0.07483348 0.2078078 0.5577497 0.4923881 0.7485516 0.2824906 0.1842608

Example output with the fix; (last row is the same as current output)

Y1 Y2 Y3 Y4 Y5 Y6 Y7
0.19694157 0.1400551 0.2231896 0.5610747 0.4529248 0.8701000 0.3086403
0.03157659 0.2037264 0.3376861 0.4832005 0.4502285 0.6097922 0.2669111
0.03696794 0.1572429 0.4032445 0.5270550 0.5196305 0.5684885 0.2580613
-0.42382382 0.1871817 0.4830292 0.5387928 0.7028809 0.4456416 0.2973962
0.12573047 0.2354062 0.5292030 0.6077442 0.6309911 0.3632288 0.2060916
-0.07483348 0.2078078 0.5577497 0.4923881 0.7485516 0.2824906 0.1842608

PS. I have not looked into how the changes in predictMS are affecting the cross-validation in cv.BigVAR

Clarification, the return statement I am talking about are these;

if(n.ahead==1){return(pred)}

if(n.ahead==1){return(pred)}

Does this mean that the cv.BigVAR only optimizes the last forecast point?

I'm hesitant to change the default behavior in the predict method since it could cause compatibility issues, but I enabled the ability to return all forecasts with the added option predict_all=TRUE.

Does this work for your use case?

Does this mean that the cv.BigVAR only optimizes the last forecast point?

Yes, it optimizes according to h-step forecast horizon. If you wanted to optimize over a blended horizon you could run cv.BigVAR for various forecast horizons and take an average over the resulting lambdas selected.

I'm hesitant to change the default behavior in the predict method since it could cause compatibility issues, but I enabled the ability to return all forecasts with the added option predict_all=TRUE.

Does this work for your use case?

I fully understand keeping the predict function untouched to minimize the dependency modifications. And yes that would solve the problem, thank you :-)