## Time Series Basics

A time series is a set of points that are ordered in time. Each time point is usually assigned an integer index to indicate its position within the series. For example, you can construct a time series by measuring and computing an average daily temperature. When the outcome of the next point in a time series is unknown, the time series is said to be random or "stochastic" in nature. A simple example would be creating a time series from a sequential set of coin flips with outcomes of either heads or tails. A more practical example is the time series of prices of a given stock.

When the unconditional joint probability distribution of the series does not change with time (it is time-invariant), the stochastic process generating the time series is said to be stationary. Under these circumstances, parameters such as the mean and standard deviation do not change over time. Assuming the same coin for each flip, the coin flip is an example of a stationary process. On the other hand, stock price data is not a stationary process.

This unit aims to use your knowledge of statistics to model time series data for random processes. Even though the outcome of the next time point is unknown, given the time series statistics, it should be possible to make inferences if you can create a model. The concept of a stationary random process is central to statistical model building. Since nonstationary processes require a bit more sophistication than stationary processes, it is important to understand what type of time series is being modeled. Our first step in this direction is to introduce the autoregressive (AR) model. This linear model can be used to estimate current time series values based on known past time series values. Read through this article which introduces the idea behind AR models and additionally explains the autocorrelation function (ACF).

### Overview of Time Series Characteristics

In this lesson, we'll describe some important features that we must consider when describing and modeling a time series. This is meant to be an introductory overview, illustrated by example, and not a complete look at how we model a univariate time series. Here, we'll only consider univariate time series. We'll examine relationships between two or more time series later on.

##### Univariate Time Series

A **univariate time series** is a sequence of measurements of the same variable collected over time. Most often, the measurements are made at regular time intervals.

One difference from standard linear regression is that the data are not necessarily independent and not necessarily identically distributed. One defining characteristic of a time series is that it is a list of observations where the ordering matters. Ordering is very important because there is dependency, and changing the order could change the meaning of the data.

### Basic Objectives of the Analysis

The basic objective usually is to determine a model that describes the pattern of the time series. Uses for such a model are:

- To describe the important features of the time series pattern.
- To explain how the past affects the future or how two time series can "interact".
- To forecast future values of the series.
- To possibly serve as a control standard for a variable that measures the quality of the product in some manufacturing situations.

### Types of Models

There are two basic types of "time domain" models.

- Models that relate the present value of a series to past values and past prediction errors - these are called ARIMA models (for Autoregressive Integrated Moving Average). We'll spend substantial time on these.
- Ordinary regression models that use time indices as x-variables. These can be helpful for an initial description of the data and form the basis of several simple forecasting methods.

### Important Characteristics to Consider First

Some important questions to first consider when first looking at a time series are:

- Is there a
**trend**, meaning that, on average, the measurements tend to increase (or decrease) over time? - Is there
**seasonality**, meaning that there is a regularly repeating pattern of highs and lows related to calendar time, such as seasons, quarters, months, days of the week, and so on? - Are there
**outliers**? In regression, outliers are far away from your line. With time series data, your outliers are far away from your other data. - Is there a
**long-run cycle**or period unrelated to seasonality factors? - Is there
**constant variance**over time, or is the variance non-constant? - Are there any
**abrupt changes**to either the level of the series or the variance?

##### Example 1-1

The following plot is a** time series plot** of the annual number of earthquakes in the world with a seismic magnitude over 7.0 for 99 consecutive years. By a time series plot, we simply mean that the variable is plotted against time.

Some features of the plot:

- There is
**no consistent trend** - Almost by definition, there is
**no seasonality**as the data are annual data. - There are
**no obvious outliers**. - It's difficult to judge whether the variance is constant or not.

One of the simplest ARIMA-type models is a model in which we use a linear model to predict the value at the present time using the value at the previous time. This is called an **AR(1) model**, standing for **autoregressive model of order 1**. The order of the model indicates how many previous times we use to predict the present time.

A start in evaluating whether an AR(1) might work is to plot values of the series against **lag 1 values** of the series. Let denote the value of the series at any particular time , so denotes the value of the series one time before time . That is, is the lag 1 value of . As a short example, here are the first five values in the earthquake series, along with their lag 1 values.

t | x_{t } |
x_{ t-1}(lag 1 value) |
---|---|---|

