Functions > Data Analysis > Interpolation and Prediction > Example: Linear Prediction 1
  
Example: Linear Prediction 1
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.
Click to copy this expression
2. Plot the time series.
Click to copy this expression
Click to copy this expression
Click to copy this expression
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.
Click to copy this expression
Click to copy this expression
4. Call the predict function to extrapolate future values of the time series.
Click to copy this expression
5. Plot the observed data and the predicted values.
Click to copy this expression
Click to copy this expression
Click to copy this expression
How predict Works
To understand how the function works, define a time-series and the number of previous and future values.
Click to copy this expression
Click to copy this expression
Click to copy this expression
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:
Click to copy this expression
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:
Click to copy this expression
The predict function can now estimate future values.
Click to copy this expression
Click to copy this expression
Click to copy this expression
Click to copy this expression
Click to copy this expression
These are the same values as those returned by the predict function:
Click to copy this expression
* 
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:
Click to copy this expression
The predicted values cannot be a linear function of all the data points. You can use up to (n - 1) data points:
Click to copy this expression
It is best to choose a value that is not too large relative to the amount of data points.