What does Kalman Filtering for Readings and Ad Reports conclude, in numbers, about “Where the Kalman Gain Comes From: One Prediction, One Correction and Exponential Smoothing”?
Answer: The Kalman filter for the local level model is four lines of arithmetic: the predicted variance grows by \(q\), the gain is the predicted variance over the predicted variance plus \(r\), the estimate absorbs the innovation in proportion to the gain, and the variance shrinks by the gain. The gain settles within days, and once settled the filter is exponential smoothing with weight equal to the gain; with the illustrative parameters it is 0.2207, with half the weight on the last three days. The seven-day average loses little on noisy readings but does worse than no smoothing on clean ones. Real metrics, however, do not always drift at random around one level. Scale readings may have a sustained trend, and orders may step up on a given day because of a real event. What happens to the filter when it meets a trend or a step? The next chapter answers.
Scope of the numbers: Its noise variances, drifts, returns and budgets are illustrative parameters; all calculations are generated by its programs. On wearable readings it is not medical advice, claims no effect, judges no one's state of health, and asks readers to consult a licensed physician before any self-experiment; on advertising attribution it is not individual business advice.
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: 0.2207
| day | predicted P | gain K | filtered sd |
|---|---|---|---|
| 1 | 100.000 | 0.9615 | 1.961 |
| 2 | 4.096 | 0.5059 | 1.423 |
| 3 | 2.274 | 0.3624 | 1.204 |
| 5 | 1.443 | 0.2651 | 1.030 |
| 8 | 1.195 | 0.2300 | 0.959 |
| 12 | 1.141 | 0.2219 | 0.942 |
| steady state: P = 1.133 | K = 0.2207 | filtered sd 0.940 | |
| single reading sd 2.000; error variance cut to 0.221 | |||
| EWMA weight today 0.2207; half the weight in last 3 days, 90 % in last 10 | |||
| mean age of the information: 3.53 days |
Key formula
Show the full program
# Chapter 2. p21: The Kalman gain settles fast and turns into an EWMA.
# Local level, q = 0.25 (true daily change sd 0.5) and r = 4 (reading
# error sd 2.0), as in p11; the first estimate starts from a vague
# prior, variance 100. Predicted variance P satisfies, at steady state,
# P = (q + sqrt(q^2 + 4 q r)) / 2, K = P / (P + r).
# Muth (1960): the steady-state filter is exponential smoothing with
# weight K, so reading j days back gets weight K (1 - K)^j.
import math
Q, R, P0 = 0.25, 4.0, 100.0
p = P0
print("day predicted P gain K filtered sd")
for t in range(1, 13):
pp = p + Q if t > 1 else p
k = pp / (pp + R)
p = pp * (1 - k)
if t in (1, 2, 3, 5, 8, 12):
print("%3d %10.3f %.4f %.3f" % (t, pp, k, math.sqrt(p)))
pss = (Q + math.sqrt(Q * Q + 4 * Q * R)) / 2
kss = pss / (pss + R)
print("steady state: P = %.3f K = %.4f filtered sd %.3f"
% (pss, kss, math.sqrt(pss * (1 - kss))))
print("single reading sd %.3f; error variance cut to %.3f"
% (math.sqrt(R), pss * (1 - kss) / R))
w = [kss * (1 - kss) ** j for j in range(200)]
cum, half, ninety = 0.0, None, None
for j in range(200):
cum = math.fsum(w[:j + 1])
if half is None and cum >= 0.5:
half = j + 1
if ninety is None and cum >= 0.9:
ninety = j + 1
print("EWMA weight today %.4f; half the weight in last %d days,"
" 90 %% in last %d" % (kss, half, ninety))
print("mean age of the information: %.2f days" % ((1 - kss) / kss))Single source and citation
Fan, Y. (2026). Kalman Filtering and State-Space Assimilation: Separating Observation Noise from True Signals in Wearable Readings and Advertising Reports (Version 1.0.0), Chapter 2: Where the Kalman Gain Comes From: One Prediction, One Correction and Exponential Smoothing. 5D Library. DOI pending
DOI pending · monograph page goes live after publication · 5DL-B-245 · v1.0.0 · CC-BY-NC-ND-4.0
BibTeX
@book{fan2026245,
author = {Fan, Yafu},
title = {Kalman Filtering and State-Space Assimilation: Separating Observation Noise from True Signals in Wearable Readings and Advertising Reports},
year = {2026},
publisher = {5D Library},
edition = {1.0.0},
note = {DOI pending}
}Other chapter answers in this book
- Chapter 1 · Why Raw Readings Overreact: the Noise-to-Signal Ratio and Decision Flips
- Chapter 3 · Trends and Steps: Slow Drift Takes Weeks to Show, a Real Jump Costs Days of Lag
- Chapter 4 · Looking Back and Filling Gaps: the RTS Smoother, Missing Days and Artefact Readings
- Chapter 5 · How Large Is the Noise? Maximum Likelihood, Innovation Tests and Moments of Differences
- Chapter 6 · The Advertising Report: Attribution Noise, On/Off Flighting and Budget Switching
- Chapter 7 · Classical Sources East and West: the Mencius and Gauss's Least Squares
- Chapter 8 · Closing the Loop: a Four-Week Filtered Log, Filtered Advertising Reports and Pre-Registered Tests