insight
insight copied to clipboard
checking diagonal elements of a covariance matrix is insufficient to diagnose singularity
insight has a helper function that claims to check singularity of mixed effect models. It does it by checking to see if any of the diagonal elements of the random effects covariance matrix are less than a tolerance value.
This is insufficient for "unstructured" (general positive definite) covariance matrices with dimension > 2 (and maybe >1, I'm not sure).
See https://github.com/easystats/performance/pull/684
- The most general (but least efficient) check is to extract the covariance matrice(s) and see if any of their eigenvalues are less than a tolerance.
- for
lme4, which parameterizes the covariance matrices by their Cholesky factor, checking the diagonal elements is sufficient - if the covariance structure is known to have a special form (e.g. diagonal!) then one may be able to check more easily.
### Tasks
We have an improved implementation in the performance package: https://github.com/easystats/performance/blob/main/R/check_singularity.R
Maybe we should this code instead?
That's a good idea. Where is the insight helper function used?
in compute_variances, here
Do you have an example of a model we can use for tests?
I re-opened after merging the PR, because I still want to add some tests.
I think it's ok to rely on tests in performance, since insight now just calls performance::check_singularity().
For it's worth it's not obvious why this line uses abs() in any(abs(theta[diag.element]) < tolerance), as these elements are guaranteed to be non-negative ... (harmless though) (oops, this is a comment about code in the performance package ...)