← Notes · December 2026

The KZ filter and LMG: some theory

Frequency response, moments, cutoffs and noise reduction for the Kolmogorov–Zurbenko filter, and the Shapley structure of the LMG decomposition of R², with proofs.

Environmental time series mix processes on very different time scales, and the meteorological variables that drive them are strongly correlated. A common workflow handles both problems: separate time scales with the Kolmogorov–Zurbenko (KZ) filter, then share the explained variance among correlated predictors with the LMG method. Papers usually state these tools without proof. These notes collect the main mathematical facts behind them.

1. The KZ filter

Definition 1. For an odd window \(m = 2q+1\), the centred moving average of a sequence \(x\) is \((A_m x)_t = \frac1m\sum_{j=-q}^{q} x_{t+j}\). The KZ filter with window \(m\) and \(k\) iterations is \(\mathrm{KZ}_{m,k} = A_m^{\,k}\).

Write \(H(\omega)\) for the frequency response of a linear filter: if \(x_t = e^{2\pi i \omega t}\), the output is \(H(\omega)\,e^{2\pi i\omega t}\), with \(\omega\) in cycles per time step.

Lemma 1 (moving average). \(A_m\) has frequency response \[ H_m(\omega) = \frac{\sin(\pi m\omega)}{m\sin(\pi\omega)}, \qquad H_m(0)=1, \] which is real, satisfies \(|H_m(\omega)|\le 1\), and vanishes at \(\omega = j/m\) for \(j = 1,\dots,q\).

Proof. Applying \(A_m\) to \(e^{2\pi i\omega t}\) gives the factor \(\frac1m\sum_{j=-q}^{q} e^{2\pi i\omega j}\). This geometric sum equals \(\frac{e^{\pi i m\omega}-e^{-\pi i m\omega}}{m\,(e^{\pi i\omega}-e^{-\pi i\omega})} = \frac{\sin(\pi m\omega)}{m\sin(\pi\omega)}\), and it is real because the weights are symmetric. The bound follows from the triangle inequality, since the weights are non-negative and sum to 1. The zeros are the zeros of \(\sin(\pi m\omega)\) with \(\sin(\pi\omega)\ne0\). \(\square\)

Proposition 1 (structure of KZ). \(\mathrm{KZ}_{m,k}\) is a linear, time-invariant filter \((\mathrm{KZ}_{m,k}x)_t = \sum_j w_j\, x_{t+j}\) with
  1. frequency response \(H_m(\omega)^k\);
  2. weights that are non-negative, symmetric (\(w_j = w_{-j}\)), sum to 1, and are supported on \(k(m-1)+1\) points;
  3. \(w_j = \Pr(U_1+\dots+U_k = j)\), where \(U_1,\dots,U_k\) are independent and uniform on \(\{-q,\dots,q\}\).

Proof. Composing linear time-invariant filters multiplies their frequency responses, which gives (1). The weights of \(A_m\) are the uniform probabilities \(1/m\) on \(\{-q,\dots,q\}\). Composing filters convolves their weights, and the \(k\)-fold convolution of a probability mass function is the distribution of a sum of \(k\) independent copies. This is (3), and (2) follows from it: the support of the sum is \(\{-kq,\dots,kq\}\), which has \(2kq+1 = k(m-1)+1\) points. \(\square\)

The probabilistic description in (3) does most of the work below.

Proposition 2 (moments and bias). Let \(s^2 = \sum_j j^2 w_j\). Then \[ s^2 = \frac{k\,(m^2-1)}{12}. \] The filter reproduces linear trends exactly, \(\mathrm{KZ}_{m,k}(a+bt) = a+bt\), and for a smooth signal \(f\) \[ (\mathrm{KZ}_{m,k} f)(t) = f(t) + \tfrac12 s^2 f''(t) + R(t), \qquad |R(t)| \le \tfrac{\mu_4}{24}\,\sup|f^{(4)}|, \] where \(\mu_4 = \sum_j j^4 w_j\).

