Home > Articles > Home & Office Computing > Microsoft Applications

Predictive Analytics with Microsoft Excel: Working with Seasonal Time Series

  • Print
  • + Share This
This chapter from More Predictive Analytics: Microsoft Excel takes a look at how to decompose a time series so that you can see how its seasonality operates apart from its trend (if any).
This chapter is from the book

Matters get incrementally more complicated when you have a time series that’s characterized in part by seasonality: the tendency of its level to rise and fall in accordance with the passing of the seasons. We use the term season in a more general sense than its everyday meaning of the year’s four seasons. In the context of predictive analytics, a season can be a day if patterns repeat weekly, or a year in terms of presidential election cycles, or just about anything in between. An eight-hour shift in a hospital can represent a season.

This chapter takes a look at how to decompose a time series so that you can see how its seasonality operates apart from its trend (if any). As you might expect from the material in Chapters 3 and 4, several approaches are available to you.

Simple Seasonal Averages

The use of simple seasonal averages to model a time series can sometimes provide you with a fairly crude model for the data. But the approach pays attention to the seasons in the data set, and it can easily be much more accurate as a forecasting technique than simple exponential smoothing when the seasonality is pronounced. Certainly it serves as a useful introduction to some of the procedures used with time series that are both seasonal and trended, so have a look at the example in Figure 5.1.

Figure 5.1

Figure 5.1 With a horizontal model, simple averages result in forecasts that are no more than seasonal means.

The data and chart shown in Figure 5.1 represent the average number of daily hits to a website that caters to fans of the National Football League. Each observation in column D represents the average number of hits per day in each of four quarters across a five-year time span.

Identifying a Seasonal Pattern

You can tell from the averages in the range G2:G5 that a distinct quarterly effect is taking place. The largest average number of hits occurs during fall and winter, when the main 16 games and the playoffs are scheduled. Interest, as measured by average daily hits, declines during the spring and summer months.

The charted data series includes data labels showing which quarter each data point belongs to. The chart echoes the message of the averages in G2:G5: Quarters 1 and 4 repeatedly get the most hits. There’s clear seasonality in this data set.

Calculating Seasonal Indexes

After you’ve decided that a time series has a seasonal component, you’d like to quantify the size of the effect. The averages shown in Figure 5.2 represent how the simple-averages method goes about that task.

Figure 5.2

Figure 5.2 Combine the grand mean with the seasonal averages to get the seasonal indexes.

In Figure 5.2, you get additive seasonal indexes in the range G10:G13 by subtracting the grand mean in cell G7 from each seasonal average in G2:G5. The result is the “effect” of being in Quarter 1, that of being in Quarter 2, and so on. If a given month is in Quarter 1, you expect it to have 99.65 more average daily hits than the grand mean of 140.35 hits per day.

This information gives you a sense of how important it is to be in a given season. Suppose that you own the web site in question and you want to sell advertising space on it. You can surely ask a higher price of advertisers during the first and fourth quarters than during the second and third. More to the point, you can likely charge twice as much during the first quarter than during either the second or the third.

With the seasonal indexes in hand, you’re also in a position to calculate seasonal adjustments. For example, still in Figure 5.2, the seasonally adjusted values for each quarter in 2005 appear in G16:G19. They’re calculated by subtracting the index from the associated quarterly measurement.

Notice that in the normal course of events from 2001 to 2005, you expect the second quarter’s results to lag behind the first quarter’s results by 133.6 (that is, 99.65 minus –33.95). But in both 2004 and 2005, the seasonally adjusted results for the second quarter exceed those for the first quarter. That outcome might well prompt you to ask what has changed in the final two years that reverses the relationship between the seasonally adjusted results for the first two quarters. (I don’t pursue that issue here. I bring it up to suggest that you often want to have a look at both the observed and the seasonally adjusted figures.)

Forecasting from Simple Seasonal Averages: No Trend

Although the method of simple averages is—as I said earlier—crude, it can be much more accurate than the more sophisticated alternative of exponential smoothing, particularly when the seasonal effects are pronounced and reliable.

When the time series is untrended, as is the case with the example this section has discussed, the simple seasonal forecasts are nothing more than the seasonal averages. When the series is not trending either up or down, your best estimate of the value for the next season is that season’s historic average. See Figure 5.3.

