nonlinear_mixed_lm
Fit a nonlinear model with a per-group random intercept using penalized least squares, returning fixed parameters and random-effect estimates for grouped data.
Instructions
Fit a nonlinear model with one random intercept per group, approximately.
The model is ``y = f(x; params) + b_g + error`` where ``b_g`` is a random
intercept shared by the observations of group ``g``. ``model`` is a sympy
expression in ``x`` (the independent-variable name is always ``x``, taken
from the column named by the ``x`` argument) and the parameter names given
by the keys of ``p0``.
``data`` is either a ``{column: list}`` mapping or an ``"@<path>.csv"``
reference (relative paths resolve against ``output_dir()``). ``groups``,
``x`` and ``y`` are column names. All fixed parameters and every ``b_g``
are optimized together with ``scipy.optimize.least_squares``, minimizing
``sum((y - f(x; params) - b_g)^2) + penalty * sum(b_g^2)``. Setting
``random_effect=False`` drops the ``b_g`` terms and returns no
``random_effects`` field.
This is a **penalized least-squares approximation**, not a full nonlinear
mixed-effects marginal-likelihood fit: random-effect variance components
are not estimated, there is no integration over random effects, and no
standard errors are produced. The response always carries
``approximation: true`` and an explanatory ``note``.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| x | Yes | ||
| y | Yes | ||
| p0 | Yes | ||
| data | Yes | ||
| model | Yes | ||
| groups | Yes | ||
| maxiter | No | ||
| penalty | No | ||
| random_effect | No |