3. Trends and their uncertainty¶
A trend is a slope; the question is how fast temperature rose in each window and how sure we can be. We fit slopes by hand and with a library, then allow for the fact that one year is a lot like the next.
3.1 A trend line, by hand and for every window¶
A trend is the slope of the straight line that best fits the points. "Best" means the line that makes the sum of the squared vertical distances from the points to the line as small as possible: ordinary least squares (OLS). For points (x, y), with x̄ and ȳ their means, the slope is
It is in degrees per year; multiplying by ten gives degrees per decade. Here it is by hand, for five years:
small = d[d.year.between(2010, 2014)][["year", "global"]].copy()
small["x - xbar"] = small.year - small.year.mean()
small["y - ybar"] = small["global"] - small["global"].mean()
small["product"] = small["x - xbar"] * small["y - ybar"]
small["(x - xbar)^2"] = small["x - xbar"] ** 2
print(small.round(4).to_string(index=False))
b = small["product"].sum() / small["(x - xbar)^2"].sum()
print(f"\nslope = {small['product'].sum():.4f} / {small['(x - xbar)^2'].sum():.0f} = {b:.4f} °C per year")
print(f"numpy gives {np.polyfit(small.year, small['global'], 1)[0]:.4f}")
year global x - xbar y - ybar product (x - xbar)^2
2010 0.6804 -2.0 0.0619 -0.1239 4.0
2011 0.5377 -1.0 -0.0807 0.0807 1.0
2012 0.5776 0.0 -0.0408 -0.0000 0.0
2013 0.6236 1.0 0.0052 0.0052 1.0
2014 0.6729 2.0 0.0544 0.1089 4.0
slope = 0.0709 / 10 = 0.0071 °C per year
numpy gives 0.0071
Five years is far too short for climate: a single El Niño year can tip the slope either way. The paper used 42-year windows, so we do the same, for the global record and for the United States.
WINDOWS = [(1899, 1940), (1941, 1982), (1983, 2024)]
rows = []
for a, e in WINDOWS:
w = d[d.year.between(a, e)]
for col in ["global", "conus"]:
slope = np.polyfit(w.year, w[col], 1)[0] * 10
rows.append({"window": f"{a}-{e}", "series": col, "trend per decade": round(slope, 3),
"CO2 emitted (Gt)": round(w.co2.sum() / 1000), "change in human forcing (W/m2)": round(w.anthro.iloc[-1] - w.anthro.iloc[0], 2)})
trends = pd.DataFrame(rows)
print(trends.to_string(index=False))
gl = trends[trends.series == "global"].set_index("window")["trend per decade"]
print(f"\nRead across the global rows: the recent window warmed {gl['1983-2024'] / gl['1899-1940']:.1f} times as fast as 1899-1940,")
print(f"while {trends['CO2 emitted (Gt)'].iloc[4]:,} Gt of CO2 were emitted in it against {trends['CO2 emitted (Gt)'].iloc[0]:,} Gt in the first window.")
window series trend per decade CO2 emitted (Gt) change in human forcing (W/m2)
1899-1940 global 0.101 140 0.18
1899-1940 conus 0.168 140 0.18
1941-1982 global 0.012 459 0.51
1941-1982 conus -0.059 459 0.51
1983-2024 global 0.216 1209 2.05
1983-2024 conus 0.280 1209 2.05
Read across the global rows: the recent window warmed 2.1 times as fast as 1899-1940,
while 1,209 Gt of CO2 were emitted in it against 140 Gt in the first window.
How to read the table. One row per window and series. "trend per decade" is the slope in °C per decade: 0.1 means the line rose a tenth of a degree every ten years. "CO2 emitted" is the total released in that window, and "change in human forcing" is how much the human push on the climate grew across the window, in W/m².
What it says. Both the globe and the United States warmed fastest in the most recent window, 1983–2024, not in 1899–1940. In the middle window the human forcing grew, yet warming nearly stopped: something cancelled it, which the physics section identifies as sulfate aerosols. Comparing trends with emissions in the same window, as the paper did, hides that.
3.2 Neighbouring years are not independent¶
How sure are we of each slope? The standard error (SE) of a slope measures how much it would vary if the "noise" around the line were drawn again. The usual formula assumes every point is an independent piece of information. Climate years are not: a warm year tends to follow a warm year, because the oceans store heat and El Niño lasts more than one year. This is autocorrelation. We measure it with the lag-1 correlation r₁ of the leftovers (residuals) after removing the trend, and then count how many independent years we really have:
The SE grows accordingly. scipy.stats.linregress gives the slope and the naive SE; we then correct it.
def trend_with_uncertainty(years, values):
fit = stats.linregress(years, values)
resid = values - (fit.intercept + fit.slope * years)
r1 = np.corrcoef(resid[:-1], resid[1:])[0, 1]
n = len(values)
n_eff = n * (1 - r1) / (1 + r1) if r1 > 0 else n
se = fit.stderr * np.sqrt((n - 2) / max(n_eff - 2, 1))
return {"trend": fit.slope * 10, "se_naive": fit.stderr * 10, "r1": r1, "n_eff": n_eff, "se_corrected": se * 10}
rows = []
for a, e in WINDOWS:
w = d[d.year.between(a, e)]
t = trend_with_uncertainty(w.year.to_numpy(float), w["global"].to_numpy())
rows.append({"window": f"{a}-{e}", **{k: round(v, 3) for k, v in t.items()}})
unc = pd.DataFrame(rows)
print(unc.to_string(index=False))
window trend se_naive r1 n_eff se_corrected
1899-1940 0.101 0.014 0.483 14.648 0.026
1941-1982 0.012 0.016 0.475 14.935 0.028
1983-2024 0.216 0.013 0.217 27.023 0.016
How to read the table. "trend" is the slope (°C per decade); "se_naive" its standard error if every year were independent; "r1" how alike neighbouring years are after removing the trend (0 = not at all, 1 = identical); "n_eff" the number of independent years that leaves; "se_corrected" the standard error allowing for it.
Read the table: in 1983–2024 the global trend is about 0.22 °C per decade with a corrected SE of about 0.02. A 95% range is roughly the trend ± 2 SE, so 0.18 to 0.25. In 1899–1940 it is about 0.10 ± 0.05. The ranges do not overlap: the recent warming really is faster.