Proof. A uniform variable on \(\{-q,\dots,q\}\) has mean 0 and variance \(\frac{q(q+1)}{3} = \frac{m^2-1}{12}\). Variances of independent variables add, so \(s^2 = k(m^2-1)/12\). For the expansion, Taylor's theorem gives \(f(t+j) = f(t) + jf'(t) + \frac{j^2}{2}f''(t) + \frac{j^3}{6}f'''(t) + \frac{j^4}{24}f^{(4)}(\xi_j)\). Multiplying by \(w_j\) and summing, the odd moments vanish by symmetry, \(\sum_j w_j = 1\), and \(\sum_j j^2 w_j = s^2\). Linear trends have \(f''=0\) and \(f^{(4)}=0\). \(\square\)

So the KZ filter smooths with bias \(\tfrac12 s^2 f''\), like a kernel smoother with bandwidth \(s\). Since \(s \approx m\sqrt{k/12}\), this explains the familiar rule of thumb that the "effective width" of the filter is proportional to \(m\sqrt k\).

Proposition 3 (cutoff frequency). As \(\omega\to0\), \[ H_m(\omega) = 1 - \frac{\pi^2 (m^2-1)}{6}\,\omega^2 + O(\omega^4), \qquad\text{so}\qquad H_m(\omega)^k \approx \exp\!\Big(-\frac{k\pi^2(m^2-1)}{6}\,\omega^2\Big). \] The frequency where the amplitude response falls to \(1/2\) is therefore approximately \[ \omega_{1/2} \approx \frac{1}{\pi}\sqrt{\frac{6\ln 2}{k\,(m^2-1)}} . \]

Proof. Use \(\sin u = u\,(1 - u^2/6 + O(u^4))\) in the numerator with \(u=\pi m\omega\) and in the denominator with \(u = \pi\omega\). The factors \(\pi m\omega\) cancel, leaving \(\frac{1-\pi^2m^2\omega^2/6}{1-\pi^2\omega^2/6} + O(\omega^4) = 1-\frac{\pi^2(m^2-1)}{6}\omega^2 + O(\omega^4)\). Then \(\log H_m^k = k\log H_m = -\frac{k\pi^2(m^2-1)}{6}\omega^2 + O(k\omega^4)\). Setting the Gaussian approximation equal to \(1/2\) and solving gives \(\omega_{1/2}\). \(\square\)

The approximation is accurate for the filters used in practice (computed numerically):

Filter\(s\) (days)Half-amplitude period, exactApproximation
KZ(3,3)1.417.8 days7.5 days
KZ(15,5)9.6652.3 days51.6 days

Note that the half-amplitude period of KZ(15,5) is about 52 days, noticeably longer than the value \(15\sqrt5\approx33\) days often quoted. The two numbers measure different things: \(m\sqrt k\) is a width in the time domain, while \(1/\omega_{1/2}\) is where the filter passes half the amplitude.

Proposition 4 (noise reduction). If \(\varepsilon_t\) is white noise with variance \(\sigma^2\), then \[ \operatorname{Var}\big((\mathrm{KZ}_{m,k}\varepsilon)_t\big) = \sigma^2 \sum_j w_j^2 = \sigma^2\int_{-1/2}^{1/2} H_m(\omega)^{2k}\,d\omega . \] As \(k\to\infty\), \(\sum_j w_j^2 \sim \dfrac{1}{2\sqrt{\pi}\,s}\).

Proof. The output is \(\sum_j w_j\varepsilon_{t+j}\) with uncorrelated terms, so its variance is \(\sigma^2\sum_j w_j^2\). The integral form is Parseval's identity for the sequence \(w\), whose Fourier transform is \(H_m^k\). For the asymptotic, the local central limit theorem gives \(w_j \approx \phi(j/s)/s\), where \(\phi\) is the standard normal density. Then \(\sum_j w_j^2 \approx \int \phi(u)^2\,du\,/\,s = 1/(2\sqrt\pi\,s)\). \(\square\)

For KZ(15,5) the exact value is \(\sum_j w_j^2 = 0.0288\), against the approximation \(0.0292\). So the baseline filter cuts white-noise variance by a factor of about 35.

2. Decomposing a series into time scales

For daily data, a standard decomposition (Rao and Zurbenko, 1994) applies two KZ filters to the log series \(x_t\):

\[ W = x - \mathrm{KZ}_{3,3}\,x, \qquad M = \mathrm{KZ}_{3,3}\,x - \mathrm{KZ}_{15,5}\,x, \qquad B = \mathrm{KZ}_{15,5}\,x . \]
Proposition 5. \(x = W + M + B\) exactly. The three components are linear filters of \(x\) with frequency responses \[ 1 - H_3^3, \qquad H_3^3 - H_{15}^5, \qquad H_{15}^5, \] which sum to 1 at every frequency.

Proof. The sum telescopes, and frequency responses are linear in the filter. \(\square\)

Remark (variance shares). The components are not orthogonal in general, because the three frequency responses overlap. Hence \[ \operatorname{Var}(x) = \operatorname{Var}(W)+\operatorname{Var}(M)+\operatorname{Var}(B) + 2\big[\operatorname{Cov}(W,M)+\operatorname{Cov}(W,B)+\operatorname{Cov}(M,B)\big], \] and the shares \(\operatorname{Var}(\cdot)/\operatorname{Var}(x)\) need not add up to 1. They are good for comparing time scales, but they are not a partition of the variance.

3. LMG as a Shapley value

Let \(y\) be a response and \(x_1,\dots,x_p\) predictors. For \(S \subseteq \{1,\dots,p\}\), let \(R^2(S)\) be the coefficient of determination of the least-squares fit of \(y\) on \(\{x_i : i\in S\}\) with an intercept, and \(R^2(\varnothing) = 0\).

Definition 2 (LMG). For an ordering \(r\) of \(\{1,\dots,p\}\), let \(S_j(r)\) be the predictors that come before \(j\). The LMG share of predictor \(j\) is \[ \mathrm{LMG}_j = \frac1{p!}\sum_{r}\Big[R^2\big(S_j(r)\cup\{j\}\big)-R^2\big(S_j(r)\big)\Big]. \]
Theorem 1.
  1. (Subset form.) \(\displaystyle \mathrm{LMG}_j = \sum_{S \subseteq \{1..p\}\setminus\{j\}} \frac{|S|!\,(p-|S|-1)!}{p!}\Big[R^2(S\cup\{j\}) - R^2(S)\Big]\), which is the Shapley value of the game \(v(S) = R^2(S)\).
  2. (Efficiency.) \(\sum_{j=1}^p \mathrm{LMG}_j = R^2(\{1,\dots,p\})\).
  3. (Non-negativity.) \(\mathrm{LMG}_j \ge 0\).
  4. (Symmetry.) If swapping \(x_i\) and \(x_j\) leaves every \(R^2(S)\) unchanged, then \(\mathrm{LMG}_i = \mathrm{LMG}_j\).
  5. (Null predictor.) If \(R^2(S\cup\{j\}) = R^2(S)\) for every \(S\), then \(\mathrm{LMG}_j = 0\).

Proof. (1) Fix \(S\) not containing \(j\). An ordering has \(S_j(r) = S\) exactly when it lists the elements of \(S\) in some order, then \(j\), then the rest in some order. There are \(|S|!\,(p-|S|-1)!\) such orderings, and grouping the sum in Definition 2 by \(S\) gives the subset form. (2) Within one ordering, adding the increments of all \(p\) predictors telescopes to \(R^2(\{1..p\}) - R^2(\varnothing) = R^2(\{1..p\})\). Averaging over orderings keeps this value. (3) Least squares on a larger set of columns minimises the residual sum of squares over a larger space, so \(R^2(S\cup\{j\})\ge R^2(S)\). Every increment is non-negative, and so is their average. (4) and (5) follow directly from the subset form. \(\square\)

Proposition 6 (uncorrelated predictors). If the predictors are mutually uncorrelated, then \(\mathrm{LMG}_j = r_j^2\), the squared correlation between \(x_j\) and \(y\).

Proof. After centring, uncorrelated predictors are orthogonal vectors, so the projection of \(y\) onto their span is the sum of the projections onto each one. Hence \(R^2(S) = \sum_{i\in S} r_i^2\). Every increment of \(j\) equals \(r_j^2\), whatever the ordering. \(\square\)

So LMG only does something non-trivial when predictors are correlated, which is exactly the case of temperature, humidity and wind. Two predictors already show how it splits shared variance.

Proposition 7 (two predictors). Let \(r_1, r_2\) be the correlations of \(x_1, x_2\) with \(y\), and \(\rho\) the correlation between \(x_1\) and \(x_2\), with \(|\rho|<1\). Then \[ R^2(\{1,2\}) = \frac{r_1^2 + r_2^2 - 2\rho\, r_1 r_2}{1-\rho^2}, \qquad \mathrm{LMG}_1 = \tfrac12\Big[r_1^2 + R^2(\{1,2\}) - r_2^2\Big]. \]

Proof. For standardised variables, \(R^2 = \mathbf r^\top C^{-1}\mathbf r\), where \(\mathbf r = (r_1,r_2)^\top\) and \(C = \begin{pmatrix}1&\rho\\\rho&1\end{pmatrix}\). Inverting \(C\) gives the first formula. There are two orderings: in \((1,2)\) the increment of \(x_1\) is \(r_1^2\), and in \((2,1)\) it is \(R^2(\{1,2\}) - r_2^2\). Average them. \(\square\)

Each predictor gets its own \(r_j^2\) half the time and its increment over the other predictor half the time. The shared part of the explained variance is split evenly, which is the sense in which LMG is "fair".

4. Implementation

The subset form gives a direct algorithm with \(2^{p-1}\) regressions per predictor, which is cheap for a handful of weather variables. A tested Python version (the shares add up to the full \(R^2\), as Theorem 1 requires):

import numpy as np, pandas as pd
from itertools import combinations
from math import factorial

def kz(x, m, k):
    """KZ filter: k passes of a centred moving average of width m."""
    y = pd.Series(x, dtype=float)
    for _ in range(k):
        y = y.rolling(m, center=True, min_periods=1).mean()
    return y.to_numpy()

def r2(X, y):
    X1 = np.column_stack([np.ones(len(y)), X])
    beta, *_ = np.linalg.lstsq(X1, y, rcond=None)
    return 1 - (y - X1 @ beta).var() / y.var()

def lmg(X, y):
    """Shapley shares of R^2 (Theorem 1, subset form)."""
    p = X.shape[1]
    out = np.zeros(p)
    for j in range(p):
        others = [i for i in range(p) if i != j]
        for s in range(p):
            for S in combinations(others, s):
                w = factorial(s) * factorial(p - s - 1) / factorial(p)
                out[j] += w * (r2(X[:, list(S) + [j]], y) - r2(X[:, list(S)], y))
    return out

In R, the kza package provides kz(), and relaimpo::calc.relimp(fit, type = "lmg") computes LMG shares.

5. An application

We used this approach to compare PurpleAir low-cost sensors with regulatory EPA monitors in Cook County, Illinois. The low-cost sensors were more sensitive to weather than the reference monitors: wind speed explained the most in the short-term component, and relative humidity in the baseline. Details are in Kumar et al. (2024).

Exercises

  1. Show that \(\mathrm{KZ}_{m,k}(t^3) = t^3 + 3s^2 t\). What does this say about the filter near a peak of a smooth signal?
    Show answer

    \(\sum_j w_j (t+j)^3 = t^3 + 3t^2\sum_j jw_j + 3t\sum_j j^2 w_j + \sum_j j^3 w_j = t^3 + 3s^2t\), since the odd moments vanish by symmetry. This agrees with Proposition 2 (here \(f'' = 6t\) and \(f^{(4)}=0\), so the expansion is exact). In general the bias is \(\tfrac12 s^2 f''\). At a peak \(f''<0\), so the filter lowers peaks (and raises troughs) by about \(\tfrac12 s^2|f''|\): short, sharp pollution episodes are flattened in the baseline.

  2. Using Proposition 1(3) and the central limit theorem, explain why \(\mathrm{KZ}_{m,k}\) behaves like a Gaussian kernel smoother with bandwidth \(s\) when \(k\) is large.
    Show answer

    The weights are the distribution of a sum of \(k\) independent uniform variables with total variance \(s^2\). By the local central limit theorem, \(w_j \approx \phi(j/s)/s\), so \((\mathrm{KZ}_{m,k}f)(t) \approx \sum_j \frac1s\phi(j/s)\,f(t+j)\), a Gaussian kernel smoother with bandwidth \(s\). The frequency side agrees: since \(\frac{k\pi^2(m^2-1)}{6} = 2\pi^2 s^2\), Proposition 3 says \(H_m^k(\omega)\approx e^{-2\pi^2 s^2\omega^2}\), which is exactly the Fourier transform of a Gaussian with standard deviation \(s\).

  3. For three mutually correlated predictors, write \(\mathrm{LMG}_1\) as a weighted sum of four increments and give the weights.
    Show answer

    From the subset form with \(p=3\), the weight for \(|S| = 0, 1, 2\) is \(\frac{|S|!\,(2-|S|)!}{6} = \frac13, \frac16, \frac13\): \[ \mathrm{LMG}_1 = \tfrac13 R^2(1) + \tfrac16\big[R^2(1,2)-R^2(2)\big] + \tfrac16\big[R^2(1,3)-R^2(3)\big] + \tfrac13\big[R^2(1,2,3)-R^2(2,3)\big]. \] The weights add up to 1. Entering first or last each happens in 2 of the 6 orderings; entering second after a specific predictor happens in 1.

  4. Give an example with \(\rho \neq 0\) where \(x_2\) is uncorrelated with \(y\) (\(r_2 = 0\)) but \(\mathrm{LMG}_2 > 0\). Interpret it.
    Show answer

    With \(r_2 = 0\), Proposition 7 gives \(R^2(\{1,2\}) = r_1^2/(1-\rho^2)\) and \(\mathrm{LMG}_2 = \tfrac12\big[R^2(\{1,2\}) - r_1^2\big] = \tfrac12\,\frac{r_1^2\rho^2}{1-\rho^2} > 0\). A concrete case: \(y = z\), \(x_1 = z + u\), \(x_2 = u\), with \(z, u\) independent. Then \(x_2\) is uncorrelated with \(y\), yet \(y = x_1 - x_2\) exactly, so \(R^2 = 1\). This is a suppressor variable: \(x_2\) explains nothing about \(y\) directly, but it removes the noise in \(x_1\). LMG gives it credit for that.

References