A shop records its sales every day for a year and ends up with 365 numbers. Busy days may follow busy days, weekends may differ from weekdays, and the level may drift upward over the months. Shuffling the 365 numbers would keep their mean and standard deviation and destroy all of that structure, so treating them as an independent sample of 365 days can be badly misleading. This lesson names the structure in ordered data, trend, seasonality and autocorrelation, defines stationarity, and shows why a standard error that treats ordered observations as independent can be far too small.
Key terms
Time series
Definition A time series is a set of observations of one variable recorded at successive times, written in time order. The times, the spacing between them and the order are part of the data. A series is equally spaced when consecutive observations are a fixed interval apart, such as one hour or one day. Statistically, the series is treated as one realization of a stochastic process , a sequence of random variables, and the process has serial dependence when observations at different times are not independent.
In plain words A time series is one long record of a single process, not a pile of separate draws. Summaries that ignore order, such as a histogram, the mean and the standard deviation, cannot see a pattern over time. A long series is therefore not automatically a large independent sample, and a reading every minute need not bring a new independent piece of information every minute.
Example The sequences and contain the same five values. Both have mean and sample standard deviation , and their histograms are identical. As time series they differ, since the first rises steadily and the second zigzags around .
Trend
Definition A trend is a sustained change in the level of a series over time, the slowly varying part of its mean. It may be roughly linear over an interval, curved, or broken by a structural change such as a new instrument. In the additive decomposition
the trend component is , the seasonal component is and is the irregular remainder.
In plain words The trend says where the level is heading over many periods. Individual steps can go against it, because seasonal effects and noise are added on top. A trend describes the data without explaining them, and a change in level that begins at some date is not by itself evidence that an event on that date caused it.
Example Twelve constructed readings were built as for , with trend and seasonal offsets that repeat every four steps. Written one cycle per row, they are
| Cycle | Position 1 | Position 2 | Position 3 | Position 4 |
|---|---|---|---|---|
| Steps 1 to 4 | 19 | 23 | 22 | 26 |
| Steps 5 to 8 | 23 | 27 | 26 | 30 |
| Steps 9 to 12 | 27 | 31 | 30 | 34 |
The cycle averages are , and , rising by per cycle, one unit per step. Yet the reading falls from to between steps 2 and 3, and from to between steps 4 and 5. Here the trend is known because the data were built from it. With real data the trend must be estimated under a model, and its separation from the other components can be uncertain.
Seasonality
Definition Seasonality is a pattern that repeats with a fixed, known period of observation steps. In an additive model the seasonal component satisfies for every , usually with so that the seasonal effects do not shift the level. The period comes from the measurement frequency and the process, for example for a pattern within the day in hourly data, for a weekly pattern in daily data and for a yearly pattern in monthly data. Rises and falls without a fixed period, such as business cycles, are not seasonality in this sense.
In plain words Seasonality calls for comparing like with like. The same position in different cycles, the same weekday or the same month, is the fair comparison, and the seasonal difference removes a fixed additive seasonal pattern. When the seasonal swings grow with the level, a multiplicative model, or an additive model for the logarithm of a positive series, may describe them better.
Example In the constructed series the offsets are , which sum to , and the period is steps. Each column of the table above holds one seasonal position, and down each column the values rise by exactly . Since , for
The comparison of neighboring readings mixes the trend with the change in seasonal position, while the comparison four steps apart isolates the trend.
Lag
Definition In an equally spaced series, lag pairs each observation with the observation taken steps earlier, so the time separation is times the spacing. A lag- plot shows the points for . For irregularly spaced observations a fixed number of rows need not correspond to a fixed time separation.
In plain words A lag counts observation steps. With hourly data lag means four hours, and with daily data it means four days. The pairs in a lag plot overlap, because an observation can appear in two pairs, once as the earlier value and once as the later one. The points of a lag plot are therefore not independently sampled pairs.
Example The twelve constructed readings give pairs at lag and pairs at lag . The lag-4 pairs are , , , , , , and , and in each of them the later value is the earlier value plus . The reading at step 5 appears twice, as the later value of the first pair and the earlier value of the fifth.
Autocorrelation
Definition For a weakly stationary process, as defined under stationarity below, with autocovariance and variance , the lag- autocorrelation is
which does not depend on . The autocorrelation function, or ACF, is the sequence . A common sample version, used on this page, centers at the overall mean and divides by the total sum of squares,
Software packages use several conventions, so the one used should be stated. Autocorrelation measures linear association only, so autocorrelations of at every lag do not in general imply independence.
In plain words A positive lag-1 autocorrelation means that neighbors tend to lie on the same side of the mean, and a negative one means that the series tends to alternate. A seasonal pattern tends to produce peaks in the sample ACF at multiples of the period, and a trend tends to make sample autocorrelations positive and slow to die out. The sample ACF has sampling noise, especially in short series, and its shape is a clue for building a model, not a test that singles out one correct model.
Example For the mean is and the deviations are , whose squares add to . The products of neighbors are , which add to , so
For the deviations are , the products of neighbors are and . The values and the denominator are the same, and only the order changed. Five points are far too few to estimate a process autocorrelation, and a steadily rising sequence gives no reason to assume the stationarity on which is defined.
Stationarity
Definition A stochastic process with finite variances is weakly stationary if for all times and lags
with , and not depending on . Strict stationarity asks that the joint distribution of any stretch of the process is unchanged by a shift in time, which implies weak stationarity when the variances are finite. The difference and the seasonal difference are common ways to build a series that is closer to stationary, and they change the variable under study from levels to changes. For a weakly stationary process with and autocorrelations , the mean of consecutive observations has
where the weight reflects that only pairs of the observations are steps apart.
In plain words Stationarity means that the probability rules of the process stay the same over time, and in the weak sense only its mean, variance and autocovariances have to. It does not mean that the observed values are constant, and it does not mean that they are independent. A stationary process can fluctuate widely and be strongly correlated from one step to the next. A trend in the mean, a seasonal mean or a variance that changes over time each rule it out. Stationarity is an assumption about the process, so a plot or a test can make it more or less plausible but cannot prove it, and subtracting a fitted line can leave seasonality, changing variance or breaks behind. When and every autocorrelation is positive, the factor exceeds and the independent formula understates the variance of the mean.
Example Take a declared stationary model with and , not fitted to any data. For consecutive observations the factor is , so
while the independent formula gives . Dividing by the factor gives an effective sample size of about , a variance comparison under this model rather than a count of observations. For with the factor approaches as grows, which is here. The constructed seasonal series above is not stationary, since its mean changes with .
Check yourself
- For the series , compute and with the convention of this page.
Show the answer
The mean is , the deviations are and the denominator is . The lag-1 products are , which add to , so . The lag-2 products are , and , which add to , so . This series alternates around its mean, which gives a negative lag-1 and a positive lag-2 autocorrelation. With five values these are descriptive numbers, not estimates of a process autocorrelation.
- Suppose the twelve constructed readings come from a process, and a new operating instruction is introduced right after step 8. The mean of steps 9 to 12 is and the mean of steps 5 to 8 is . Does the increase of show that the instruction raised the readings? What does the fall from at step 8 to at step 9 show?
Show the answer
The increase does not show an effect of the instruction. The series was built with a trend of one unit per step, so every block of four steps averages more than the block before it, as the steps 1 to 4 and 5 to 8 already show without any instruction. The fall from to is not evidence of a harmful effect either. It is the move from seasonal position 4, with offset , to position 1, with offset , partly made up by one step of trend.
A before-after comparison in one series cannot separate an intervention from an existing trend, the seasonal timing, other changes at the same date and random variation. Separating them needs more, for example a model of the trend and seasonality checked on the data before the change, a comparison series that did not receive the instruction, or a randomized design.
- A sensor is read once a minute for two hours. The readings drift upward, neighboring readings are very similar, and an analyst reports a narrow confidence interval for the mean using the standard error . Give two reasons to doubt the interval. What does lag 5 mean here, and would subtracting a fitted line prove that what remains is stationary? Finally, suppose instead that the readings had no drift and followed a stationary model with . Roughly how many independent readings are the 120 worth for estimating the mean?
Show the answer
First, the upward drift means the mean changes over the two hours, so it is unclear which mean the interval is supposed to estimate. Second, very similar neighbors suggest positive autocorrelation, and then tends to understate the standard error of the average because it ignores the covariance terms.
The readings are equally spaced one minute apart, so lag 5 pairs readings taken five minutes apart. Subtracting a fitted line does not prove stationarity. It can leave autocorrelation, changing variance, a recurring pattern or a break, so the remainder still has to be examined and stationarity remains an assumption.
With the factor approaches , so the effective sample size is roughly . The exact factor for is about , which gives about . The standard error of the mean is about times the value for independent readings.