| predict.ardl | R Documentation |
Makes predictions based on fitted ARDL models, extending the
generic function predict for use with
ardl. It is designed to take advantage of lags of the dependent
variable (AR components) from the fitted model and new values of the
independent variable(s) to calculate predictions.
## S3 method for class 'ardl'
predict(object, newdata, ...)
object |
A fitted model of |
newdata |
A time series object ( |
... |
further arguments passed to or from other methods. |
predict.ardl works recursively to calculate predictions based on
y_{t-1}, ..., y_{t-p} values contained within a fitted model, and new
values of x_{T+1}, ..., x_{T+h}, where T denotes the last observation
of t from the original data and h is the number of new
observations that will be used to calculate predictions. These are supplied
through the newdata argument. It is important to note that for a given
prediction \hat{y}_{T+1}, the independent variables provided through
newdata, are expected to follow consecutively from the last observation
x_{T} used to create the model, i.e. x_{T+1}, ..., x_{T+h},
with no gaps. If a time series object is passed to the function, the frequency
and whether the observations follow consecutively will be checked.
predict.ardl returns values for \hat{y}_{T+1}, ...,
\hat{y}_{T+h} equal in length to the number of rows in newdata,
as a vector.
We want to predict \hat{y}_{T+1} given an ARDL(2,2) model:
\hat{y}_{T+1} = Z \boldsymbol{\beta}
where Z is our design matrix and \beta is a vector of our model
coefficients. We need 2 lags for our dependent and independent variables:
y_T, y_{T-1} and X_T, X_{T-1}.
Plus, X_{T+1} (from newdata), which in our design matrix is
equivalent to time t in our original model:
Z =
\left[
\begin{array}{c|cccccc}
& \mathbf{c} & \mathbf{y_{t-1}} & \mathbf{y_{t-2}} & \mathbf{x_t} &
\mathbf{x_{t-1}} & \mathbf{x_{t-2}} \\
\hline
T\!+\!1 & 1 & y_{T} & y_{T-1} & x_{T+1} & x_{T} & x_{T-1}
\end{array}
\right]
We proceed to the next iteration, predicting \hat{y}_{T+2}, using the
previously calculated value of \hat{y}_{T+1}:
Z =
\left[
\begin{array}{c|cccccc}
& \mathbf{c} & \mathbf{y_{t-1}} & \mathbf{y_{t-2}} & \mathbf{x_t} & \mathbf{x_{t-1}} & \mathbf{x_{t-2}} \\
\hline
T\!+\!2 & 1 & y_{T+1} & y_{T} & x_{T+2} & x_{T+1} & x_{T}
\end{array}
\right]
Iteration continues until we've calculated all the necessary values of
\hat{y}_{T+h} for newdata.
Kleanthis Natsiopoulos, klnatsio@gmail.com
Daniel Finnan, dan@custom-made.org.uk
ardl
data(denmark)
## Estimate an ARDL(2,1,2,1,1) model, using a subset of the denmark data
ardl_21211 <- ardl(LRM ~ LRY + LPY + IBO + IDE, data = denmark,
order = c(2,1,2,1,1),
start = "1974 Q1", end = "1986 Q2")
## Make predictions based on the remainder of the denmark data not used in
## training the model
predict_data <- window(denmark, start = "1986 Q3", end = "1987 Q3")
## Drop the dependent variable, since we're predicting it
predict_data <- predict_data[, c("LRY", "LPY", "IBO", "IDE")]
predictions <- predict(ardl_21211, predict_data)
## Estimate a ARDL(4,4,4,4) model with a linear trend and dummies
## Create dummies
d_74Q1_75Q3 <- ifelse(time(denmark) >= "1974 Q1" & time(denmark) <= "1975 Q3", 1, 0)
# Add them to the data
denmark_dums <- cbind(denmark, d_74Q1_75Q3)
## Estimate the model
ardl_4444 <- ardl(LRM ~ LRY + LPY + IBO + trend(LRM) | d_74Q1_75Q3,
data = denmark_dums,
order = c(4,4,4,4),
start = "1974 Q1", end = "1986 Q2")
## Take the remaining data not used in training the model
predict_data <- window(denmark_dums, start = "1986 Q3", end = "1987 Q3")
## Drop the dependent variable
predict_data <- predict_data[, c("LRY", "LPY", "IBO", "d_74Q1_75Q3")]
## Compute the predictions
predictions <- predict(ardl_4444, predict_data)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.