linalg
condition_number
Ratio of largest to smallest eigenvalue of a symmetric matrix.
Returns ``inf`` for a singular matrix. Used as an empirical-identification diagnostic: a very large condition number on the observed covariance matrix means the data carry little independent information about some directions in parameter space, whatever the algebraic identification rules say.
corr_matrix
Sample correlation matrix of the columns of ``x``.
cov_matrix
Sample covariance matrix of the columns of ``x``.
cov_to_corr
Convert a covariance matrix to the corresponding correlation matrix.
is_positive_definite
True if all eigenvalues of the symmetric matrix ``a`` exceed ``tol``.
is_symmetric
True if ``a`` is square and symmetric to within ``tol``.
logdet
Log determinant of a symmetric positive-definite matrix.
Raises ``ValueError`` when the matrix is not positive definite, because the maximum-likelihood discrepancy function is undefined in that case and silently returning ``-inf`` would hide a model that has failed.
nearest_positive_definite
Project a symmetric matrix onto the positive-definite cone.
Eigenvalues below ``floor`` are raised to ``floor``. This is a repair, not an estimate; anything using it should say so. In this package it is used only when a disattenuated latent correlation matrix comes back indefinite, which is itself a finding worth reporting (see :mod:`ehs_risk_sem.diagnostics`).
safe_inverse
Invert a symmetric matrix, optionally with a ridge, reporting trouble.
Returns the inverse and a warning string (or ``None``). The warning is returned rather than raised so that a caller running thousands of simulation replications can count problem cases instead of aborting.
smallest_eigenvalue
Smallest eigenvalue of a symmetric matrix.
standardize
Return ``x`` with each column centred and scaled to unit variance.
Columns with zero variance are returned centred but unscaled, and a ``ValueError`` is raised only if every column is constant, because a constant indicator is a data problem the caller should see rather than a numerical edge case to be smoothed over.
vech
Half-vectorization: the lower triangle of a symmetric matrix, including the diagonal, as a 1-d array. Its length ``p(p+1)/2`` is the number of non-redundant observed moments available to identify a model.