Figure 5.3

Figure 5.3 Combine the grand mean with the seasonal averages to get the seasonal indexes.

In the chart in Figure 5.3, the dashed line represents the forecasts from simple smoothing. The two solid lines represent the actual seasonal observations and the seasonal averages. Notice that the seasonal averages track the actual seasonal observations quite closely—much more closely than do the smoothed forecasts. You can see how much more closely from the two RMSEs in cells F23 and H23. The RMSE for the seasonal averages is just a little more than a third of the RMSE for the smoothed forecasts.

You can chalk that up to the size of the seasonal effects as well as their consistency:

  • Suppose, for example, that the difference between the average first and second quarters were 35.0 instead of 133.6 (which is the difference between cells G2 and G3 in Figure 5.2). Then, in a smoothing context, the actual value for Quarter 1 would be a much better predictor of the value for Quarter 2 than is the case with this time series. And exponential smoothing can rely heavily on the value of the current observation for its forecast of the next period. If the smoothing constant is set at 1.0, exponential smoothing resolves to naïve forecasting and the forecast always equals the prior actual.
  • The fact that the size of each seasonal swing is so consistent from quarter to quarter means that the simple seasonal averages are reliable forecasts: No actual quarterly observation departs very far from the overall seasonal average.

Simple Seasonal Averages with Trend

The use of simple seasonal averages with a trended series has some real drawbacks, and I’m tempted to suggest that we ignore it and move on to meatier topics. But it’s possible that you’ll run into situations in which someone has used this method and then it won’t hurt to know both how it works and why there are better choices.

Any method of dealing with seasonality in a trended series must deal with the fundamental problem of disentangling the effect of the trend from that of the seasonality. Seasonality tends to obscure trend, and vice versa. See Figure 5.4.

Figure 5.4

Figure 5.4 The presence of trend complicates the calculation of seasonal effects.

The fact that the trend in the series is upward over time means that simply averaging each season’s observations, as was done in the no-trend case, confounds the general trend with the seasonal variation. The usual idea is to account for the trend separately from the seasonal effects. You could quantify the trend and subtract its effect from the observed data. The result is an untrended series that retains the seasonal variation. It could be handled in the same fashion as I illustrated earlier in this chapter.

Calculating the Mean for Each Year

One way to detrend the data (and other ways will doubtless occur to you) is to calculate the trend based on yearly averages rather than quarterly data. The idea is that the yearly average is insensitive to the seasonal effects. That is, if you subtract a year’s mean from the value for each of its quarters, the sum (and thus the average) of the four quarterly effects is precisely zero. So a trend calculated using the yearly averages is unaffected by the seasonal variations. This calculation appears in Figure 5.5.

Figure 5.5

Figure 5.5 This method now imposes linear regression on the simple averages.

The first step in detrending the data is to get the average daily hits for each year. That’s done in the range H3:H7 in Figure 5.5. The formula in cell H3, for example, is =AVERAGE(D3:D6).

Calculating the Trend Based on Annual Means

With the yearly averages in hand, you’re in a position to calculate their trend. That’s managed by using LINEST() in the range I3:J7, using this array formula:


The point of this exercise is to quantify the year-to-year trend, and LINEST() does that for you in cell I3. That cell contains the regression coefficient for the x-values. Multiply 106.08 by 1; then by 2; then by 3, 4, and 5; and add to each result the intercept of 84.63. Although that gets you annual forecasts, the important point for this procedure is the value of the coefficient 106.08, which quantifies the annual trend.

Prorating the Trend Across Seasons

The simple-averages method of dealing with a trended, seasonal series such as this one continues by dividing the trend by the number of periods in the encompassing period to get a per-period trend. Here, the number of periods per year is four—we’re working with quarterly data—so we divide 106.08 by 4 to estimate the trend per quarter at 26.5.

The procedure uses that periodic trend by subtracting it from the average periodic result. The purpose is to remove the effect of the annual trend from the seasonal effects. First, though, we need to calculate the average result across all five years for Period 1, for Period 2 and so on. To do that, it helps to rearrange the list of actual quarterly hits, shown in the range D3:D22 of Figure 5.5, into a matrix of five years by four quarters, shown in the range G11:J15. Notice that the values in that matrix correspond to the list in column D.

