Skip to content
Prev 18021 / 20628 Next

About computing covariances between two fixed effects with 4 and 5 levels respectively.

Dear Thierry,


Thank you so much for your comment. In fact, it was the first step of the analysis:

Mol<- glmmTMB(Observations ~ CAP * Condition  + (1|ID), data=mDATA, ziformula=~ 1, family=nbinom1)

I aimed to investigate  the differences between the CAPs (CAP: c1, c2, c3, c4), across 5 conditions (Condition: base, neu, pneu, aff, paff). For this purpose, implemented the Anova function (glmmTMB), and the emmeans package for assessing the interactions.

Another question to answer is how related (i.e., Pearson coefficients for normally distributed and independent data)  are those CAPs to each other,  across conditions (Condition: neu, pneu, aff, paff), being from the same individuals (N=20).  In the previous email, you were right when pointing my confusion between fixed  and random effects.  So, I went on solving my problem, and I found two alternative solutions:

1)   Taking the previous model:
Mol<- glmmTMB(Observations ~ CAP * Condition  + (1|ID), data=mDATA, ziformula=~ 1, family=nbinom1)

We can compute the corr/cov

(vcov(Mol)$cond)

I assume that the output covariance structure is autoregresive (AR1).(Question aside: Is there any way to change the structure when using his function?)

2) Following the previously cited vignette:
https://cran.r-project.org/web/packages/glmmTMB/vignettes/covstruct.html

I found the following alternative:
fit.us <- glmmTMB(Observations ~ us(CAP * Condition +  0 | group), data=mDATA)

Where the"group "variable" is just a 1 in every row of the data, and "us" corresponds to the"heterogeneous unstructured" covariance structure.

Regardless of the method, I obtain a correlation values (-1 to 1), of the covariances of the random effect (ID). Therefore, my questions to solve are:
1) Would it be right to interpret the output "correlation" values as the evaluation of the relationship between the factors "CAP" and "Condition" (fixed effects), based on the number of counts  reported in "Observations" (random effect)?

2) I do not manage to obtain the cov/corr values from the intercept. For instance, if the intercept values corresponds to"CAP:c1, Condition: base" how can I obtain the corr/cov values corresponding to the regressors from itself? e.g.:

CAP:c1, Condition: base" - CAP:c1, Condition: neu"
CAP:c1, Condition: base" - CAP:c1, Condition: pneu"
CAP:c1, Condition: base" - CAP:c1, Condition: aff"
CAP:c1, Condition: base" - CAP:c1, Condition: paff"

Thank you so much in advance for any comment.



Julian Gaviria
Neurology and Imaging of cognition lab (Labnic)
University of Geneva. Campus Biotech.
9 Chemin des Mines, 1202 Geneva, CH
Tel: +41 22 379 0380
Email: Julian.GaviriaLopez at unige.ch