API Reference
birm.data
Ragged multi-metric training data on a shared daily grid.
MetricData
dataclass
Observations for one response metric on the shared grid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
ndarray
|
Observed values \(Y^{(j)}\), length |
required |
idx
|
ndarray
|
Integer positions into the shared grid, length |
required |
exog
|
dict[str, ndarray]
|
Exogenous columns \(X^{(j)}\), each length |
dict()
|
Panel
dataclass
Shared daily grid plus per-metric ragged observations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
grid
|
DatetimeIndex
|
Contiguous daily grid spanning |
required |
load
|
ndarray
|
Training load \(w_t\), dense length |
required |
metrics
|
dict[str, MetricData]
|
Response metrics, each with its own values, grid positions, and exog. |
required |
scaling
|
dict[str, tuple[float, float]]
|
|
dict()
|
T
property
Number of days on the shared grid.
Returns:
| Type | Description |
|---|---|
int
|
Length of |
densest()
Metric with the most observations (auto-pinned to \(\gamma \equiv 1\)).
Returns:
| Type | Description |
|---|---|
str
|
Name of the metric with the largest number of observed days. |
from_long(df, date, metric, value, load, exog=None)
classmethod
Build a Panel from one tidy long table.
Each row carries a (date, metric, value) reading; the metric's exog columns ride on
the same rows. Missingness is implied by absent (date, metric) rows.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Long-form table with ISO-date, metric-label, and value columns. |
required |
date
|
str
|
Name of the ISO-date column. |
required |
metric
|
str
|
Name of the metric-label column. |
required |
value
|
str
|
Name of the value column. |
required |
load
|
str
|
Metric label that denotes the training load \(w_t\). |
required |
exog
|
dict[str, list[str]]
|
Per-metric exogenous column names, read off that metric's rows. |
None
|
Returns:
| Type | Description |
|---|---|
Panel
|
Validated panel. |
from_sheets(sheets, date, load, exog=None)
classmethod
Build a Panel from one sheet per metric.
Each sheet has a date column, a value column named after the metric, and that metric's
own exog columns; blank cells mark unobserved days.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sheets
|
dict[str, DataFrame]
|
Mapping of metric name to its wide sheet. |
required |
date
|
str
|
Name of the ISO-date column present in every sheet. |
required |
load
|
str
|
Sheet name that denotes the training load \(w_t\). |
required |
exog
|
dict[str, list[str]]
|
Per-metric exogenous columns, found within each metric's own sheet. |
None
|
Returns:
| Type | Description |
|---|---|
Panel
|
Validated panel. |
standardize()
Center/scale each response and its exog, rescale load to average-day units.
Each response metric's values and exog columns are z-scored (center/scale stored in
scaling for back-transform); load is rescaled by its own mean so gains stay
\(O(1)\).
Returns:
| Type | Description |
|---|---|
Panel
|
A new standardized panel. |
birm.model
The impulse-response model specification.
IRModel
dataclass
Declarative spec of the shared-stock multivariate impulse-response model.
Selects one impulse-response core \(R_t\) and attaches one observation layer per
Metric. Call fit with a
Panel to sample.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
load
|
Load
|
The training-load driver \(w_t\). |
required |
core
|
str
|
Impulse-response core; one of |
required |
metrics
|
tuple[Metric, ...]
|
Response metrics sharing the single latent stock. |
required |
priors
|
dict[str, Prior]
|
Optional overrides for named model parameters (e.g. |
dict()
|
parameterization
|
str
|
Latent-stock prior geometry; one of |
'informed'
|
build_model(panel)
Assemble the PyMC model binding this spec to panel.
Validates the spec against the panel, builds the shared latent stock \(R_t\) from the
selected cores, then attaches one observation layer and obs_<name> likelihood per
metric.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
panel
|
Panel
|
Observations to bind, with metric names matching this spec's Metric names. |
required |
Returns:
| Type | Description |
|---|---|
Model
|
The assembled model, ready to sample. |
fit(panel, sampler=None)
Validate this spec against panel, build the model, and sample the posterior.
Checks that every spec metric exists in the panel with resolvable exog columns, warns on unused panel metrics, assembles the PyMC model via build_model, then samples.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
panel
|
Panel
|
Observations to fit, with metric names matching this spec's Metric names. |
required |
sampler
|
dict[str, Any]
|
Overrides merged over the R&D defaults ( |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
An |
Raises:
| Type | Description |
|---|---|
ValueError
|
If a spec metric is missing from the panel, or references an exog column that metric does not carry. |
Load
dataclass
The training-load driver \(w_t\) of the latent stock shared across metrics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Series name identifying the load in the Panel. |
required |
Metric
dataclass
One response series \(Y^{(j)}\) as a noisy readout of the shared stock.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Metric name; must match a key in |
required |
link
|
str
|
Link function \(l^{(j)}\); one of |
'identity'
|
exog
|
tuple[str, ...]
|
Exogenous predictor columns \(X^{(j)}\) ( |
()
|
ar1
|
bool
|
Whether to include the orthogonalized lag-1 process \(u^{(j)}\). |
False
|
intercept
|
bool
|
Whether to include the intercept \(\alpha^{(j)}\). |
True
|
gamma
|
float
|
Fixed scale \(\gamma^{(j)}\). If |
None
|
offset
|
bool
|
Whether to read this metric's stock at a shifted time \(r_{t-d}\) with an integer lag
\(d\) (support \(\{0,\dots,14\}\) if causal, else \([-14,14]\)) under a 0-centered discrete
Gaussian prior, marginalized out via |
False
|
Prior
dataclass
A named prior distribution with its keyword parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dist
|
str
|
PyMC distribution name (e.g. |
required |
params
|
dict[str, Any]
|
Keyword arguments passed through to the distribution. |
dict()
|