A record is a trend, a seasonal cycle and noise added together. The least-squares line finds the trend, and its R squared says how much of the scatter the line explains. A mean over twelve months removes a yearly cycle, and the mean of each calendar month gives the cycle itself.
about 30 min1 simulation2 practice questions
Lesson 1 of 3Show all lessonsHide
Try the code and the simulations beside the lesson.
A staircase hidden in a wave
In March 1958 a young scientist, Charles David Keeling, began to measure the carbon dioxide of the air on a Hawaiian mountain. The line that he drew was not a smooth staircase. It had a wave that came back every year, and the wave stood on a slope. The wave is the breathing of the northern forests: they take up carbon dioxide in summer and release it in winter. The slope is the rise from burning fuels. Both are in one list of numbers. Our task is to pull them apart.
What a time series is
A time series is a list of values taken at known times: a gauge reading each day, a satellite mean each month, a temperature each year. It is useful to think of each value as a sum of three parts:
y=trend+season+noise
The trend is the slow change over many years.
The seasonal cycle repeats every year.
The noise is what is left: weather, instrument error, a volcano.
Not every record has all three. A yearly mean has no seasonal cycle. A river record often has a wet season so large that it hides the trend.
The least-squares line
The straight line y=a+bx that fits best is the one that makes the sum of the squared vertical gaps, the residuals, as small as possible. The result has two closed forms. With xˉ and yˉ the means,
Sxy=∑(x−xˉ)(y−yˉ)
Sxx=∑(x−xˉ)2
b=SxxSxy,a=yˉ−bxˉ
The slope b has the unit of y per unit of x, such as ppm per year. The line always passes through the point (xˉ,yˉ).
The quantity R2=1−SSE/SST says how much of the spread of y the line explains. Here SSE is the sum of the squared residuals and SST is the sum of (y−yˉ)2. It lies between 0 and 1. A high R2 does not prove that the line is the right shape. A curve can have a high R2 for a line and still bend.
Use the time as a number with a clear unit. If the times are the years 2011,2012,…, then x−xˉ is a small number and the arithmetic is easy. The slope is the same whether the origin is 0 or 2011.
Taking the cycle out
Two methods remove a yearly cycle.
The 12-month mean. The cycle goes up and down, and the sum of its twelve monthly values is zero. So the mean of any twelve consecutive months has no cycle in it. It is the trend, at the middle of those twelve months. A centred version averages the two overlapping windows that straddle a month.
The monthly means. Subtract the line first. For each calendar month, average the leftover values over all the years. This table of twelve numbers is the seasonal cycle, or climatology. Its largest and smallest entries give the month of the peak and the size of the cycle.
At Mauna Loa the carbon dioxide cycle is about 6 to 7ppm from peak to trough, with the peak in May. The trend since 2010 is about 2.5ppm per year.
A figure in two parts that share a time axis of three years, from January of year 1. The top part shows the monthly carbon dioxide, in parts per million from 403 to 415, as a blue wavy line that rises from left to right and repeats a yearly cycle: it peaks in the spring and has its lowest values in autumn. A red dashed straight line through the middle of the waves is labelled trend, 2.4 parts per million per year. The bottom part shows what is left when the trend is taken away: a green wave about three parts per million above and below zero, with the same peak and trough each year.
Worked example: a tide gauge
Here are seven yearly means of sea level at a gauge, in millimetres above the gauge's datum. They were made up for this example: 7012, 7019, 7031, 7036, 7048, 7053, 7066. Let x=0,1,…,6 count the years.
The means.xˉ=3 and yˉ=7037.9mm.
The sums.Sxx=9+4+1+0+1+4+9=28. Sxy=247mm year.
The slope.b=247/28=8.82mm/year.
The intercept.a=7037.9−8.82×3=7011.4mm.
The fit.R2=0.991, so the line explains 99% of the spread.
A prediction. At x=10, the line gives 7099.6mm. Four years beyond the record, this is an extrapolation, and it assumes that nothing changes.
Take the amplitude to 0. What does the monthly record become? Now set the trend to 0. What is left of the 12-month mean?
Practise with new numbers
Try it in Python
The program fits a line to nine yearly values of a lake's level, finds how well the line fits, and then predicts three years. One of them is far outside the record.
Common mistakes
Reading a high R2 as proof of the model. It says only how much of the scatter the line takes.
Predicting far outside the record. The line says nothing about what happens beyond the data.
Averaging fewer than twelve months to remove a yearly cycle. Only a whole number of cycles cancels.
Mixing the unit of the slope. A slope per month is not a slope per year.
Remember these
Record = trend + season + noise.
b=Sxy/Sxx and a=yˉ−bxˉ. The line goes through (xˉ,yˉ).
R2=1−SSE/SST.
A 12-month mean removes a yearly cycle. The mean of each calendar month gives the cycle.
Check yourself
Try each one on your own first. If you are stuck, open a hint. Then check with Show the answer.
A record rises by 9.6ppm in 4 years along its trend line. What is the trend, in ppm per year?
Why does the least-squares line pass through (xˉ,yˉ)?
The twelve monthly values of a cycle add to zero. What is the mean of the cycle?
Can the slope of a record of monthly values and of the same record in years be compared directly?
References
D. S. Wilks, Statistical Methods in the Atmospheric Sciences (4th edition, Elsevier, 2019), the chapters on Time Series and on Linear Regression.
OpenStax, Introductory Statistics (2nd edition), the chapter Linear Regression and Correlation.
NOAA Global Monitoring Laboratory, Trends in atmospheric carbon dioxide, the Mauna Loa record, for the size of the trend and of the cycle.
Enroll free in Earth Data with Python: Trends, Anomalies and Models
Every lesson is open to read. Enrolling also lets you:
Mark lessons done and carry on where you stopped.
Take the tests of this lesson and its course.
Count the course towards the certificate for its chapter.