Skip to main content

Note 29: Case Study I: Solar Cycles & Harmonic Modeling

Module 7: Wrangling, Case Studies & Ethics

Learning Objectives

  • Motivate solar-cycle forecasting and inspect over three centuries of annual sunspot numbers (data/sunspots.rds).
  • Select an appropriate variance-stabilizing transformation (\(\sqrt{y_t}\)) for right-skewed count-like series that contain exact zeros.
  • Estimate dominant periodicities using the sample periodogram and connect spectral peaks to the ~11-year Schwabe cycle and ~100-year Gleissberg modulation.
  • Fit and evaluate Fourier harmonic regression with ARIMA errors against pure ARIMA and ETS benchmarks on a multi-cycle holdout window.

1. Solar Activity & Variance Stabilization with Zeros

Sunspots are dark magnetic regions on the solar photosphere whose counts track geomagnetic storm risk, satellite drag, and high-frequency radio disruptions. The local archive data/sunspots.rds contains 324 annual Wolf sunspot numbers from 1700 through 2023, capturing both the regular ~11-year Schwabe cycle and prolonged quiet eras such as the Dalton Minimum (1790–1830).

sunspots <- readRDS("data/sunspots.rds")

sunspots |>
  autoplot(Sunspots, color = ts_pal["navy"], linewidth = 0.75) +
  annotate("rect", xmin = 1790, xmax = 1830, ymin = 0, ymax = Inf,
           fill = ts_pal["slate"], alpha = 0.14) +
  annotate("text", x = 1810, y = 252, label = "Dalton Minimum",
           size = 3.3, color = ts_pal["slate"], fontface = "bold") +
  labs(
    title = "Annual Sunspot Activity (1700–2023)",
    subtitle = "Strong right skew and variance that scales with cycle amplitude",
    x = "Year",
    y = "Mean annual sunspot number"
  )
Figure 1: Annual Wolf sunspot numbers (1700–2023), showing quasi-periodic ~11-year cycles, asymmetric sharp peaks, and three exact zero-activity years.

Because Sunspots is non-negative, right-skewed, and exhibits larger fluctuations at cycle maxima than at minima, a power transformation stabilizes variance. However, the series contains three exact zeros (1711, 1712, and 1810), so \(\log(y_t)\) produces \(-\infty\) and fails immediately.

For Poisson-like counts where \(\text{Var}(y_t) \propto \mathbb{E}[y_t]\), the delta method shows that the square-root transform (Box-Cox with \(\lambda = 0.5\)) stabilizes variance while remaining well-defined at zero:

\[g(y_t) = \sqrt{y_t}, \qquad \text{Var}\!\left(\sqrt{y_t}\right) \approx \left(\frac{1}{2\sqrt{\mu_t}}\right)^2 \text{Var}(y_t) \approx \text{const}.\]

Using sqrt(Sunspots) directly inside fable::model() lets fable fit on the stabilized scale and automatically back-transform point forecasts (with bias adjustment) and prediction intervals to the original sunspot scale.

2. Spectral Identification of the Dominant Period

Before writing a harmonic model, verify the cycle period empirically with the sample periodogram. For a demeaned series \(z_t = \sqrt{y_t} - \bar{z}\) of length \(T\), the periodogram at Fourier frequency \(f_j = j / T\) measures squared amplitude:

\[I(f_j) = \frac{1}{T}\left|\sum_{t=1}^{T} z_t e^{-2\pi i f_j t}\right|^2, \qquad P_j = \frac{1}{f_j}.\]

spec_obj <- stats::spectrum(sqrt(sunspots$Sunspots), plot = FALSE)

spec_tbl <- tibble(
  freq = spec_obj$freq,
  period = 1 / spec_obj$freq,
  power = spec_obj$spec
)

