DecompositionFilterResult._penalized_result#

classmethod DecompositionFilterResult._penalized_result(panel, penalty, order, method)[source]#

Run the penalized smoother and package it.

Solves \((I + \lambda D'D)\tau = y\) column by column, records the cutoff period \(\pi / \arcsin(\lambda^{-1/2n} / 2)\), and flags the first and last \(\lceil \text{cutoff} \rceil\) rows (capped at half the sample) as provisional. Shared by HodrickPrescottFilter and ButterworthFilter, which differ only in how they arrive at penalty and order.

Parameters:
  • panel (NDArray[double]) – The validated (nobs, k) panel.

  • penalty (float) – The smoothing weight \(\lambda\).

  • order (int) – Differences penalized, \(n\).

  • method (str) – "hodrick-prescott" or "butterworth".

Return type:

DecompositionFilterResult

Returns:

The DecompositionFilterResult with every row kept.

Example

>>> t = np.arange(60.0)[:, None]
>>> res = DecompositionFilterResult._penalized_result(
...     2.0 + 0.5 * t, 1600.0, 2, "hodrick-prescott"
... )
>>> bool(np.abs(res.cycle).max() < 1e-8), round(res.cutoff, 1)
(True, 39.7)
>>> int(res.provisional.sum()), bool(res.provisional.all())
(60, True)