Home / Articles / Advanced Topics
Advanced Topics · 5 min read

Time Series Analysis and Forecasting

Understand time series analysis and forecasting: trend, seasonality, moving averages, exponential smoothing and least-squares trend lines, with examples.

Electricity demand, wheat prices, monthly rainfall, the number of students logging into an online portal each hour: all of these are measured again and again over time. A sequence of observations recorded at regular intervals is called a time series, and analysing it lets us understand the past and make sensible forecasts about the future. This article explains the core ideas and walks through the techniques you are most likely to meet in statistics courses and real jobs.

What Makes Time Series Special?

In ordinary statistics we often assume that observations are independent: one student's height tells us nothing about the next student's. In a time series, the order matters. Today's temperature is closely related to yesterday's, and this month's sales depend partly on last month's. This dependence, called autocorrelation, is both a challenge and an opportunity. It breaks many standard methods, but it is exactly what makes forecasting possible.

The Four Components

Most time series can be thought of as a combination of four components:

  1. Trend (T): the long-term upward or downward movement, such as steadily rising mobile phone usage.
  2. Seasonal variation (S): regular patterns that repeat over a fixed period, such as higher electricity demand every summer or more ice-cream sales on weekends.
  3. Cyclical variation (C): longer, irregular rises and falls, often linked to economic booms and recessions, lasting several years.
  4. Irregular or random variation (I): unpredictable noise caused by one-off events like strikes, floods or data errors.

Analysts usually combine these in one of two ways:

$$ Y = T + S + C + I \quad \text{(additive model)} $$

$$ Y = T \times S \times C \times I \quad \text{(multiplicative model)} $$

The additive model suits series where seasonal swings stay roughly the same size. The multiplicative model suits series where swings grow as the overall level grows, which is common for sales and passenger numbers.

Smoothing with Moving Averages

The first step in analysing a series is often to smooth out the random noise so the trend becomes visible. A moving average replaces each value with the average of itself and its neighbours.

Worked Example 1: A 3-Point Moving Average

A shop records weekly sales (in thousands of rupees): 12, 15, 14, 18, 20, 19, 23. Find the 3-point moving averages.

Average the first three values, then slide the window one step at a time:

  • \( (12 + 15 + 14)/3 = 41/3 \approx 13.67 \)
  • \( (15 + 14 + 18)/3 = 47/3 \approx 15.67 \)
  • \( (14 + 18 + 20)/3 = 52/3 \approx 17.33 \)
  • \( (18 + 20 + 19)/3 = 57/3 = 19.00 \)
  • \( (20 + 19 + 23)/3 = 62/3 \approx 20.67 \)

The raw data jumps up and down (14 after 15, 19 after 20), but the moving averages rise smoothly from 13.67 to 20.67, revealing a clear upward trend of roughly 1.75 thousand rupees per week. For quarterly data, a 4-point moving average (followed by centring) removes the seasonal pattern as well.

Fitting a Trend Line by Least Squares

To forecast, we often fit a straight line \( y = a + bt \) through the data, choosing \( a \) and \( b \) to minimise the sum of squared errors. The formulas are

$$ b = \frac{n\sum ty - \sum t \sum y}{n\sum t^2 - (\sum t)^2}, \qquad a = \frac{\sum y - b\sum t}{n} $$

Worked Example 2: Forecasting Enrolments

A tuition academy's enrolments over five years are 10, 12, 15, 17 and 21 (in tens of students). Let \( t = 1, 2, 3, 4, 5 \).

Compute the sums:

  • \( \sum t = 1 + 2 + 3 + 4 + 5 = 15 \)
  • \( \sum y = 10 + 12 + 15 + 17 + 21 = 75 \)
  • \( \sum t^2 = 1 + 4 + 9 + 16 + 25 = 55 \)
  • \( \sum ty = 10 + 24 + 45 + 68 + 105 = 252 \)

Find the slope:

