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() method confusion #44

Open
michael-aksonov opened this issue Sep 15, 2023 · 0 comments
Open

predict() method confusion #44

michael-aksonov opened this issue Sep 15, 2023 · 0 comments

Comments

@michael-aksonov
Copy link

michael-aksonov commented Sep 15, 2023

Hello, and thank you for this amaizing package!

I am a little bit confused with your predict() method, I tried too clarify it for myself by looking into source code for it, it did not resolve my issue, so I hope you can help.

In this piece of code below, if n.ahead == 1, there is no VARX method, only VAR, is it because you assume, that the model depends only on lagged external regressors so they are not needed?

Additionaly, If you have n.ahead > 1 for VARX, there seems to no predict_all option, so what forecast step is then outputed? The last one?

Thank you!

if (n.ahead == 1) {
        if (confint) {
            lower <- fcst + ci[, 1]
            upper <- fcst + ci[, 2]
            fcst <- as.data.frame(cbind(fcst, lower, upper))
            names(fcst) <- c("forecast", "lower", "upper")
        }
        return(fcst)
    } else {
        if (!VARX) {
            fcst <- predictMS(matrix(fcst, nrow = 1), Y[(nrow(Y) - p + 1):nrow(Y), ], n.ahead - 1, betaPred, p, MN, predict_all = predict_all)
            if (predict_all) {
                row.names(fcst) <- paste0("T+", 1:n.ahead)
            } else {
                fcst <- t(fcst)
            }
        } else {
            if (is.null(newxreg)) {
                stop("Need new data for multi-step VARX forecasts.  Re-run with new data in newxreg")
            } else {
                if (nrow(newxreg) < n.ahead - 1) {
                    stop(paste("Need at least ", n.ahead - 1, "rows of new data"))
                }
                C <- max(p, s)
                if (contemp) {
                    C <- C + 3
                }
                fcst <- matrix(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), ncol = 1)
            }
        }
    }

UPD:
As of now, I have solved part of the question "... that the model depends only on lagged external regressors so they are not needed?". As I understood, it is possible to include unlagged external regressors by setting

contemp = TRUE

inside VARX list of settings in constructModel()

But now even if contemporaneous unmodeled series is included, predict() still does not ask for regressors which are corresponding to beta-0 coefficient matrix when making a 1-step-ahead forecast.

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

1 participant