You are on page 1of 10

Time Series Analysis This (not surprisingly) concerns the analysis of data collected over time ...

weekly values, monthly values, quarterly values, yearly values, etc. Usually the intent is to discern whether there is some pattern in the values collected to date, with the intention of short term forecasting (to use as the basis of business decisions). We will write t response of interest at time = t y (we usually think of these as equally spaced in clock time). Standard analyses of business time series involve: smoothing/trend assessment 1)assessment of/accounting for seasonality 2) assessment of/exploiting "serial correlation" 3) ectively done on a scale where the "local" variation These are usually/most e is approximately constant. t y in Smoothing Time Series There are various fairly simple smoothing/averaging methods. Two are "ordinary moving averages" and "exponentially weighted moving averages."periods, k For a "span" of Ordinary Moving Averages t moving average through time = et y = 1 k t y + +2 t y +1 t y +t y k ects are expected, it is standard to use Where seasonal e number of periods per cycle = k These weight observations less Exponentially Weighted Moving Averages heavily as one moves back in time from the current period. They are typically computed "recursively" as t exponentially weighted moving average at time = et y 1e t y ) w +(1 t wy =ey( 1 t is the EWMA from the previous period and the current EWMA is a compromise between the previous EWMA and the current observation.) 1y = e . 1y One must start this recursion somewhere and its common to take smooths so much = 0 w does no smoothing, while = 1 w Notice that rst). that the EWMA never changes (i.e. all the values are equal to the Table 13.1 (page 13-5) of the text gives quarterly retail Exercise/Example sales for JC Penney, 1996-2001 (in millions of dollars). "By hand" 1) using nd ordinary moving averages for periods 5 through 8, then 2) using = 4 k nd the exponentially weighted moving average values for those , 3. = w (e.g.) periods.EWMA 3. = w MA = 4 k Span t ty 4452 4452 1