$$ b = \frac{5(252) - 15(75)}{5(55) - 15^2} = \frac{1260 - 1125}{275 - 225} = \frac{135}{50} = 2.7 $$

Find the intercept:

$$ a = \frac{75 - 2.7(15)}{5} = \frac{75 - 40.5}{5} = \frac{34.5}{5} = 6.9 $$

So the trend line is \( y = 6.9 + 2.7t \). The forecast for year 6 is

$$ y = 6.9 + 2.7(6) = 6.9 + 16.2 = 23.1 $$

meaning about 231 students. A sanity check: the data rose by 11 over 4 steps, an average of 2.75 per year, very close to our slope of 2.7.

Exponential Smoothing

A moving average treats all values in the window equally. Often, though, recent data is more relevant. Simple exponential smoothing gives the most weight to the latest observation and steadily less to older ones:

$$ S_t = \alpha y_t + (1 - \alpha) S_{t-1} $$

where \( 0 < \alpha < 1 \) is the smoothing constant. A large \( \alpha \) reacts quickly to changes; a small \( \alpha \) produces a calmer forecast.

Worked Example 3: Smoothing Monthly Demand

Monthly demand for a product is 50, 54, 52, 58. Use \( \alpha = 0.3 \) and start with \( S_1 = 50 \).

  • \( S_2 = 0.3(54) + 0.7(50) = 16.2 + 35 = 51.2 \)
  • \( S_3 = 0.3(52) + 0.7(51.2) = 15.6 + 35.84 = 51.44 \)
  • \( S_4 = 0.3(58) + 0.7(51.44) = 17.4 + 36.008 = 53.408 \)

The forecast for month 5 is about 53.4 units. Notice it is lower than the latest value of 58 because the method does not overreact to one high month. Extensions such as Holt's method add a trend term, and the Holt-Winters method adds seasonality.

Measuring Forecast Accuracy

No forecast is perfect, so we measure errors. If actual values are \( y_t \) and forecasts are \( \hat{y}_t \), two common measures are

$$ \text{MAE} = \frac{1}{n}\sum |y_t - \hat{y}_t|, \qquad \text{RMSE} = \sqrt{\frac{1}{n}\sum (y_t - \hat{y}_t)^2} $$

RMSE punishes large errors more heavily. Analysts compare these values across methods and choose the one with the smallest error on data the model has not seen.

Beyond the Basics: ARIMA and Machine Learning

Professional forecasters often use ARIMA models, popularised by George Box and Gwilym Jenkins in their 1970 book. ARIMA combines autoregression (using past values), differencing (removing trend to make the series stationary, with constant mean and variance) and moving-average terms (using past errors). More recently, neural networks and gradient-boosted trees have joined the toolkit, although simple methods remain surprisingly hard to beat on many real datasets.

Did You Know?

  • In the M-competitions run by Spyros Makridakis since 1982, simple methods like exponential smoothing have repeatedly performed as well as far more complicated models.
  • Some of the earliest recorded time series are records of the Nile's flood levels, kept in ancient Egypt to predict harvests and set taxes.
  • The Hurst exponent, now used in finance, came from H. E. Hurst's study of Nile flood records while designing reservoirs in the twentieth century.

Key Takeaways

  • A time series is data recorded in time order, where neighbouring values are usually related.
  • Series are built from trend, seasonal, cyclical and irregular components, combined additively or multiplicatively.
  • Moving averages smooth noise; least-squares lines and exponential smoothing produce forecasts.
  • Forecast accuracy is judged with error measures such as MAE and RMSE.
  • Advanced methods like ARIMA require the series to be made stationary first.

Working on a statistics or forecasting assignment? Get step-by-step solutions from Amathify's experts and PhD scholars via WhatsApp or the Ask a Question form.

Stuck on a problem or assignment?

Our experts and PhD scholars solve maths, physics and chemistry — step by step.

WhatsApp usAsk a question

Related articles