insight icon indicating copy to clipboard operation
insight copied to clipboard

checking diagonal elements of a covariance matrix is insufficient to diagnose singularity

Open bbolker opened this issue 1 year ago • 5 comments

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

bbolker avatar May 30 '24 21:05 bbolker

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?

strengejacke avatar Jun 03 '24 07:06 strengejacke

That's a good idea. Where is the insight helper function used?

bwiernik avatar Jun 03 '24 13:06 bwiernik

in compute_variances, here

bbolker avatar Jun 03 '24 13:06 bbolker

Do you have an example of a model we can use for tests?

strengejacke avatar Jun 05 '24 08:06 strengejacke

I re-opened after merging the PR, because I still want to add some tests.

strengejacke avatar Jun 12 '24 08:06 strengejacke

I think it's ok to rely on tests in performance, since insight now just calls performance::check_singularity().

strengejacke avatar Nov 05 '24 22:11 strengejacke

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 ...)

bbolker avatar Nov 05 '24 23:11 bbolker