With the data arranged in that fashion, it’s easy to calculate the average quarterly value across the five years in the data set. That’s done in the range G18:J18.

The effect of the trend returned by LINEST() appears in the range G19:J19. The starting value for each year is the observed mean daily hits for the first quarter, so we make no adjustment for the first quarter. One quarter’s worth of trend, or 26.5, is subtracted from the second quarter’s mean hits, resulting in an adjusted second-quarter value of 329.9 (see cell H21, Figure 5.5). Two quarters’ worth of trend, 2 × 26.5 or 53 in cell I19, is subtracted from the third quarter’s mean to get an adjusted third-quarter value of 282.6 in cell I21. And similarly for the fourth quarter, subtracting three quarters of trend from 454.4 to get 374.8 in cell J21.

Converting the Adjusted Seasonal Means to Seasonal Effects

Per the logic of this method, the values shown in rows 20–21 of Figure 5.5 are the average quarterly results for each of four quarters, with the effect of the general upward trend in the data set removed. (Rows 20 and 21 are merged in columns G through J.) With their trend out of the way, we can convert those figures to estimates of seasonal effects: the result of being in the first quarter, in the second quarter, and so on. To get those effects, start by calculating the grand mean of the adjusted quarterly means. That adjusted grand mean appears in cell I23.

The analysis continues in Figure 5.6.

Figure 5.6

Figure 5.6 The quarterly effects, or indexes, are used to deseasonalize the observed quarterlies.

Figure 5.6 repeats the quarterly adjustments and the adjusted grand mean from the bottom of Figure 5.5. They are combined to determine the quarterly indexes (which you can also think of as seasonal effects). For example, the formula in cell D8 is as follows:


It returns –33.2. That’s the effect of being in the second quarter, vis-à-vis the grand mean: With respect to the grand mean, we can expect a result that belongs to the second quarter to fall below the grand mean by 33.2 units.

Applying the Seasonal Effects to the Observed Quarterlies

To recap: Thus far, we’ve quantified the annual trend in the data via regression and divided that trend by 4 to prorate it to a quarterly value. Picking up in Figure 5.6, we adjusted the mean for each quarter (in C3:F3) by subtracting the prorated trends in C4:F4. The result is a detrended estimate of the mean for each quarter, regardless of the year in which the quarter takes place, in C5:F5. We subtracted the adjusted grand mean, in cell G5, from the adjusted quarterly means in C5:F5. That converts each quarter’s mean to a measure of the effect of each quarter relative to the adjusted grand mean. Those are the seasonal indexes or effects in C8:F8.

Next we remove the seasonal effects from the observed quarterlies. As shown in Figure 5.6, you do so by subtracting the quarterly indexes in C8:F8 from the corresponding values in C12:F16. And the easiest way to do that is to enter this formula in cell C20:


Note the single dollar sign before the 8 in the reference to C$8. That’s a mixed reference: partly relative and partly absolute. The dollar sign anchors the reference to the eighth row, but the column portion of the reference is free to vary.

Therefore, after the latter formula is entered in cell C20, you can click on the cell’s selection handle (the small square in the lower-right corner of a selected cell) and drag right into cell F20. The addresses adjust as you drag right and you wind up with the values, with the seasonal effects removed, for year 2001 in C20:F20. Select that range of four cells and use the multiple selection’s handle, now in F20, to drag down into row 24. So doing fills the remainder of the matrix.

I have charted those seasonally adjusted values in Figure 5.6. Compare that chart to the chart in Figure 5.4. Notice in Figure 5.6 that although the deseasonalized values do not lie precisely on a straight line, much of the seasonal effect has been removed.

Regressing the Deseasonalized Quarterlies onto the Time Periods

The next step is to create forecasts from the seasonally adjusted, trended data in Figure 5.6, cells C20:F24, and at this point you have several alternatives available. You could use the differencing approach combined with simple exponential smoothing that was discussed in Chapter 3, “Working with Trended Time Series.” You could also use Holt’s approach to smoothing trended series, discussed in both Chapter 3 and Chapter 4, “Initializing Forecasts.” Both methods put you in a position to create a one-step-ahead forecast, to which you would add the corresponding seasonal index.