spec_tbl |>
  filter(freq > 0) |>
  ggplot(aes(x = freq, y = power)) +
  geom_line(color = ts_pal["navy"], linewidth = 0.8) +
  geom_vline(xintercept = 1 / 11, color = ts_pal["crimson"], linetype = "dashed") +
  annotate("text", x = 1 / 11 + 0.014, y = 408, label = "Schwabe cycle",
           hjust = 0, size = 3.4, color = ts_pal["crimson"], fontface = "bold") +
  annotate("text", x = 1 / 11 + 0.014, y = 372,
           label = TeX(r"($P \approx 11.2$ yr)", output = "character"),
           parse = TRUE, hjust = 0, size = 3.3, color = ts_pal["crimson"]) +
  labs(
    title = TeX(r"(Spectral Periodogram of Square-Root Sunspots ($\sqrt{y_t}$))", bold = TRUE),
    subtitle = TeX(r"(Dominant power near $f \approx 1/11$ cycles/yr (10–11.2 yr Schwabe band))"),
    x = TeX(r"(Frequency, $f$ (cycles per year))", bold = TRUE),
    y = TeX(r"(Spectral density, $I(f)$)", bold = TRUE)
  )
Figure 2: Sample periodogram of square-root annual sunspot numbers, identifying the dominant ~11.2-year Schwabe peak and secondary ~108-year secular modulation.

The periodogram (Figure 2) peaks sharply at \(f \approx 0.0895\) cycles/year (\(P \approx 11.2\) years), with substantial adjacent power between 10.1 and 11.2 years because individual solar cycles vary slightly in length (roughly 9 to 14 years). A secondary low-frequency ridge near \(P \approx 108\) years reflects the century-scale Gleissberg modulation of peak amplitudes.

3. Harmonic Regression with ARIMA Errors

Because annual data carry no calendar seasonality (period = 1 in a yearly tsibble), standard seasonal SARIMA or seasonal ETS models cannot capture an 11-year cycle automatically. Instead, we model the non-calendar cycle via Fourier harmonic regression with ARIMA errors:

\[\sqrt{y_t} = \beta_0 + \sum_{k=1}^{K} \left[\alpha_k \sin\!\left(\frac{2\pi k t}{P}\right) + \beta_k \cos\!\left(\frac{2\pi k t}{P}\right)\right] + \eta_t, \qquad \phi(B)(1-B)^d \eta_t = \theta(B)\varepsilon_t.\]

Here \(P = 11\) sets the fundamental Schwabe period, \(K \le \lfloor P/2 \rfloor\) controls how flexibly the harmonics capture asymmetric rise-and-fall shapes (solar cycles typically rise faster than they decline), and the \(\text{ARIMA}(p,d,q)\) error process \(\eta_t\) absorbs cycle-to-cycle amplitude drift and phase jitter.

We hold out the final 22 years (2002–2023, two complete solar cycles) as an out-of-sample test set and compare three candidate specifications: ETS, pure ARIMA, and Harmonic_ARIMA (K = 3).

ss_train <- sunspots |> filter(Year <= 2001)
ss_test  <- sunspots |> filter(Year > 2001)

fit_ss <- ss_train |>
  model(
    ETS = ETS(sqrt(Sunspots)),
    ARIMA = ARIMA(sqrt(Sunspots)),
    Harmonic_ARIMA = ARIMA(sqrt(Sunspots) ~ fourier(period = 11, K = 3) + PDQ(0, 0, 0))
  )

fc_ss <- fit_ss |> forecast(h = nrow(ss_test))

fabletools::accuracy(fc_ss, sunspots) |>
  select(.model, RMSE, MAE, MASE) |>
  arrange(RMSE) |>
  fmt_tbl(digits = 2, caption = "Out-of-sample forecast accuracy on the 2002–2023 holdout window (22 years).")
Out-of-sample forecast accuracy on the 2002–2023 holdout window (22 years).
.model RMSE MAE MASE
Harmonic_ARIMA 29.62 27.32 0.93
ARIMA 41.91 33.53 1.15
ETS 831.31 693.69 23.73

