Time series analysis: Lab 1

Model identification from the ACF and PACF, checked on simulated processes with known answers, then hourly Svedala temperatures, where differencing out the daily cycle turns out to be the wrong move.

PythonNumPySciPyMatplotlibJupyter 2026

The first MASM17 lab is the working loop of time series modelling: guess a structure from the autocorrelation and partial autocorrelation functions, estimate it, check whether what is left over is white noise, and go round again. It runs on simulated data first, where the right answer is known, and then on hourly temperatures from Svedala, where it is not.

Stability, and how far a covariance estimate reaches

The lab opens with two processes $A(z)y_t = C(z)e_t$ that share the same $C(z)$. One of them explodes, reaching values near $10^{75}$ within 200 samples. The pole-zero map shows why at a glance: $A_2(z) = 1 - 1.79z^{-1}$ puts its pole at 1.79, outside the unit circle, while the poles of $A_1(z) = 1 - 1.79z^{-1} + 0.84z^{-2}$ are a complex pair of modulus 0.917, just inside it.

That modulus matters for the next question: how many lags of an estimated covariance function can be trusted. Poles so close to the unit circle give the process a long memory, so 200 samples hold few independent cycles. Neighbouring lags of the estimate are also strongly correlated, so an error at one lag carries into the next. Five realisations agree with the theoretical covariance up to about lag 5 and then fan out: at lag 15 they range from −25.5 to 7.6, against a true value of −14.2. One realisation of 20,000 samples stays within 1.8 of the theory at every lag. The rule of thumb of $N/4$ lags would allow 50 here; about 5 are trustworthy.

Choosing an order when the answer is known

The second data set is 200 samples of the ARMA(1,1) process

$$y_t - 0.6\,y_{t-1} = e_t + 0.8\,e_{t-1},$$

supplied with the noise that generated it, so every fitted model's residual can be held against the true $e_t$.

Treated as unknown, the data points to an MA part through its partial autocorrelation, which does not cut off but decays with alternating sign: −0.77, 0.48, −0.31, 0.22. Pure AR models confirm it the hard way. They need order 4 before the residual is white with every parameter significant, because inverting the zero at −0.8 gives the slowly decaying series $1 - 0.8z^{-1} + 0.64z^{-2} - 0.51z^{-3} + \dots$, which a finite AR polynomial can only approximate.

Model Parameters Residual variance FPE White residual All significant
AR(1) 1 1.754 1.772 No Yes
AR(4) 4 1.165 1.213 Yes Yes
ARMA(1,1) 2 1.158 1.182 Yes Yes
ARMA(1,2) 3 1.146 1.182 Yes No
ARMA(2,2) 4 1.151 1.198 Yes No

ARMA(1,1) matches the residual variance of AR(4) with half the parameters. Its estimates, $\hat a_1 = -0.582 \pm 0.062$ and $\hat c_1 = 0.764 \pm 0.049$, are each within one standard error of the truth, and its residual follows the true noise with correlation 0.994. Larger ARMA models lower the variance slightly, but each adds a parameter that is not significant. In ARMA(2,2) none of the four is, and the standard errors are about as large as the estimates themselves: the parameters trade off against one another, and the data cannot pin any of them down.

The order criterion is no referee either. On the first simulated process, whose true structure is ARMA(2,2), the FPE is lowest for ARMA(3,2), and that model even passes its significance tests. What gives it away is a pole at −0.949 and a zero at −0.986, which nearly cancel. Without that pair the remaining poles, $0.880 \pm 0.158i$, sit close to the true $0.895 \pm 0.197i$.

A seasonal process

Next comes a process with a seasonal unit root,

$$A(z)(1 - z^{-12})\,y_t = C(z)\,e_t, \qquad A(z) = 1 - 1.5z^{-1} + 0.7z^{-2}, \qquad C(z) = 1 - 0.5z^{-12}.$$

Its ACF barely decays at the seasonal lags, 0.91, 0.87 and 0.84 at lags 12, 24 and 36, which is the mark of a unit root. After differencing with $1 - z^{-12}$, an AR(2) leaves one isolated ACF spike of −0.41 at lag 12, the sign of an MA term at that lag. Adding $c_{12}$ alone, with $c_1$ to $c_{11}$ held at zero, leaves a white residual and three significant parameters.

Parameter True $N = 500$ $N = 10{,}000$
$a_1$ −1.5 −1.452 ± 0.033 −1.501 ± 0.007
$a_2$ 0.7 0.676 ± 0.033 0.706 ± 0.007
$c_{12}$ −0.5 −0.466 ± 0.040 −0.501 ± 0.009

