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.
2. Plot the periodic data set.
3. Calculate the next 20 points of the function.
4. Use the predict function to extrapolate the next 20 data points.
5. Add the calculated and the extrapolated data points to the original plot, then compare the results.
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.
2. Plot the linear data set.
3. Calculate and the next 50 points of the function.
4. Use the predict function to extrapolate the next 100 data points.
5. Add the calculated and the extrapolated data points to the original plot, then compare the results.
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.
2. Set the number of prior values.
3. Use function reverse to reverse the order of the original data points then apply predict to the reversed time series.
4. Reverse the vector of results.
5. Plot the extrapolated values and the original time series.
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.