Three findings stand out immediately:

  • Harmonic_ARIMA (LM w/ ARIMA(2,0,0) errors) wins decisively (RMSE = 29.6, MAE = 27.3, MASE = 0.93), tracking the phase of Solar Cycles 23, 24, and 25 over two full decades.
  • Pure ARIMA(2,0,1) (RMSE = 41.9) generates damped oscillations via complex conjugate AR(2) roots, capturing the first half-cycle before decaying back toward the historical mean.
  • Auto-selected ETS(A,Ad,N) fails severely (RMSE = 831) because 2001 sits right at a solar maximum (170.3); ETS misinterprets the rising limb of Cycle 23 as a damped upward trend and extrapolates sqrt(Sunspots) upward into an explosive squared trajectory. Notice also why we report MASE rather than MAPE: near solar minima (3.6 in 2019), percentage errors blow up even for small absolute errors.
fc_ss |>
  filter(.model != "ETS") |>
  anchor_fc(ss_train) |>
  autoplot(sunspots |> filter(Year >= 1970), level = 80, alpha = 0.35) +
  scale_color_manual(
    values = c(ARIMA = unname(ts_pal["orange"]), Harmonic_ARIMA = unname(ts_pal["teal"])),
    labels = c(ARIMA = "ARIMA", Harmonic_ARIMA = "Harmonic ARIMA")
  ) +
  scale_fill_manual(
    values = c(ARIMA = unname(ts_pal["orange"]), Harmonic_ARIMA = unname(ts_pal["teal"])),
    labels = c(ARIMA = "ARIMA", Harmonic_ARIMA = "Harmonic ARIMA")
  ) +
  labs(
    title = "Multi-Cycle Sunspot Forecasts (2002–2023 Holdout)",
    subtitle = "Harmonic ARIMA sustains 11-yr cycles; pure ARIMA damps toward the mean",
    x = "Year",
    y = "Mean annual sunspot number",
    color = NULL,
    fill = NULL
  )
Figure 3: Out-of-sample forecasts (2002–2023) comparing pure ARIMA against 11-year Fourier harmonic regression with ARIMA(2,0,0) errors (ETS omitted from y-scale due to trend blow-up).

4. Residual Diagnostics & Quasi-Periodicity Limits

Even our best harmonic model (LM w/ ARIMA(2,0,0) errors, so \(p + q = 2\) ARMA degrees of freedom) should be audited via innovation residuals.

p_ss_res <- fit_ss |>
  select(Harmonic_ARIMA) |>
  gg_tsresiduals(lag_max = 25)
p_ss_res[[2]] <- p_ss_res[[2]] + labs(y = "ACF")
p_ss_res[[3]] <- p_ss_res[[3]] + labs(x = "Innovation residual", y = "Count")

ts_panel(
  p_ss_res,
  title = TeX(r"(Innovation Residuals: Harmonic ARIMA ($K = 3$) on $\sqrt{y_t}$)", bold = TRUE),
  subtitle = "Training years 1700–2001; ACF ripples at lags 9–12 reflect cycle drift"
)
Figure 4: Innovation residual diagnostics for the 11-year Harmonic ARIMA(2,0,0) model on training years 1700–2001.
fit_ss |>
  select(Harmonic_ARIMA) |>
  augment() |>
  features(.innov, ljung_box, lag = 20, dof = 2) |>
  fmt_tbl(digits = 4, caption = "Ljung-Box whiteness test on Harmonic ARIMA(2,0,0) innovation residuals (dof = 2).")
Ljung-Box whiteness test on Harmonic ARIMA(2,0,0) innovation residuals (dof = 2).
.model lb_stat lb_pvalue
Harmonic_ARIMA 53.02 0

The Ljung-Box test rejects white noise (\(Q^* = 53.0\), \(p < 0.0001\)), and the residual ACF (Figure 4) displays subtle ripples near lags 9–12. That diagnostic is scientifically revealing rather than a coding bug: a fixed-period \(P = 11\) Fourier basis assumes an exact rigid clock, whereas true solar cycles drift between 9 and 14 years in duration and exhibit nonlinear amplitude modulation. Accounting for phase drift requires time-varying state-space harmonics or nonlinear solar-dynamo models.

