Skip to main content

Crate glmm

Crate glmm 

Source
Expand description

glmm — standalone f64 GLMM fit kernels (OLS → GLM → LMM → GLMM).

Two public surfaces:

  • fit_cold/fit_warm + ModelSpec + GroupIds: the stable, semver-covered friendly API.

  • loop_advanced (cargo feature, off by default): the unstable scratch-explicit hot-path surface (loop tier) that warm-start consumers like MCPower bind to, exposing the kernels and StartValues. NO semver guarantees.

  • formula (cargo feature, on by default): the R-style formula frontend — formula::lower("y ~ x + (1|g)", &table, family) builds the kernel’s inputs from a formula string and a data table instead of by hand.

  • orchestrate (cargo feature, off by default): the string-typed fit orchestration the FFI ports (glmm-python, glmm-r) share — like loop_advanced, NO semver guarantees.

parallel (cargo feature, off by default, experimental): enables in-fit parallelism (AGQ cluster loop, FD-Hessian grid) via rayon’s global pool; a no-op on wasm32; gated at runtime by FitOptions::parallel_inner (also off by default — both the feature and the knob are explicit opt-ins).

Modules§

consts
Scratch-bounding capacity constants. glmm owns these; they size the solver’s stack buffers, so they are HARD ceilings. These ceilings live here in consts as the single source, no drift.
dual
Crate-own forward-mode dual number types.
formula
R-style formula frontend for the glmm kernel.
linalg
Linear-algebra primitives shared by the sim and fit layers.
scalar
The scalar type the blocked fit kernel is generic over.
simd_transcendental
Restricted-domain SIMD transcendentals for the GLM/GLMM fit path — a single compiled-in, full-precision exp/log1p that vectorizes across the PIRLS row loop (the scalar libm exp/ln_1p are extern calls the compiler cannot vectorize; profiling put them at ~51% of the no-extras GLMM fit).

Structs§

Diagnostics
Everything a fit reports about itself, reached as fit.diagnostics.
Fit
Result of fit. Fixed-effect estimates cover all p predictors; SE and tau2 have the ranges below. Non-target SE slots are NaN.
FitOptions
Options for fit. Carries the safe, defaulted method knobs: unlike a warm start these do not silently move the estimate based on a caller’s guess.
GroupIds
Per-row random-effect level ids for one fit. Each vector has length n.
Grouping
An extra (crossed or nested) grouping factor beyond the primary grouping. slopes are the random-slope design columns; the RE correlation structure is always full (parametrized by the fitted θ). Structure-only, like ModelSpec: magnitudes and warm starts are not carried here.
ModelSpec
The kernels’ model-spec input. family selects the outcome kernel; re selects fixed-only vs mixed (None → OLS/GLM, Some → LMM/GLMM).
ReStructure
Random-effect structure of a mixed model — present iff the model has random effects. Carried in ModelSpec::re as Option, so None is a fixed-only model (OLS/GLM) and Some is mixed (LMM/GLMM): an OLS-with-grouping state is unrepresentable. Holds exactly the RE fields the LMM/GLMM kernels read.
StartValues
Raw optimizer warm-start state for one model fit.

Enums§

BinomialLink
Binomial link function. Logit is canonical (the fused-SIMD kernel); Probit and Cloglog both use the general Fisher-scoring branch.
Boundary
Where the accepted θ sits in its parameter space.
Family
Outcome distribution + link. Selects the fit kernel together with ModelSpec::re (re.is_some() ⇒ mixed): Gaussian → OLS / LMM, Binomial{Logit} → GLM / GLMM. Every variant here has a wired kernel, so no kernel-less variant is reachable through crate::fit_cold.
GammaLink
Gamma link function. Log is the safe default; Inverse is the classic Gamma link but can drive μ≤0 mid-IRLS (domain-clamped).
GroupingRelation
How an extra grouping’s clusters map onto rows, relative to the primary grouping.
InverseGaussianLink
Inverse-Gaussian link function. Log is the safe default; InverseSquared is R’s inverse.gaussian() default and can drive μ≤0 mid-IRLS (domain-clamped).
NegBinomialLink
Negative-binomial link function. Only the log link is offered.
Note
A solver observation about the fit that has no dedicated field. The enum variant, not any English sentence, is the stable identifier a caller filters on; the wrappers turn each variant into their own warning category (Python) or condition class (R).
PoissonLink
Poisson link function. Only the canonical log link is offered.
Sizing
Cluster sizing regime: a fixed cluster count, or a fixed per-cluster size.
WaldSe
GLMM fixed-effect Wald-SE denominator.

Constants§

THETA0
The blind θ start. Re-exported because a caller that must supply StartValues (β and θ are bundled) cannot reach the None-θ blind path, and so has to reproduce that start explicitly. θ start — DIAGONAL vech entries only; off-diagonals cold-start at 0 (unit diagonal, the lme4/MixedModels.jl default — the blind_theta_and_bounds shape). Cold start per fit; no warm-start across sims (would re-import cross-grid-point path dependence).

Functions§

fit_cold
Cold single fit — the default real-data entry. Random-effect level ids are supplied per-row via ids (GroupIds); every level count is derived from them, so ModelSpec stays structure-only. Exactly fit_warm(.., None, ..).
fit_warm
Warm single fit — identical to fit_cold but accepts an optional StartValues warm start. Some warm-starts the optimizer; None cold-starts (byte-identical to fit_cold). One fit, one answer — the start only shortens the path. The start threads beta+theta into the LMM/GLMM kernels; fixed-only (OLS/GLM) and the NB global-θ search ignore it (see crate::StartValues).

Type Aliases§

ColumnId
Predictor column index — indexes into the p-wide design matrix x.