Skip to main content
A macro exists when the same logic would otherwise be copy-pasted across models a shrinkage formula, a filter predicate, a numeric approximation. Defining it once means every consumer shares one definition instead of several silently-diverging copies. A macro’s full signature, arguments, and worked example live on its own generated reference page, linked from each card below.

Validation

assert_additive_identity

Proves an additive decomposition holds to tolerance: total = Σ(components) + residual. The shared engine behind the lap seven-term identity test and its worked macro-usage duplicate; the other identity-closure tests assert different identity shapes with their own inline SQL rather than this macro.

Shrinkage

bayesian_shrinkage

Normal-normal conjugate shrinkage toward a prior mean, weighted by sample size. Used by the three Skill-family shrinkage models: driver-circuit affinity, driver-circuit-era affinity, and driver-season ratings.

posterior_variance

The matching posterior variance for a bayesian_shrinkage estimate, used by the same three models to emit standard errors and confidence-interval bounds.

Filters

clean_lap_filter

The canonical “clean lap” predicate correction_weight = 1.0, no mistake/conditions anomaly class, no rain for any model extracting a driver-skill signal. Defined as the recommended pattern so skill extraction can’t silently diverge; no model calls it directly today, since each current skill-extracting model inlines the equivalent three-condition filter itself.

Mapping

normalize_compound

Maps 2018’s legacy seven-compound names onto the modern SOFT/MEDIUM/HARD set so compound-parameter joins don’t go NULL for that season. Scoped to ML-facing feature joins only applying it inside the compound-cliff model itself would silently re-attribute compound effects as driver skill. Not called by any model today.

circuit_id_from_name

Slugifies a circuit’s display name into a stable physical-venue ID, collapsing renamed events and same-venue double-headers onto one identifier. Used by int_driver_circuit_era_affinity and dim_circuits.

Numeric

normal_cdf

The standard normal CDF Φ(x), inlined via a Zelen & Severo rational approximation since DuckDB has no erf builtin. Used by fct_ghost_race_finish to turn pairwise predicted-pace gaps into finish-order probabilities.