Practice Exercises

  1. Harmonic Order Sensitivity (\(K\)). Holding differencing fixed at \(d = 0\) (so AICc values remain strictly comparable across models), fit Fourier regression with ARIMA errors on ss_train for \(K \in \{1, 2, 3, 5\}\) at \(P = 11\). Which \(K\) minimizes AICc, and what happens at \(K = 5\)?
Solution

Fixing pdq(d = 0) keeps the response scale identical across all four models so AICc and BIC are directly comparable:

fit_k <- ss_train |>
  model(
    K1 = ARIMA(sqrt(Sunspots) ~ fourier(period = 11, K = 1) + pdq(d = 0) + PDQ(0, 0, 0)),
    K2 = ARIMA(sqrt(Sunspots) ~ fourier(period = 11, K = 2) + pdq(d = 0) + PDQ(0, 0, 0)),
    K3 = ARIMA(sqrt(Sunspots) ~ fourier(period = 11, K = 3) + pdq(d = 0) + PDQ(0, 0, 0)),
    K5 = ARIMA(sqrt(Sunspots) ~ fourier(period = 11, K = 5) + pdq(d = 0) + PDQ(0, 0, 0))
  )

glance(fit_k) |>
  select(.model, sigma2, log_lik, AICc, BIC) |>
  arrange(AICc) |>
  fmt_tbl(digits = 2, caption = "Information criteria across harmonic orders K (fixed d = 0, P = 11).")
Information criteria across harmonic orders K (fixed d = 0, P = 11).
.model sigma2 log_lik AICc BIC
K2 1.99 -529.9 1076 1106
K1 2.01 -532.5 1077 1099
K3 1.98 -528.3 1077 1114
K5 1.99 -526.8 1083 1134

\(K = 2\) achieves the lowest AICc (1076.1), closely followed by \(K = 1\) and \(K = 3\); adding fourth and fifth harmonics at \(K = 5\) increases AICc to 1082.9 because higher harmonics overfit noise rather than true cycle asymmetry.

  1. Residual Autocorrelation Under \(K = 2\). Extract the K2 model from Exercise 1, inspect its ARMA order using tidy(), and run a Ljung-Box test at lag 20 with the exact dof equal to \(p + q\). Does switching to the AICc-optimal \(K = 2\) eliminate residual autocorrelation?
Solution

Count only the AR and MA terms (\(p + q\)) from tidy() to set dof:

k2_terms <- fit_k |> select(K2) |> tidy()
arma_dof <- sum(grepl("^(ar|ma)[0-9]+$", k2_terms$term))

fit_k |>
  select(K2) |>
  augment() |>
  features(.innov, ljung_box, lag = 20, dof = arma_dof) |>
  mutate(dof_used = arma_dof) |>
  fmt_tbl(digits = 4, caption = "Ljung-Box test for AICc-optimal K = 2 harmonic model.")
Ljung-Box test for AICc-optimal K = 2 harmonic model.
.model lb_stat lb_pvalue dof_used
K2 52.47 0 2

Residual autocorrelation remains significant (\(p < 0.0001\)) because the limitation is physical quasi-periodicity (variable cycle lengths around 11 years), not missing higher harmonics of an exact 11-year clock.

Key Takeaways

  • For non-negative, right-skewed count series containing zeros, \(\sqrt{y_t}\) stabilizes variance cleanly without the \(-\infty\) failure of \(\log(y_t)\).
  • Use the sample periodogram (stats::spectrum()) to confirm dominant non-calendar periodicities empirically before specifying Fourier terms.
  • Fourier harmonic regression with ARIMA errors captures sustained multi-cycle oscillations where non-seasonal ETS extrapolates local slopes catastrophically and pure ARIMA damps back to the mean.
  • Persistent residual autocorrelation in a fixed-period harmonic model signals genuine quasi-periodicity or amplitude modulation rather than a simple misspecification of \(K\).
Back to top