# forecast

Forecast vector autoregression (VAR) model responses

## Syntax

## Description

### Conditional and Unconditional Forecasts for Numeric Arrays

returns a numeric array containing paths of minimum mean squared error (MMSE)
multivariate response forecasts `Y`

= forecast(`Mdl`

,`numperiods`

,`Y0`

)`Y`

over a length
`numperiods`

forecast horizon, using the fully specified
VAR(*p*) model `Mdl`

. The forecasted
responses represent the continuation of the presample data in the numeric array
`Y0`

.

uses additional options specified by one or more name-value arguments.
`Y`

= forecast(`Mdl`

,`numperiods`

,`Y0`

,`Name=Value`

)`forecast`

returns numeric arrays when all optional
input data are numeric arrays. For example,
`forecast(Mdl,10,Y0,X=Exo)`

returns a numeric array
containing a 10-period forecasted response path from `Mdl`

and the numeric matrix of presample response data `Y0`

, and
specifies the numeric matrix of future predictor data for the model regression
component in the forecast horizon `Exo`

.

To produce a conditional forecast, specify future response data in a numeric
array by using the `YF`

name-value argument.

### Unconditional Forecasts for Tables and Timetables

returns the table or timetable `Tbl2`

= forecast(`Mdl`

,`numperiods`

,`Tbl1`

)`Tbl2`

containing the length
`numperiods`

paths of multivariate MMSE response variable
forecasts, which result from computing unconditional forecasts from the VAR
model `Mdl`

. `forecast`

uses the table
or timetable of presample data `Tbl1`

to initialize the
response series.* (since R2022b)*

`forecast`

selects the variables in
`Mdl.SeriesNames`

to forecast, or it selects all variables
in `Tbl1`

. To select different response variables in
`Tbl1`

to forecast, use the
`PresampleResponseVariables`

name-value argument.

uses additional options specified by one or more name-value arguments. For
example, `Tbl2`

= forecast(`Mdl`

,`numperiods`

,`Tbl1`

,`Name=Value`

)```
forecast(Mdl,10,Tbl1,PresampleResponseVariables=["GDP"
"CPI"])
```

returns a timetable of response variables containing their
unconditional forecasts from the VAR model `Mdl`

, initialized
by the data in the `GDP`

and `CPI`

variables
of the timetable of presample data in `Tbl1`

.* (since R2022b)*

### Conditional Forecasts for Tables and Timetables

returns the table or timetable `Tbl2`

= forecast(`Mdl`

,`numperiods`

,`Tbl1`

,InSample=`InSample`

,ResponseVariables=`ResponseVariables`

)`Tbl2`

containing the length
`numperiods`

paths of multivariate MMSE response variable
forecasts and corresponding forecast MSEs, which result from computing
conditional forecasts from the VAR model `Mdl`

.
`forecast`

uses the table or timetable of presample
data `Tbl1`

to initialize the response series.
`InSample`

is a table or timetable of future data in the
forecast horizon that `forecast`

uses to compute
conditional forecasts and `ResponseVariables`

specifies the
response variables in `InSample`

.* (since R2022b)*

uses additional options specified by one or more name-value arguments.`Tbl2`

= forecast(`Mdl`

,`numperiods`

,`Tbl1`

,InSample=`InSample`

,ResponseVariables=`ResponseVariables`

,`Name=Value`

)* (since R2022b)*

## Examples

## Input Arguments

## Output Arguments

## Algorithms

`forecast`

estimates unconditional forecasts using the equation$${\widehat{y}}_{t}={\widehat{\Phi}}_{1}{\widehat{y}}_{t-1}+\mathrm{...}+{\widehat{\Phi}}_{p}{\widehat{y}}_{t-p}+\widehat{c}+\widehat{\delta}t+\widehat{\beta}{x}_{t},$$

where

*t*= 1,...,`numperiods`

.`forecast`

filters a`numperiods`

-by-`numseries`

matrix of zero-valued innovations through`Mdl`

.`forecast`

uses specified presample innovations (`Y0`

or`Tbl1`

) wherever necessary.`forecast`

estimates conditional forecasts using the Kalman filter.`forecast`

represents the VAR model`Mdl`

as a state-space model (`ssm`

model object) without observation error.`forecast`

filters the forecast data`YF`

through the state-space model. At period*t*in the forecast horizon, any unknown response is$${\widehat{y}}_{t}={\widehat{\Phi}}_{1}{\widehat{y}}_{t-1}+\mathrm{...}+{\widehat{\Phi}}_{p}{\widehat{y}}_{t-p}+\widehat{c}+\widehat{\delta}t+\widehat{\beta}{x}_{t},$$

where $${\widehat{y}}_{s},$$

*s*<*t*, is the filtered estimate of*y*from period*s*in the forecast horizon.`forecast`

uses specified presample values in`Y0`

or`Tbl1`

for periods before the forecast horizon.

The way

`forecast`

determines`numpaths`

, the number of paths (pages) in the output argument`Y`

, or the number of paths (columns) in the forecasted response variables in the output argument`Tbl2`

, depends on the forecast type.If you estimate unconditional forecasts, which means you do not specify the

`YF`

name-value argument, or`InSample`

and`ResponseVariables`

name-value arguments,`numpaths`

is the number of paths in the`Y0`

or`Tbl1`

input argument.If you estimate conditional forecasts and the presample data

`Y0`

and future sample data`YF`

, or response variables in`Tbl1`

and`InSample`

have more than one path,`numpaths`

is the fewest number of paths between the presample and future sample response data. Consequently,`forecast`

uses only the first`numpaths`

paths of each response variable for each input.If you estimate conditional forecasts and either

`Y0`

or`YF`

, or response variables in`Tbl1`

or`InSample`

have one path,`numpaths`

is the number of pages in the array with the most pages.`forecast`

uses the variables with one path to produce each output path.

`forecast`

sets the time origin of models that include linear time trends*t*_{0}to`numpreobs`

–`Mdl.P`

(after removing missing values), where`numpreobs`

is the number of presample observations. Therefore, the times in the trend component are*t*=*t*_{0}+ 1,*t*_{0}+ 2,...,*t*_{0}+`numpreobs`

. This convention is consistent with the default behavior of model estimation in which`estimate`

removes the first`Mdl.P`

responses, reducing the effective sample size. Although`forecast`

explicitly uses the first`Mdl.P`

presample responses in`Y0`

or`Tbl1`

to initialize the model, the total number of usable observations determines*t*_{0}. An observation in`Y0`

is usable if it does not contain a`NaN`

.

## References

[1]
Hamilton, James D. *Time Series Analysis*. Princeton, NJ: Princeton University Press, 1994.

[2]
Johansen, S. *Likelihood-Based Inference in Cointegrated Vector Autoregressive Models*. Oxford: Oxford University Press, 1995.

[3]
Juselius, K. *The Cointegrated VAR Model*. Oxford: Oxford University Press, 2006.

[4]
Lütkepohl, H. *New Introduction to Multiple Time Series Analysis*. Berlin: Springer, 2005.

## Version History

**Introduced in R2017a**