What does Solar Terms, Thermal Lag and Seasonal Demand conclude, in numbers, about “Harmonic Regression: Estimating Amplitude and Phase from Daily Readings”?
Answer: Chapter 4 shows that "the hottest day" is a statistic dominated by weather noise: in illustrative data the single hottest day misses by 16.81 days, while the harmonic phase from three years of daily data misses by only 1.25 days.
Scope of the numbers: Parameters in this book are illustrative; all calculations are generated by the book's programs; the book is non-personalised business guidance, and its order dates are demonstrations that promise no sales to any merchant. Chapter 4 shows that "the hottest day" is a statistic dominated by weather noise: in illustrative data the single hottest day misses by 16.81 days, while the harmonic phase from three years of daily data misses by only 1.25 days.
Data table
The numbers below are printed verbatim by the chapter's Python program and can be reproduced by running it. standard-library Python onlyprinted values that match the answer: 1.25, 16.81
| years | harmonic: mean | rmse | | hottest day: mean | rmse | | 7-day: rmse | ||
| 1 | 32.62 | 2.25 | | | 33.08 | 16.11 | | | 15.02 |
| 3 | 32.35 | 1.25 | | | 31.59 | 16.73 | | | 15.43 |
| 10 | 32.53 | 0.68 | | | 31.74 | 16.92 | | | 15.41 |
| 30 | 32.49 | 0.37 | | | 30.47 | 16.81 | | | 15.82 |
| true lag of the first harmonic: 32.5 days |
Show the full program
# Chapter 4. p42: how many years pin down the lag?
# Same illustrative truth as p41 (mean 14.0, first harmonic 14.0 C
# peaking 32.5 days after Xiazhi, second harmonic 1.0 C, AR(1) noise
# rho 0.7, sd 3.0 C). For N years of daily data, 300 seeded replicates
# compare three estimators of "when summer peaks", in days after
# Xiazhi: the first-harmonic phase (mean, cos, sin regression, sums by
# math.fsum), the single hottest day of the last year, and the centre
# of the hottest 7-day mean in the last year. Seed 20261113.
# For scale: Stine, Huybers and Fung (2009, Nature) describe the
# seasons by this same yearly sinusoid and report that its phase over
# extratropical land moved 1.7 days earlier between 1954 and 2007.
import math
import random
YEAR = 365.2422
W = 2 * math.pi / YEAR
XIAZHI = 171.68
LAG = 32.5
RHO, SD = 0.7, 3.0
REPS = 300
def simulate(days, rng):
e = rng.gauss(0, SD)
innov = SD * math.sqrt(1 - RHO ** 2)
out = []
for d in range(days):
e = RHO * e + rng.gauss(0, innov)
out.append(math.fsum([14.0,
14.0 * math.cos(W * (d - XIAZHI - LAG)),
math.cos(2 * W * (d - 200)), e]))
return out
def phase_lag(series):
c = [math.cos(W * d) for d in range(len(series))]
s = [math.sin(W * d) for d in range(len(series))]
n = len(series)
sy, sc, ss = math.fsum(series), math.fsum(c), math.fsum(s)
scc = math.fsum(x * x for x in c)
sss = math.fsum(x * x for x in s)
scs = math.fsum(x * y for x, y in zip(c, s))
syc = math.fsum(x * y for x, y in zip(series, c))
sys_ = math.fsum(x * y for x, y in zip(series, s))
# centre, then solve the 2 x 2 system for the cos and sin weights
a11 = scc - sc * sc / n
a22 = sss - ss * ss / n
a12 = scs - sc * ss / n
b1 = syc - sy * sc / n
b2 = sys_ - sy * ss / n
det = a11 * a22 - a12 * a12
bc = (b1 * a22 - b2 * a12) / det
bs = (a11 * b2 - a12 * b1) / det
peak = (math.atan2(bs, bc) / W) % YEAR
return peak - XIAZHI
def last_year_peaks(series):
seg = series[-365:]
off = len(series) - 365
hot = max(range(len(seg)), key=lambda i: seg[i]) + off
runs = [math.fsum(seg[i - 3:i + 4]) for i in range(3, len(seg) - 3)]
c7 = 3 + max(range(len(runs)), key=lambda i: runs[i]) + off
shift = (len(series) // 365 - 1) * YEAR
return hot - XIAZHI - shift, c7 - XIAZHI - shift
def rms(xs, centre):
return math.sqrt(math.fsum((x - centre) ** 2 for x in xs) / len(xs))
if __name__ == "__main__":
rng = random.Random(20261113)
print("years harmonic: mean rmse | hottest day: mean rmse"
" | 7-day: rmse")
for years in (1, 3, 10, 30):
ph, hd, h7 = [], [], []
for _ in range(REPS):
series = simulate(int(round(years * YEAR)), rng)
ph.append(phase_lag(series))
a, b = last_year_peaks(series)
hd.append(a)
h7.append(b)
print("{:5d} {:14.2f} {:5.2f} | {:16.2f} {:5.2f} | {:11.2f}"
.format(years, math.fsum(ph) / REPS, rms(ph, LAG),
math.fsum(hd) / REPS, rms(hd, LAG), rms(h7, LAG)))
print("true lag of the first harmonic: {:.1f} days".format(LAG))Single source and citation
Fan, Y. (2026). Temperature Phase Lag across the Twenty-Four Solar Terms, First-Order Thermal Inertia behind the Dog Days and Seasonal Demand Forecasting (Version 1.0.0), Chapter 4: Harmonic Regression: Estimating Amplitude and Phase from Daily Readings. 5D Library. DOI pending
DOI pending · monograph page goes live after publication · 5DL-B-232 · v1.0.0 · CC-BY-NC-ND-4.0
BibTeX
@book{fan2026232,
author = {Fan, Yafu},
title = {Temperature Phase Lag across the Twenty-Four Solar Terms, First-Order Thermal Inertia behind the Dog Days and Seasonal Demand Forecasting},
year = {2026},
publisher = {5D Library},
edition = {1.0.0},
note = {DOI pending}
}Other chapter answers in this book
- Chapter 1 · The Solstice Is Not the Hottest Day: First-Order Thermal Inertia and the Phase Lag arctan(ωτ)
- Chapter 2 · Fifteen Degrees a Step: Solar Longitude, the Twenty-Four Terms and the Sinusoid of Sunshine
- Chapter 3 · The Arithmetic of the Dog Days: the Geng-Day Rule, the Heat Window and Thermal Mass
- Chapter 5 · The Phase of Demand: Regressing Demand on Temperature, and the Misplaced Nominal Season
- Chapter 6 · The Price of a Phase Error: Order Timing under the Newsvendor Model
- Chapter 7 · Classical Sources East and West: the Shi Xun Chapter of the Yi Zhou Shu and Hesiod's Works and Days
- Chapter 8 · Closing the Loop: the Solar-Term Order Calendar, Store Scheduling and a Pre-Registered Test