ExamSaathi learning library · Government exams · SSC CGL quantitative foundations; published syllabus labelled 2024 · Quantitative aptitude
Time series trend: moving averages and the least squares line
Smooth a yearly time series with three-, four- and five-yearly moving averages written against the right year, and fit the least squares trend line v = a + b t with coded years t to estimate the trend for a later year.
Status: original pilot lesson. Teacher review is pending. It is not a complete course or official exam material.
You will learn to
- Name the four components of a time series and say which one moving averages and a least squares trend line are meant to bring out.
- Calculate three-yearly and five-yearly moving averages of a time series and write each one against the middle year of its window.
- Centre four-yearly moving averages of a time series by averaging each pair of neighbouring four-yearly averages.
- Fit a least squares trend line v = a + b t with coded years t that add up to 0, and use the trend line to estimate a later year.
Before you start
A time series is a list of values recorded at equal steps of time, such as a shop's yearly sales or a state's yearly rainfall, always kept in time order. Here the recorded values are called v and a coded time is called t, since the letter x is reserved for multiplication. You need to be able to find a mean, total a column of products and square small whole numbers. Sales are in Rs. lakh and rainfall in cm, and every data set is invented for practice. All the methods in this lesson aim at the trend, so begin by scanning the values to see whether they rise or fall overall.
The four components of a time series
The movement of a series is usually split into four parts. The secular trend is the long-run rise or fall, such as the steady growth of a town's water use over twenty years. Seasonal variation repeats within each year: umbrella sales in Mumbai jump every monsoon, and sweet shops sell most around Diwali. Cyclical variation is a slower wave lasting several years, linked to booms and slowdowns in business. Irregular variation is whatever is left over: one-off shocks such as a flood, a strike or a sudden lockdown. In yearly data the seasonal part cannot show up, because each value already covers a whole year. Moving averages and the least squares line are two ways to bring out the trend while damping the other parts.
Three-yearly and five-yearly moving averages
A three-yearly moving average replaces each run of three consecutive values by their mean and writes it against the middle year of the run. The window then slides on by one year: drop the oldest value, bring in the next one, and divide the new total by 3 again. A quick way to get each new total is old total - value dropped + value added. With sales of 10, 13, 16 and 13 for 2018 to 2021, the first average is 39 / 3 = 13 against 2019, and the next total is 39 - 10 + 13 = 42, giving 14 against 2020. A five-yearly moving average works the same way with five values and is written against the third year of each run. A moving average over an odd number n of years leaves (n - 1) / 2 years blank at each end, so five-yearly averages lose two years at the start and two at the end. A longer period gives a smoother curve, and a period equal to the length of a regular cycle removes that cycle.
Four-yearly averages and centring
With an even period the middle of the window falls between two years. The four-yearly average of 2017 to 2020 belongs halfway between 2018 and 2019, and the next one, for 2018 to 2021, belongs halfway between 2019 and 2020. To bring them back onto whole years, take the mean of each pair of neighbouring four-yearly averages; this centred value is written against 2019, the year halfway between the two midpoints. Centring the first pair is the same as a weighted average of five years, (v1 + 2 x v2 + 2 x v3 + 2 x v4 + v5) / 8, where v1 to v5 are the values for 2017 to 2021. A centred four-yearly average leaves two years blank at each end of the series. The same pairing idea centres any even-period average, such as a six-yearly one.
The least squares trend line
A moving average gives smoothed values but no formula to carry forward. The method of least squares fits a straight line v = a + b t, choosing a and b so that the total of the squared gaps between the actual values and the line is as small as it can be. The line must satisfy two normal equations: sum of v = n x a + b x sum of t, and sum of (t x v) = a x sum of t + b x sum of t^2. The work is easiest when the years are coded so that the t values add up to 0, for five years t = -2, -1, 0, 1, 2 with t = 0 at the middle year. Then the equations shrink to a = sum of v / n, the mean of the values, and b = sum of (t x v) / sum of t^2, the change in trend per year. For five years the sum of t^2 is 4 + 1 + 0 + 1 + 4 = 10, and for seven years it is 28. To estimate a later year, count its t from the year where t = 0 and put it into the line. With an even number of years, such as six, code them as -5, -3, -1, 1, 3, 5, so one unit of t stands for half a year, consecutive years differ by 2 units of t, and a full year adds 2b.
Common mistakes
Writing a three-yearly average against the last year of its window instead of the middle year. Dividing a four-yearly total by 4 and stopping there, so the averages float between years; they must be centred. Losing count of the blank years at the ends: one at each end for three-yearly averages, two for five-yearly averages and two for centred four-yearly averages. Coding the years so that the t values do not add up to 0, and then still taking a as the mean of v. Dividing the sum of t x v by n instead of by the sum of t^2. Counting the t of a later year from the last year in the table rather than from the year where t = 0. Treating a one-off flood or strike year as part of the trend.
A routine for trend questions
1. List the years in order with their values v. 2. For an odd period, total each run of values, divide by the period, and write the mean against the middle year, updating each total by dropping one value and adding the next. 3. For an even period, find the plain averages first, then average each neighbouring pair and write the result against the year between them. 4. For a trend line, code the years so the t values add up to 0, and make columns of t, t x v and t^2. 5. Work out a = sum of v / n and b = sum of (t x v) / sum of t^2. 6. Find the t of the year asked about and work out a + b t. 7. Sense-check: the trend values for the given years should add up to the same total as the actual values.
Worked examples
A cloth shop in Surat recorded yearly sales (Rs. lakh) of 20 in 2018, 24 in 2019, 22 in 2020, 26 in 2021, 30 in 2022, 28 in 2023 and 35 in 2024. Find the three-yearly moving averages and the year each one belongs to.
- First total, 2018 to 2020: 20 + 24 + 22 = 66, so the average 22 goes against 2019.
- Slide the window: 66 - 20 + 26 = 72, average 24 against 2020; then 72 - 24 + 30 = 78, average 26 against 2021.
- Next, 78 - 22 + 28 = 84, average 28 against 2022; and 84 - 26 + 35 = 93, average 31 against 2023.
- 2018 and 2024 get no three-yearly average. The smoothed values climb steadily, so the trend is upward even though actual sales dipped in 2020 and 2023.
Answer: The three-yearly moving averages are 22, 24, 26, 28 and 31 (Rs. lakh) against 2019 to 2023, so the value for 2023 is Rs. 31 lakh.
Yearly rainfall (cm) at a town in Rajasthan was 40 in 2017, 44 in 2018, 42 in 2019, 46 in 2020, 48 in 2021, 46 in 2022, 50 in 2023 and 52 in 2024. Find the centred four-yearly moving averages.
- Four-yearly totals: 2017 to 2020 = 172, 2018 to 2021 = 180, 2019 to 2022 = 182, 2020 to 2023 = 190 and 2021 to 2024 = 196.
- Four-yearly averages: 43, 45, 45.5, 47.5 and 49. The first sits between 2018 and 2019, the second between 2019 and 2020, and so on.
- Centre by averaging neighbours: (43 + 45) / 2 = 44 against 2019, (45 + 45.5) / 2 = 45.25 against 2020, (45.5 + 47.5) / 2 = 46.5 against 2021, and (47.5 + 49) / 2 = 48.25 against 2022.
- Check 2019 with the weighted form: (40 + 2 x 44 + 2 x 42 + 2 x 46 + 48) / 8 = 352 / 8 = 44.
Answer: The centred four-yearly moving averages are 44, 45.25, 46.5 and 48.25 cm against 2019, 2020, 2021 and 2022.
A sweet shop in Agra had yearly sales (Rs. lakh) of 12 in 2020, 15 in 2021, 14 in 2022, 18 in 2023 and 21 in 2024. Fit a least squares straight-line trend and estimate the sales for 2027.
- Code the years with t = 0 at 2022: t = -2, -1, 0, 1, 2, so the t values add up to 0.
- Sum of v = 12 + 15 + 14 + 18 + 21 = 80, so a = 80 / 5 = 16.
- t x v: -24, -15, 0, 18 and 42, which add up to 21. Sum of t^2 = 4 + 1 + 0 + 1 + 4 = 10, so b = 21 / 10 = 2.1.
- Trend line: v = 16 + 2.1t, with t = 0 at 2022 and t counted in years. The trend values for 2020 to 2024 are 11.8, 13.9, 16, 18.1 and 20.2, which add up to 80, the same as the actual sales.
- 2027 is 5 years after 2022, so t = 5 and v = 16 + 2.1 x 5 = 26.5.
Answer: The trend line is v = 16 + 2.1t with t = 0 at 2022, and the estimated sales for 2027 are Rs. 26.5 lakh.
Practice checks
- Yearly rainfall (cm) at a town in Madhya Pradesh was 82 in 2017, 90 in 2018, 86 in 2019, 94 in 2020, 98 in 2021, 92 in 2022 and 104 in 2023. What is the five-yearly moving average written against 2021?
- A dairy cooperative in Anand collected 60, 64, 70, 66 and 72 lakh litres of milk in the five years 2019 to 2023. What is the centred four-yearly moving average against 2021?
- A sugar mill near Kolhapur crushed 30, 34, 37, 41 and 43 thousand tonnes of cane in the years 2019 to 2023. Using a least squares straight-line trend with t = 0 at 2021, what is the trend estimate for 2026, in thousand tonnes?
- A shop's yearly sales (Rs. lakh) were 40 in 2019, 45 in 2020, k in 2021, 50 in 2022 and 57 in 2023. The three-yearly moving average written against 2021 is 48. What is the three-yearly moving average against 2022?
- Sales of woollen shawls in Shimla rise every winter and fall every summer, year after year. Which component of the time series does this pattern show?
Sources checked
- SSC CGL Scheme and Syllabus, labelled 2024 — Tier-II Paper-II Statistics (time series analysis: components, measurement of trend); not verified as the full 2026-cycle syllabus
- NIST/SEMATECH e-Handbook of Statistical Methods — Section 6.4.2.2, Centered Moving Average: placing a moving average against the middle period, and centring an even-period moving average by averaging pairs of successive averages; mathematical relationships only
- NIST/SEMATECH e-Handbook of Statistical Methods — Section 4.1.4.1, Linear Least Squares Regression: fitting a straight line by minimising the sum of squared deviations; mathematical relationships only