Functions > Data Analysis > Interpolation and Prediction > Example: Linear Prediction 2
  
Example: Linear Prediction 2
Prediction of Periodic Data
Use the predict function to find future values of periodic data sets.
1. Use the sin and cos functions to define a periodic data set.
Click to copy this expression
Click to copy this expression
2. Plot the periodic data set.
Click to copy this expression
3. Calculate the next 20 points of the function.
Click to copy this expression
Click to copy this expression
4. Use the predict function to extrapolate the next 20 data points.
Click to copy this expression
Click to copy this expression
Click to copy this expression
5. Add the calculated and the extrapolated data points to the original plot, then compare the results.
Click to copy this expression
As the plot shows, the predict function works very well on periodic data. This is because it depends on autocorrelation.
Prediction of Linear Data
Use the predict function to find future values of linear data sets.
1. Define a linear data set.
Click to copy this expression
Click to copy this expression
2. Plot the linear data set.
Click to copy this expression
3. Calculate and the next 50 points of the function.
Click to copy this expression
Click to copy this expression
Click to copy this expression
4. Use the predict function to extrapolate the next 100 data points.
Click to copy this expression
Click to copy this expression
Click to copy this expression
5. Add the calculated and the extrapolated data points to the original plot, then compare the results.
Click to copy this expression
Initially, the linear prediction is good. Further on, the predict function forces periodicity. In general, it is not recommended to predict too far ahead.
Estimating Prior Values
The predict function can also be used to estimate prior values of a set of time-series data.
1. Define and plot a time series.
Click to copy this expression
Click to copy this expression
Click to copy this expression
2. Set the number of prior values.
Click to copy this expression
3. Use function reverse to reverse the order of the original data points then apply predict to the reversed time series.
Click to copy this expression
Click to copy this expression
4. Reverse the vector of results.
Click to copy this expression
5. Plot the extrapolated values and the original time series.
Click to copy this expression
Click to copy this expression
Click to copy this expression
Click to copy this expression
The dashed line is drawn between the last extrapolated point and the first data point of the time series as a way to help the user in visualizing the complete set of data points.