incline.StateSpace

class incline.StateSpace(seasonal_periods=None)[source]

Local linear trend, optionally with seasonal and damping.

The slope is a state, so its smoothed variance is a diagonal entry of the smoother covariance and needs no extra machinery. This replaces a hand-rolled Kalman filter and a BFGS call whose inverse Hessian was discarded; statsmodels supplies both the state covariance and the hyperparameter covariance.

Variables:

seasonal_periods (int | None) – Length of a seasonal cycle, or None.

Parameters:

seasonal_periods (int | None)

Note

The intervals are conditional on the fitted variances. Those variances were estimated from the same data, and that estimation error is not propagated, so the intervals are somewhat narrow – most visibly on short series.

A correction for it was tried and removed. It scaled the interval by the relative standard error of each variance parameter, bse / |param|, which is undefined at the boundary – and variances land exactly on zero routinely, whenever a component is not needed. Measured over 40 fits, the median inflation factor was 1e5 and the maximum 3e8, turning a standard error of 0.017 into 4.6e6. A correction that can be eight orders of magnitude wrong is worse than the bias it was meant to remove.

There is likewise no damped-trend option. The previous implementation accepted one and forwarded it to statsmodels, which has no such parameter and ignored it, so the setting did nothing.

__init__(seasonal_periods=None)
Parameters:

seasonal_periods (int | None)

Return type:

None

Methods

__init__([seasonal_periods])

analytic_operators(axis, order)

State the smoothing and derivative operators directly, if known.

evaluate(axis, y, order)

Smoothed level and slope.

fit(axis, y[, order, se, noise, ...])

Estimate the trend and, optionally, its uncertainty.

native_posterior(axis, y, order, ...)

Standard error of the smoothed slope state.

operators(axis, order)

The smoothing and derivative operators for this configuration.

params()

Report the model configuration.

scale_of(axis)

Nominal scale, since smoothing is chosen by likelihood.

with_scale(scale, axis)

No direct scale knob; smoothing follows from the fitted variances.

Attributes

has_native_posterior

is_linear

Whether the derivative is a fixed linear map of the data.

linear

name

requires_regular_grid

seasonal_periods

supported_orders

name: ClassVar[str] = 'kalman'
has_native_posterior: ClassVar[bool] = True
supported_orders: ClassVar[frozenset[int]] = frozenset({1})
seasonal_periods: int | None = None
evaluate(axis, y, order)[source]

Smoothed level and slope.

Parameters:
  • axis (TimeAxis)

  • y (npt.NDArray[np.float64])

  • order (int)

Return type:

Evaluation

native_posterior(axis, y, order, confidence_level)[source]

Standard error of the smoothed slope state.

Parameters:
  • axis (TimeAxis)

  • y (npt.NDArray[np.float64])

  • order (int)

  • confidence_level (float)

Return type:

tuple[npt.NDArray[np.float64], None, None]

with_scale(scale, axis)[source]

No direct scale knob; smoothing follows from the fitted variances.

Parameters:
Return type:

Self

scale_of(axis)[source]

Nominal scale, since smoothing is chosen by likelihood.

Parameters:

axis (TimeAxis)

Return type:

float

params()[source]

Report the model configuration.

Return type:

dict[str, Any]