% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/predict.R
\name{predict.ardl}
\alias{predict.ardl}
\title{Predict method for ARDL model fits}
\usage{
\method{predict}{ardl}(object, newdata, ...)
}
\arguments{
\item{object}{A fitted model of \code{\link[base]{class}} \code{\link{ardl}}.}

\item{newdata}{A time series object (\code{\link[stats]{ts}},
\code{\link[zoo]{zoo}}, \code{\link[zoo]{zooreg}}) or a
\code{\link[base]{data.frame}} containing the new values of the independent
variables \eqn{x} required to make predictions.}

\item{...}{further arguments passed to or from other methods.}
}
\value{
\code{predict.ardl} returns values for \eqn{\hat{y}_{T+1}, ...,
\hat{y}_{T+h}} equal in length to the number of rows in \code{newdata},
as a \code{\link[base]{vector}}.
}
\description{
Makes predictions based on fitted ARDL models, extending the
generic function \code{\link[stats]{predict}} for use with
\code{\link{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.
}
\details{
\code{predict.ardl} works recursively to calculate predictions based on
\eqn{y_{t-1}, ..., y_{t-p}} values contained within a fitted model, and new
values of \eqn{x_{T+1}, ..., x_{T+h}}, where \eqn{T} denotes the last observation
of \eqn{t} from the original data and \eqn{h} is the number of new
observations that will be used to calculate predictions. These are supplied
through the \code{newdata} argument. It is important to note that for a given
prediction \eqn{\hat{y}_{T+1}}, the independent variables provided through
\code{newdata}, are expected to follow consecutively from the last observation
\eqn{x_{T}} used to create the model, i.e. \eqn{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.
}
\section{Calculation example}{


We want to predict \eqn{\hat{y}_{T+1}} given an \eqn{ARDL(2,2)} model:

\deqn{
     \hat{y}_{T+1} = Z \boldsymbol{\beta}
}
where \eqn{Z} is our design matrix and \eqn{\beta} is a vector of our model
coefficients. We need 2 lags for our dependent and independent variables:
\eqn{y_T}, \eqn{y_{T-1}} and \eqn{X_T}, \eqn{X_{T-1}}.
Plus, \eqn{X_{T+1}} (from \code{newdata}), which in our design matrix is
equivalent to time \eqn{t} in our original model:
\deqn{
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 \eqn{\hat{y}_{T+2}}, using the
previously calculated value of \eqn{\hat{y}_{T+1}}:
\deqn{
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
\eqn{\hat{y}_{T+h}} for \code{newdata}.
}

\examples{
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)

}
\seealso{
\code{\link{ardl}}
}
\author{
Kleanthis Natsiopoulos, \email{klnatsio@gmail.com}

Daniel Finnan, \email{dan@custom-made.org.uk}
}
\keyword{models}
\keyword{ts}