7(4452) . 3(4507) + . 4469 = 4507 2 7(4469) . 3(5537) + . 4789 = 5537 3 5663 = 8157 4 1 4 4452 + 4507 +5537 + 8157 ! 7(4789) . 3(8157) + . 5799 = 6481 5 6420 6 7208 7 9509 8 MA values for the JC = 4 k A plot of both the original time series and the Penney data is in Figure 13.13, page 13-28 of the text. Here is a JMP "Overlay Plot" version of this picture and an indication of how you can get JMP to make the MAs.MA Series = 4 k Figure 1: JC Penney Sales andFigure 2: JMP "Column Formula" for JC Penney MAs Computation of EWMAs in JMP doesnt appear to be simple. Figure 13.15 ect of erent data set) shows the e on page 13-32 of the text (that uses a di on how much smoothing is done. The most jagged plot is the w changing EWMA plot is smoother. 5. = w ). The (purple) 0. = 1 w (red) raw data plot ( plot is smoothest. Here is a plot of 3 EWMA series for 1. = w The (black) the JC Penney sales data.Figure 3: EWMAs for JC Penney Sales DataThere are other more sophisticated smoothing methods available in statistical software. JMP provides "splines." These are available using the "Fit Y by X" JMP Cubic Spline Smoothers ness knob" that lets one adjust how procedure in JMP. They have a "sti t much "wiggling" the smoothed curve can do. Here are several splines ness knob" is the parameter " to the JC Penney sales data. The "sti ".Figure 4: Splines Fit to the JC Penney DataJMP will store the smoothed values obtained from these spline smoothers (just as it will store predicted values from regressions) in the original data table, if one clicks on the appropriate red triangle and chooses that option. Typically one wants to "smooth" a time series in order to make forecasts/projections into the future. The MA, EWMA, and spline smoothers dont really provide A +1 t to the next period, period et y forecasts beyond projecting a current value . possibility for smoothing that provides forecasts other than a current smoothed " vari- x t a simple curve to the series using regression, where the " value is to

). It is particularly ,... )2 ,y (2 , )1 ,y (1 " (that is, the data vectors are t able is " t "low order" polynomials (lines, parabolas, etc.) to such data using easy to JMP. These provide extrapolations beyond the end of the data set. These are JMP Fitting of (Low Order) Polynomial Trends to Time Series again conveniently available using the "Fit Y by X" procedure in JMP. (Conceptually, one could also use the multiple regression procedure "Fit But well t Model" after adding columns to the data table for powers of . use the more elegant "Fit Y by X" method.) Below is a JMP graphic for linear and quadratic (1st and second order polynots to the JC Penney time series. NOTICE that the extrapolations to a mial) tted erent! The two 25th period from these two polynomials will be quite di equations are t 75261 . 2174 + 118 . = 5903 t y and 5) . 12 t 4274932( . 9 t 75261 . 9514 + 118 . = 6354 t y 2 and by clicking on the appropriate red triangles (next to the "Linear Fit" or "Polynomial Fit") one can save the predicted values into the data table. (If onetted equation for formula uses the "Fit Model" procedure, one can save the and get JMP to automatically compute forecasts into the future by adding rows s in them.) t to the data table with hypotheticalFigure 5: JMP Fit of Linear and Parabolic Trends to the JC Penney Datatted polynomials As one moves from a line, to a parabola, to a cubic, etc., will be allowed to be more and more wiggly, doing a better and better job ng less and less believable in terms of of hitting the plotted points, but becomi forecasts. The happiest circumstance is that where a simple straight line/linear trend seems to provide an adequate summary of the main movement of the time series. Compute "by hand" the linear and quadratic forecasts of Exercise/Example (the sales for the period immediately after the end of the data set) for the 25 y tted equations. JC Penney sales based on the JMP erent) forecasts are These (quite di 75261(25) . 2174 + 118 . = 5903 25 y = 8872and 5) . 12 4274932(25 . 9 75261(25) . 9514 + 118 . = 6354 25 y 2 = 7851

Accounting for/Adjusting for Seasonality t to the JC Penney data misses the seasonality in the data. The linear trend rst 3 quarters Mostly, the straight line in Figure 5 "over-predicts" in the = t of each year and "under-predicts" in the 4th quarter of each year. ( are "sec- 22 , 18 , 14 , 10 , 6 , = 2 t rst quarter" periods, are " 21 , 17 , 13 , 9,5,1 ond quarter" periods, etc.) It is well known that retail sales are typically best in the 4th quarter, where the Christmas season spurs consumer buying.It makes sense in the analysis of business and economic time series to try to ects. Here well adjust smoothed values (and forecasts) in light of seasonal e consider several ways of doing this. One ects Simple Arithmetic and "Additive" Adjustment for Seasonal E simple way of trying to account for seasonality is to look at all periods of a given type (e.g. 1st quarter periods where data are quarterly, or all June gures where data are monthly) and compute an average deviation of the tted values in those periods. original time series from the smoothed or to smoothed values or forecasts from a added That average can then be smooth curve in order to account for seasonality. ects Simple Arithmetic and "Multiplicative" Adjustment for Seasonal E A second simple way of trying to account for seasonality is to look at all periods of a given type (e.g. 1st quarter periods where data are quarterly, orgures where data are monthly) and compute an average ratio of all June tted values in those periods. That the actual values to the smoothed or for smoothed values or forecasts multiplier average can then be used as a from a smooth curve in order to account for seasonality. The table below gives simple computation of "additive" and "multi- Example plicative" seasonality factors for the 1st quarter JC Penney sales, based on the t to the data and pictured in Figure 5. linear trendt y t y t y t t y Period, ty t y 7393 1570 1 4452 6022. 9975 16 5 6481 6497. 9685 217 9 6755 6972. 9855 108 13 7339 7447. 9503 394 17 7528 7922. 8958 875 21 7522 8397. 5.5369 3180 is t y t y Then note that the average 3180 6 530 = is t y/t y and the average 5369 . 5

6 9228 . =t to the JC Penney data could be tted values or forecasts from the line So For example, 9228 . or multiplication by 530 addition of adjusted by either . rst period after the end of the data in hand the forecast for period 25 (the This could be . 8872 t in Figure 5 alone is rst quarter) from the linear and a adjusted for the seasonality as either 530) = 8342 = 8872 + ( 25 y (making use of an "additive" seasonality adjustment) or as 9228) = 8187 . = 8872( 25 y (making use of a "multiplicative" seasonality adjustment). tted values from The table below gives the 4th quarter values and Exercise t to the JC Penney data. Finish the calculations, get additive and the line multiplicative seasonality factors, and use them to make 4th quarter forecastsand the linear = 28 t for the year following the end of the data (this is period 75261(28) = 9228) . 2174 + 118 . = 5903 28 y t alone projects sales of . t y t y t y t t y Period, ty t y 1.2789 1779 4 8157 6378 1.3876 2656 8 9509 6853 1.2380 1744 12 9072 7328 16 9661 7803 20 9573 8278 24 9542 8753 Making an additive adjustment = 9228+( ) = 28 yand making a multiplicative adjustment ( )= = 9229 28 y The U.S. government reports values of all kinds of economic time series. In many cases, both "raw" and "seasonally adjusted" versions of these are announced. That is, not only does the government announce a value of "housing starts," but it also announces a value of "seasonally adjusted housing starts." is a multiplicative seasonality factor for the particular month under dis- SF If cussion, this means that both housing starts and = seasonally adjusted housing starts housing starts SF are reported.A more so- Using Dummy Variables in MRL to Account for Seasonality

phisticated and convenient means of creating (additive) seasonality adjustments is to employ dummy variables in a multiple linear regression. dummy 1 k seasons, one can think of making up k That is, if there are t where for period 1 k ,...,x 2 ,x 1 x variables = j,t x ) j is from season t 1 if period 0 otherwise tting (for example) and then using these in a Multiple Linear Regression, ,t 1 k x1 ka + + ,t 2 x2a + ,t 1 x1a + t1b +0b t y gure shows the set-up of a JMP data table for the JC Penney data The next to make use of this idea.Figure 6: JMP Data Table Prepared for Using MLR to Account for Seasonalitychange t y What this method does is let the "intercept" of a linear trend in with period. A "cartoon" showing how this works for the case where there are seasons is below. = 4 kSeasons) = 4 k Figure 7: Cartoon for Dummy Variables and Seasonality (t such a "linear trend plus season dummies" model to time series data, one To can employ a multiple linear regression program. JMPs "Fit Model" routine incorporates such a program. The JMP "Fit Model" dialogue box and resulting report for the JC Penney data follow.Figure 8: JMP "Fit Model" Dialogue Box for Using Dummies to Account for SeasonalityFigure 9: JMP Report for Fitting Linear Trend Plus Seasonal Dummies to the JC Penney Dataare t tted values for 4th quarter periods The report shows that t 541 . 8+99 . = 7858 t y tted values for 1st quarter periods are and, for example, t 541 . 2)) + 99 . 2274 8+( . = (7858 t y rst quarter immediately after the end of the So, for example, 25th period (the data set) sales would be forecast as 541(25) = 8073 . 2+99 . 2274 8. = 7858 25 y and 28th period sales (4th quarter sales for the year after the data ends) would be forecast as 646 , 541(28) = 10 . 8+99 . = 7858 28 yUsing Serial Correlation (in Residuals) To Improve Predictions ect" is all the information carried by a time Sometimes "trend plus seasonal e series. But there are also many cases where yet more information can be exect" forecasts. tracted from the time series to improve on "trend plus seasonal e This involves using residuals t y t y = t e

ect" values for the data in hand). tted trend plus seasonal e the " t y (for xed universe, then there is nothing If residuals look like random draws from a left in them to exploit. But sometimes they exhibit "serial correlation" thatectively predict a given residual from previous ones. That is, allows us to e sometimes the pairs )t ,e 1 t e( show some linear relationship that can be exploited. When that can be done, predictions of future residuals can be added to "trend plus seasonal" forecasts for future periods. Figure 10 shows the residuals and "lag 1 residuals" for the linear trend plus t to the JC Penney sales data in the data table. seasonale and Lag 1 Residuals t e Figure 10: Residuals 1 t for the JC Penney Dataand in the second, t is plotted against t e rst Next, there are 3 plots. In the These plots (in Figures 11 and 12) show the 1 t e is plotted against t e . erent terms. There is a time pattern in the residuals. So same thing in di consecutive residuals tend to be big (positive) together and small (negative) tted model over-predicts early in the data set together. That is because the and late in the data set, and under-predicts in the middle of the data set. That and t versus t y can also be seen if one looks carefully at the third plot of both (Figure 13). t versus t yFigure 11: Plot of Residuals versus Period for the JC Penney Datae versus Lag 1 Residual t e Figure 12: Plot of Residual 1 t for the JC Penney DataFigure 13: JC Penney Sales and Fitted Salesone might predict a residual from the The pattern in Figure 12 suggests that immediately preceding residual using some form of regression. Figure 14 shows tted that using simple linear regression of residuals on lag 1 residuals gives a equation 1 t e 7593887 . 26762 + 0 . = 30 t e Notice that this means that from the last point in the JC Penney data set (period 24) it is possible to predict the residual at period 25, since the residual for period 24 will then be known! That is 24 e 7593887 . 26762 + 0 . = 30 25 eFigure 14: JMP Report for SLR of Residual on Lag 1 ResidualIn fact, this line of thinking suggests that we can improve on the forecast of ) by using = 8073 25 y based solely on linear trend plus seasonal ( 25 y 25 e + 25 y

nal Looking in the data table of Figure 10, we see that the residual in the period of the data set is 74405 . 705 = 24 e and thus that 506 74405) = . 705 7593887( . 26762 + 0 . = 30 25 e so that what might be an improved forecast for period 25 is 506) = 7567 8073 + ( The basic idea of predicting residuals from previous residuals can be carried even further. One can try predicting a residual on the basis of not only theimmediately preceding one, but the immediately preceding two (or more). That e on t e is, it is possible to regress 1 t in order to come up with a way 2 t e and of forecasting a next residual (and therefore improving a trend plus seasonal forecast). We will not show any details here (for one thing because the idea er any improvement in the JC Penney example), but the idea doesnt really o should be clear. Case Study-JMP Airline Passenger Count Data In the "Sample Data" provided with a JMP installation are some time series data. "" gives 12 years worth of monthly airline passenger counts taken from the time series book of Box and Jenkins. (The data are fromJanuary 1949 through December 1960 and the counts are in thousands of passengers.) This data set can be used to admirably demonstrate the topics discussed here. (Although we have made use of the JC Penney data set for illustrative purposes, it is far smaller than the minimum size that should really be used in a time series analysis. The length 144 airline passenger data set is closer to being of practical size for reliable development of forecasts.) Figure 15 is a plot of the raw passenger counts versus time.Figure 15: Airline Passenger Counts Time Series Figure 15 has a feature that is common to many economic time series of any appreciable length. Namely, as time goes on, the "local" or short term variation seems to increase as the general level of the count increases. Besides, it looks like the general trend of count versus time may not be linear, but rather havet and forecast series that dont have some upward curvature. It is far easier to t the raw counts, transform these features. So what we can do is to try to nal and forecast with the transformed series, and then "untransform" to make interpretations. That is, we will analyze the (base 10) logarithms of passenger

counts )t passenger count at period ( 10 = log t y and happily looks "better" than the original series in t y Figure 16 is a plot of tting and forecasting. Figure 15 for purposes ofFigure 16: Logarithms of Passenger Counts series is perhaps to see how a linear trend does t y rst step in analysis of the A )t t, y ( t a line to the at describing the data. We can use JMP to do SLR and values and save the predictions. These can then be plotted using "Overlay Plot" along with the original series to get Figure 17.Series t y Figure 17: Linear Trend Fit toOf course, the linear trend ignores the seasonality in the times series. Since ne 11 monthly indicator variables. But these are monthly data, we could de that would be tedious, and happily the JMP data table (partially pictured in Figure 18) has the month information coded into it in the form of a "nominal" variable "Season." Since "Season" is a "nominal" variable (indicated by the red cap N) if we tell JMPs "Fit Model" routine to use it in a multiple regression, 1 = 11 12 it will automatically use the single nominal variable to create dummy variables for all but one of the values of "Season." That is, we may tted values for the ll in the "Fit Model" dialogue box as in Figure 19 to get "linear trend plus seasonal" model.Figure 18: Partial JMP Data Table for the Airline Passenger DataFigure 19: JMP "FIT Model" Dialogue Box for Linear Trend Plus Seasonal Fittting indicated in Figure 19 is shown in Figure A partial JMP report for the tted values for the linear trend plus seasonal model is shown 20. A plot of the in Figure 21.t y Figure 20: Partial JMP Report for Linear Trend Plus Seasonal Fit toFigure 21: Linear Trend Plus Seasonal Fit to Logarithms of Passenger Countst indicated in Figure 21 is better than the one in Figure 17. Of course, the And the forecasts provided by the regression model can be extended into the that represents the last point in the data set). But = 144 t "future" (beyond there is even more that can be done if one considers the nature of the residuals t y t y = t e t. Figure 22 shows a plot of the residuals from the regression and Figure 23 shows that there is a fair amount of correlation between t versus residuals and lagged residuals. (This is no surprise given the nature of the plot in Figure 22 where "slow" trends in the residuals make ones close together in time similar in value.)for the Log Passenger Counts t Figure 22: Plot of Residuals versusFigure 23: Residuals, Lag 1 Residuals, and Lag 2 Residuals for Log Passenger

CountsIt is possible (by examining regressions of residuals on lagged residuals) to come to the conclusion that in terms of predicting residuals from earlier residuals it ces to simply use the single previous one (nothing important is gained by su using the two previous ones). And in fact, for this problem, an appropriate e on t e prediction equation (coming from SLR of 1 t ) is 1 t e 7918985 . 000153 + 0 . 0 = t e ts/predictions from the linear trend plus sea- This can be used to adjust the sonal model of log counts as t e + t y = t ) adjusted fit ( tted values These are plotted along with the original series and the earlier in Figure 24. There is a small, but clearly discernible improvement in the t y quality of the modeling provided by this adjustment for serial correlation in the residuals., and Adjusted Fitted Values t y Fitted Values ,t y Figure 24: Original Values t e + t y= 145 t Notice then that an adjusted forecast of log passenger count for period (the January/Season 1 following the end of the data set) becomes 0043728(145)) . 037092) + . 0 0899065 + ( . = (2 145 e + 145 y ) 0377583) . 0 7918985( . 000153 + 0 . 0 ( + 65682038 . = 2 gure is (of course) on a log scale. We may "untransform" this value in This order to get a forecast for a passenger count (as opposed to a log passenger count). This is 10 65682038 . 2 = 454 nal plot, that compares the original series of In fact, it is worthwhile to see a counts to the whole set of values 10 t e + t ytted values on the original (count) scale. This is show in that function as Figure 25 (including the value for period 145, whose plotted symbol is larger than the others, and represents a forecast beyond the end of the original data set).10 Figure 25: Plot of Passenger Counts and Final Fitted Values t e + t y (Including ) = 145 t a Forecast for