Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Convergence diagnostics for mixed-effects models.

Classes:

NameDescription
ConvergenceMessageA convergence diagnostic message with technical and user-friendly parts.

Functions:

NameDescription
diagnose_convergenceAnalyze model convergence state and generate diagnostic messages.
format_convergence_warningsFormat convergence messages for display as warning text.

Classes

ConvergenceMessage

ConvergenceMessage(category: str, technical: str, explanation: str, tip: str | None = None) -> None

A convergence diagnostic message with technical and user-friendly parts.

Attributes:

NameTypeDescription
categorystrType of issue (“singular”, “correlation”, “boundary”, “convergence”)
technicalstrlme4-style technical message
explanationstrUser-friendly explanation of the issue
tipstr | NoneActionable suggestion to fix the issue (optional)

Attributes

category
category: str
explanation
explanation: str
technical
technical: str
tip
tip: str | None = None

Functions

diagnose_convergence

diagnose_convergence(theta: np.ndarray, theta_lower: list[float], group_names: list[str], random_names: list[str] | dict[str, list[str]], re_structure: str | list[str] | dict[str, str], sigma: float, converged: bool, boundary_adjusted: bool, restarted: bool, optimizer_message: str = '', singular_tol: float = 0.0001, corr_tol: float = 0.99) -> list[ConvergenceMessage]

Analyze model convergence state and generate diagnostic messages.

Parameters:

NameTypeDescriptionDefault
thetandarrayOptimized theta parameters (Cholesky factors, relative scale).required
theta_lowerlist[float]Lower bounds for each theta element.required
group_nameslist[str]Names of grouping factors.required
random_nameslist[str] | dict[str, list[str]]Names of random effects per group.required
re_structurestr | list[str] | dict[str, str]RE structure per group (“intercept”, “diagonal”, “slope”).required
sigmafloatResidual standard deviation (1.0 for GLMMs).required
convergedboolWhether optimizer reported convergence.required
boundary_adjustedboolWhether boundary checking adjusted parameters.required
restartedboolWhether restart_edge triggered a restart.required
optimizer_messagestrMessage from optimizer (for non-convergence).‘’
singular_tolfloatTolerance for near-zero variance detection.0.0001
corr_tolfloatTolerance for degenerate correlation detection (corr

Returns:

TypeDescription
list[ ConvergenceMessage ]List of ConvergenceMessage objects describing any issues found.

format_convergence_warnings

format_convergence_warnings(messages: list[ConvergenceMessage]) -> str

Format convergence messages for display as warning text.

Uses paired format: technical message (deemphasized) followed by explanation (prominent), without explicit labels.

Parameters:

NameTypeDescriptionDefault
messageslist[ ConvergenceMessage ]List of ConvergenceMessage objects.required

Returns:

TypeDescription
strFormatted warning string.