Testing whether a series is stationary with KPSS

Today let's understand what it means for a time series to be stationary, and how to test for it, working through one real series from start to finish.

AirPassengers is a dataset built into R: the monthly count of international airline passengers, in thousands, from January 1949 to December 1960, 144 months in all. It was first published by Box and Jenkins, and time series courses have reached for it ever since.

Here is the whole series, plotted month by month.

The line climbs across the whole twelve years, and the summer bump on top of it gets taller every year. Both of those, the climb and the growing bump, are exactly what this lesson is going to test for.

What "stationary" means: three properties that stay constant

A series is stationary when three things about it hold still as time passes. Its mean stays the same, its variance stays the same, and its autocorrelation structure, meaning how strongly a value relates to its own recent past, stays the same too. None of the three is allowed to drift as you move from the start of the series to the end.

That sounds abstract, so let's put a number on the first two for AirPassengers as a whole, before checking whether they actually hold.

RInteractive R
# Build the AirPassengers tsibble and compute its overall mean and standard deviation library(tsibble) library(dplyr) air <- as_tsibble(AirPassengers) |> rename(passengers = value, month = index) mean(air$passengers) #> [1] 280.2986 sd(air$passengers) #> [1] 119.9663

  

Across the whole series, the mean is about 280 and the standard deviation is about 120, both in thousands of passengers a month, the same units the data itself is recorded in. Those two numbers, 280.30 and 119.97, are the baseline. If AirPassengers really is stationary, any stretch of it you pull out on its own should land close to those same two numbers. Let's check that next.