PriorContext#

class cultivars.bayes.priors.PriorContext(*, k_endog, order, scales, presample_mean, k_exog=0, n_deterministic=1, include_constant=True)[source]#

What a prior needs to know about the sample before it can state itself.

Built once by the estimator and read by every prior in a stack, so two priors cannot disagree about the design’s column order or a variable’s scale. Everything here comes from the data or the specification; nothing comes from the prior.

Variables:
  • k_endog (int) – Number of modelled variables.

  • order (int) – Autoregressive order.

  • scales (NDArray[double]) – Per-variable residual scale, from _minnesota_scales() in _core.

  • presample_mean (NDArray[double]) – Mean of the first order observations, which the sum-of-coefficients restriction is centred on.

  • k_exog (int) – Exogenous regressors carried after the lag block.

  • n_deterministic (int) – Width of the leading deterministic block, which is a count rather than a flag because families disagree about it: none for a trendless specification, one for a constant, two for a constant and trend, and one per unit for a fixed-effects panel. A boolean would have been silently one column short for every "ct" model and off by N - 1 for every panel, and a prior whose columns do not line up with the design is inert at the limits while still looking plausible in between – which is worse than being wrong loudly.

  • include_constant (bool) – Whether the design carries a leading intercept column. Dummy columns must match the design’s own ordering, and a prior that guesses wrong is inert at the limits while still looking plausible in between – which is worse than being wrong loudly.

Note

Construction is keyword-only and validates nothing: the arrays are not checked against k_endog and the counts are not checked for sign. Because two fields are arrays, == between contexts raises ValueError and hash raises TypeError.

include_constant is carried but not consulted. Every prior in the package places its columns from n_deterministic alone, and nothing checks that the two fields agree.

See also

  • PriorContext – the public name of this class.

  • _BayesianVectorAutoRegressionModel._prior_context() – returns an instance.

  • _ExogenousVectorAutoRegressionModel._prior_context() – returns an instance.

  • _ExogenousVectorErrorCorrectionModel._prior_context() – returns an instance.

  • _FunctionalCoefficientVectorAutoRegressionModel._prior_context() – returns an instance.

Example

A bivariate VAR(2) with a constant has five design columns, one deterministic column ahead of four lag columns:

>>> import numpy as np
>>> context = _PriorContext(
...     k_endog=2,
...     order=2,
...     scales=np.array([1.0, 4.0]),
...     presample_mean=np.array([0.5, 2.0]),
... )
>>> context.width, context.lag_offset
(5, 1)

Attributes#

k_endog

Number of modelled variables \(k\), which is also the number of equations.

order

Autoregressive order p; the lag block is k_endog * order columns wide.

scales

Per-variable residual standard deviation \(s_i\), shape (k_endog,).

presample_mean

Mean of the first order observations of each variable, shape (k_endog,).

k_exog

Number of exogenous regressors, whose columns follow the lag block.

n_deterministic

Width of the deterministic block that leads the design.

include_constant

Whether the design carries a leading intercept column.

lag_offset

Design columns ahead of the endogenous lag block.

width

Design columns a prior's blocks must match.