Use the predict function to return the next predicted values of a time series.
1. Define a data set of a time series in vector y. The data are assumed to be measured at equal time intervals.
2. Plot the time series.
3. Define the number of previous values to be used by predict to calculate future values and the number of future values that predict should return.
4. Call the predict function to extrapolate future values of the time series.
5. Plot the observed data and the predicted values.
How predict Works
To understand how the function works, define a time-series and the number of previous and future values.
The predict function needs to calculate a weighing factor for each prior value used for the predictions. For n unknowns, the predict function needs n equations to work with. It builds equations from the following prediction model:
where X is the time-series and c is the vector of weighing factors. The weighing factors are calculated by using a technique known as Burg's method:
The predict function can now estimate future values.
These are the same values as those returned by the predict function:
Increasing or decreasing the numbers of points in a time series affect the predicted values returned since predict takes all the X data to calculate the weighing factors used for linear prediction.
Error Messages
The error messages returned by predict are often due to its arguments. In one case, the error message is related to the algorithm itself:
The predicted values cannot be a linear function of all the data points. You can use up to (n - 1) data points:
It is best to choose a value that is not too large relative to the amount of data points.