1 | 13 | * |

2 | 14 | 13 |

3 | 8 |
14 |

4 | 10 | 8 |

5 | 16 | 10 |

For the complete earthquake dataset, here's a plot of versus

:

Although it's only a moderately strong relationship, there is a positive linear association so an AR(1) model might be a useful model.

### The AR(1) model

Theoretically, the AR(1) model is written

Assumptions:

- , meaning that the errors are independently distributed with a normal distribution that has mean 0 and constant variance.
- Properties of the errors are independent of .

This is essentially the ordinary simple linear regression equation, but there is one difference. Although it's not usually true, in ordinary least squares regression, we assume that the x-variable is not random but instead is something we can control. That's not the case here, but in our first encounter with time series, we'll overlook that and use ordinary regression methods. We'll do things the "right" way later in the course.

Following is the Minitab output for the AR(1) regression in this example:

quakes = 9.19 + 0.543 lag1

98 cases used; 1 case contains missing values

Predictor | Coef | SE Coef | T | P |
---|---|---|---|---|

Constant | 9.191 | 1.819 | 5.05 | 0.000 |

lag1 | 0.54339 | 0.08528 | 6.37 | 0.000 |

S = 6.12239 R-Sq = 29.7% R-Sq(adj) = 29.0%

We see that the slope coefficient is significantly different from 0, so the lag 1 variable is a helpful predictor. The

### Residual Analysis

In traditional regression, a plot of residuals versus fits is a useful diagnostic tool. The ideal for this plot is a horizontal band of points. Following is a plot of residuals versus predicted values for our estimated model. It doesn't show any serious problems. There might be one possible outlier at a fitted value of about 28.##### Example 1-2

The following plot shows a time series of quarterly production of beer in Australia for 18 years.Some important features are:

- There is an upward trend, possibly a curved one.
- There is seasonality – a regularly repeating pattern of highs and lows related to quarters of the year.
- There are no obvious outliers.
- There might be increasing variation as we move across time, although that's uncertain.

### Classical regression methods for trend and seasonal effects

To use traditional regression methods, we might model the pattern in the beer production data as a combination of the trend over time and quarterly effect variables.Suppose that the observed series is , for .

- For a linear trend, use (the time index) as a predictor variable in a regression.
- For a quadratic trend, we might consider using both and .
- For quarterly data, with possible seasonal (quarterly) effects, we can define indicator variables such as if the observation is in quarter of a year and 0 otherwise. There are 4 such indicators.

Let . A model with additive components for linear trend and seasonal (quarterly) effects might be written

Note!

We've deleted the "intercept" from the model. This isn't necessary, but if we include it we'll have to drop one of the seasonal effect variables from the model to avoid collinearity issues.

Predictor | Coef | SE Coef | T | P |
---|---|---|---|---|

Noconstant | ||||

Time | 0.5881 | 0.2193 | 2.68 | 0.009 |

tsqrd | 0.031214 | 0.002911 | 10.72 | 0.000 |

quarter_1 | 261.930 | 3.937 | 66.52 | 0.000 |

quarter_2 | 212.165 | 3.968 | 53.48 | 0.000 |

quarter_3 | 228.415 | 3.994 | 57.18 | 0.000 |

quarter_4 | 310.880 | 4.018 | 77.37 | 0.000 |

### Residual Analysis

### Sample Autocorrelation Function (ACF)

The ACF can be used to identify the possible structure of time series data. That can be tricky going as there often isn't a single clear-cut interpretation of a sample autocorrelation function. We'll get started on that in Lesson 1.2 this week. The ACF of the residuals for a model is also useful. The ideal for a sample ACF of residuals is that there aren't any significant correlations for any lag.

Following is the ACF of the residuals for Example 1, the earthquake example, where we used an AR(1) model. The "lag" (time span between observations) is shown along the horizontal, and the autocorrelation is on the vertical. The red lines indicated bounds for statistical significance. This is a good ACF for residuals. Nothing is significant; that's what we want for residuals.

The ACF of the residuals for the quadratic trend plus seasonality model we used for Example 2 looks good too. Again, there appears to be no significant autocorrelation in the residuals. The ACF of the residual follows:

Lesson 1.2 will give more details about the ACF. Lesson 1.3 will give some R code for examples in Lesson 1.1 and Lesson 1.2.