Another approach, which I’ll use here, first puts the trended data through another instance of linear regression and then adds the seasonal index. See Figure 5.7.

Figure 5.7

Figure 5.7 The first true forecast is in row 25.

Figure 5.7 returns the deseasonalized quarterly means from the tabular arrangement in C20:F24 of Figure 5.6 to the list arrangement in the range C5:C24 of Figure 5.7.

We could use LINEST() in conjunction with the data in B5:C24 in Figure 5.7 to calculate the regression equation’s intercept and coefficient; then, we could multiply the coefficient by each value in column B, and add the intercept to each product, to create the forecasts in column D. But although LINEST() returns useful information other than the coefficient and intercept, TREND() is a faster way to get the forecasts, and I use it in Figure 5.7.

The range D5:D24 contains the forecasts that result from regressing the deseasonalized quarterly figures in C5:C24 onto the period numbers in B5:B24. The array formula used in D5:D24 is this:


That set of results reflects the effect of the general upward trend in the time series. Because the values that TREND() is forecasting from have been deseasonalized, it remains to add the seasonal effects, also known as seasonal indexes, back in to the trended forecast.

Adding the Seasonal Indexes Back In

The seasonal indexes, calculated in Figure 5.6, are provided in Figure 5.7, first in the range C2:F2 and then repeatedly in the range E5:E8, E9:E12, and so on. The reseasonalized forecasts are placed in F5:F24 by adding the seasonal effects in column E to the trend forecasts in column D.

To get the one-step-ahead forecast in cell F25 of Figure 5.7, the value of t for the next period goes into cell B25. The following formula is entered in cell D25:


It instructs Excel to calculate the regression equation that forecasts values in the range C5:C24 from those in B5:B24, and apply that equation to the new x-value in cell B25.

The appropriate seasonal index is placed in cell E25, and the sum of D25 and E25 is placed in F25 as the first true forecast of the trended and seasonal time series.

You’ll find the entire set of deseasonalized quarterlies and the forecasts charted in Figure 5.8.

Figure 5.8

Figure 5.8 The seasonal effects are returned to the forecasts.

Evaluating Simple Averages

The approach to dealing with a seasonal time series, discussed in several prior sections, has some intuitive appeal. The basic idea seems straightforward:

  1. Calculate an annual trend by regressing annual means against a measure of time periods.
  2. Divide the annual trend among the periods within the year.
  3. Subtract the apportioned trend from the periodic effects to get adjusted effects.
  4. Subtract the adjusted effects from the actual measures to deseasonalize the time series.
  5. Create forecasts from the deseasonalized series, and add the adjusted seasonal effects back in.

My own view is that several problems weaken the approach, and I would not have included it in this book except that you are likely to encounter it and therefore should be familiar with it. And it provides a useful springboard to discuss some concept and procedures found in other, stronger approaches.

First, there’s the issue (about which I complained earlier in this chapter) regarding the very small sample size for the regression of annual means onto consecutive integers that identify each year. Even with only one predictor, as few as 10 observations is really scraping the bottom of the barrel. At the very least you should look at the resulting R2 adjusted for shrinkage and probably recalculate the standard error of estimate accordingly.

It’s true that the stronger the correlation in the population, the smaller the sample you can get away with. But working with quarters within years, you’re fortunate to find as many as 10 years’ worth of consecutive quarterly observations, each measured in the same way across that span of time.

I’m not persuaded that the answer to the problematic up-and-down pattern you find within a year (see the chart in Figure 5.4) is to average out the peaks and valleys and get a trend estimate from the annual means. Certainly it’s one answer to that problem, but, as you’ll see, there’s a much stronger method of segregating the seasonal effects from an underlying trend, accounting for them both, and forecasting accordingly. I’ll cover that method later in this chapter, in the “Linear Regression with Coded Vectors” section.

Furthermore, there’s no foundation in theory for distributing the annual trend evenly among the periods that compose the year. It’s true that linear regression does something similar when it places its forecasts on a straight line. But there’s a huge gulf between making a fundamental assumption because the analytic model can’t otherwise handle the data, and accepting a flawed outcome whose flaws—errors in the forecasts—can be measured and evaluated.

That said, let’s move on to the use of moving averages instead of simple averages as a way of dealing with seasonality.

  • + Share This
  • 🔖 Save To Your Account