equatiomatic icon indicating copy to clipboard operation
equatiomatic copied to clipboard

Add option to omit triangle in variance-covariance matrices?

Open andrewheiss opened this issue 3 years ago • 1 comments

When estimating lme4 models with multiple random slopes, the results include variances (σ²) and covariances (ρ) for each of the terms and their random intercepts, like female (β1) and ses (β2) and their intercepts (α) here:

library(lme4)
library(equatiomatic)

hsb2 <- lmer(
  math ~ female + ses + minority + (female + ses | sch.id),
  hsb
)
extract_eq(hsb2)
operatorname_mat

There's a lot of duplicated information in the variance/covariance matrix (ρ_αjβ1j vs. ρ_β1jαj). One really neat solution to this that I recently came across (in https://doi.org/10.1111/2041-210X.13755) is to omit the covariances in the bottom triangle and replace them with \dots, which looks a lot cleaner, especially for bigger models (here's equation 30 from that paper):

image

In equatiomatic, hsb2 could look something like this:

operatorname_mat-1

I'm not sure how complicated the code is for creating that array LaTeX environment, but adding (yet another) argument to extract_eq() that runs something like covar_matrix[lower.tri(covar_matrix)] <- "\dots" behind the scenes could be a neat addition.

andrewheiss avatar Jan 06 '22 17:01 andrewheiss

I like it. I'll be honest in saying I'm a bit burned out with this package at the moment though so I can't promise that it will be implemented anytime real soon, but I do think it's worth implementing.

datalorax avatar Jan 07 '22 19:01 datalorax