# What is the way to determin how good a sequence will interpolate?

Say I have to sequences of numbers:

$$[5, 10, 14, 21, 27, 31]$$

$$[1, 20, 21, 22, 30, 31]$$

Even though they both get to $31$ by the $6$th element, logic tells me that only the first one is a good candidate for projecting out into the future with a linear interpolation.

What is the way to determine how good a sequence will interpolate?

I guess another way to say this is what is the judge of erraticness in a sequence of numbers?

-
"How much do my data deviate from a proposed formula" is the suject matter of statistics/regression analysis. Retagged accordingly. –  vonbrand Mar 27 '13 at 20:12

First you need some criterion by which you want to compare the two sequences. I take it you want to know which of the two fits a linear progression best. This can be tested with two OLS regressions of the form $$y_i=constant+\beta x_i\text{ or }y_i=\beta x_i,$$ where $y_i$ is the element $i$ of your series and $x_i$ is simply the index $i=1,\ldots,n$. In other words, you fit a linear trend to each of the two sequences. Since both sequences have the same number of elements, you can simply compare the fit with a goodness of fit measure like the residual sum of squares. Whichever sequence has a smaller RSS fits its linear trend better (deviates less, according to the quadratic scoring function). See below for results.

This might not make sense if you want to check whether the two sequences fit a particular linear trend. In that case, you should not fit a trend to the sequence. Instead, you can manually compute the residual sum of squares using the trend you have in mind (square the deviation of the sequence elements from the trend) and compare those.

Now this was all about fitting. If you want to predict future elements of the sequence, then you should first find the best model (which likely generates the data)---this need not be linear. If you have long sequences, you can cut it in half, use the first half for fitting parameters to model candidates, and then the second half to assess the models' predictive power (again using some scoring function).

edit: this is the OLS comparison I suggested above (stata output). The first sequence has better fit as measured by $R^2$ or RSS (this is the fit with constant). In that sense, your intuition is correct.

. reg a indx

Source |       SS       df       MS              Number of obs =       6
-------------+------------------------------           F(  1,     4) =  654.52
Model |  504.914286     1  504.914286           Prob > F      =  0.0000
Residual |  3.08571429     4  .771428571           R-squared     =  0.9939
-------------+------------------------------           Adj R-squared =  0.9924
Total |         508     5       101.6           Root MSE      =  .87831

------------------------------------------------------------------------------
a |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
indx |   5.371429   .2099563    25.58   0.000     4.788497    5.954361
_cons |        -.8   .8176622    -0.98   0.383    -3.070194    1.470194
------------------------------------------------------------------------------

. reg b indx

Source |       SS       df       MS              Number of obs =       6
-------------+------------------------------           F(  1,     4) =   16.30
Model |  468.014286     1  468.014286           Prob > F      =  0.0156
Residual |  114.819048     4  28.7047619           R-squared     =  0.8030
-------------+------------------------------           Adj R-squared =  0.7537
Total |  582.833333     5  116.566667           Root MSE      =  5.3577

------------------------------------------------------------------------------
b |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
indx |   5.171429   1.280731     4.04   0.016     1.615549    8.727308
_cons |   2.733333   4.987731     0.55   0.613    -11.11483    16.58149
------------------------------------------------------------------------------

-
thank you very much –  Aaron Anodide Mar 28 '13 at 0:07