Twenty times the data shrinks every standard error by about $\sqrt{20} \approx 4.5$.

The alternative is to leave the data undifferenced and estimate the seasonal factor as free coefficients of $A(z)$ at lags 12, 13 and 14. The estimator finds the unit root by itself, $\hat a_{12} = -1.0002 \pm 0.008$, but the model is no better: residual variance 0.9989 against 0.9930, with six parameters instead of three. Its estimated polynomial also has a root of modulus 1.0007, just outside the unit circle, so the fitted model is not stable.

Hourly temperatures from Svedala

The real data is 1361 hourly temperatures from Svedala, about 57 days. The ACF peaks at lags 24 and 48, at 0.70 and 0.55: a daily cycle. The route from the simulated case works: difference with $1 - z^{-24}$, fit AR(2), find a spike at lag 24, add $c_{24}$. The result is

$$A(z) = 1 - 1.370z^{-1} + 0.435z^{-2}, \qquad C(z) = 1 - 0.705z^{-24},$$

with all three parameters significant and a residual variance of 0.399.

The residual is close to white, but it cannot be made fully white by an ARMA model. The McLeod-Li test, which looks for dependence in the squared residuals, fails at 163 against a limit of 36.4, and the residual variance of single days ranges from 0.08 to 1.6. Calm days and windy days behave differently, and a model with constant noise variance cannot capture that.

Not differencing turns out better. A plain AR(2) on the raw data already reaches a lower residual variance, 0.381, with one parameter fewer. Adding small seasonal AR terms at lags 23, 24 and 25 together with $c_{24}$ brings it to 0.333, 17 percent below the differenced model, with every parameter significant.

The reason is visible in $\hat c_{24} = -0.705$. The factor $1 - 0.705z^{-24}$ partly cancels the $1 - z^{-24}$ that was just applied, which says the difference was too strong. Differencing assumes the daily pattern repeats exactly, and the weather changes it from one day to the next.

What this involved

The course's Python package for estimation, with individual coefficients freed or fixed, and for the ACF, PACF, normal probability plots and four whiteness tests. Two small helpers were written for the lab: one simulates with a burn-in period, and one computes residuals while dropping the first $n_a$ samples, which the inverse filter corrupts. Every method was tried on simulated data with a known answer before it was trusted on real data.


The two simulated processes. $y_1$ wanders but stays bounded; $y_2$ is flat on this scale until it shoots up to about $4 \times 10^{75}$ at the end.
The two simulated processes. $y_1$ wanders but stays bounded; $y_2$ is flat on this scale until it shoots up to about $4 \times 10^{75}$ at the end.
Poles as crosses, zeros as circles. The pole of $y_2$ sits at 1.79, outside the unit circle, which is why that process explodes; the poles of $y_1$ are just inside.
Poles as crosses, zeros as circles. The pole of $y_2$ sits at 1.79, outside the unit circle, which is why that process explodes; the poles of $y_1$ are just inside.
Left: estimated covariance from five realisations of 200 samples, against the theory in black. They agree for about five lags, then fan out. Right: one realisation of 20,000 samples follows the theory at every lag.
Left: estimated covariance from five realisations of 200 samples, against the theory in black. They agree for about five lags, then fan out. Right: one realisation of 20,000 samples follows the theory at every lag.
The ARMA(1,1) residual, dashed, over the true noise that generated the data. After the first few samples the two are almost indistinguishable.
The ARMA(1,1) residual, dashed, over the true noise that generated the data. After the first few samples the two are almost indistinguishable.
ACF and PACF of the simulated seasonal process. The ACF barely decays at lags 12, 24 and 36, the mark of a seasonal unit root.
ACF and PACF of the simulated seasonal process. The ACF barely decays at lags 12, 24 and 36, the mark of a seasonal unit root.
ACF and PACF of the residual once $a_1$, $a_2$ and $c_{12}$ are in the model. The spike at lag 12 is gone, and all four whiteness tests pass.
ACF and PACF of the residual once $a_1$, $a_2$ and $c_{12}$ are in the model. The spike at lag 12 is gone, and all four whiteness tests pass.
Hourly temperature at Svedala over 1361 hours. The daily cycle is clear, and so is how much its size changes from one day to the next.
Hourly temperature at Svedala over 1361 hours. The daily cycle is clear, and so is how much its size changes from one day to the next.
ACF and PACF of the raw Svedala temperatures. The ACF rises again to 0.70 at lag 24 and 0.55 at lag 48: a daily cycle.
ACF and PACF of the raw Svedala temperatures. The ACF rises again to 0.70 at lag 24 and 0.55 at lag 48: a daily cycle.