0
$\begingroup$

I'm trying to fit the following reproducible mediation model called final. But I get an error saying:

sigma must be a symmetric matrix

Could you please advise how I can possibly overcome this error?

Reproducible R code:

df <- read.csv("https://raw.githubusercontent.com/fpqq/w/refs/heads/main/t.csv")

library(glmmTMB)
library(mediation)

mediator <- glmmTMB(pic_percent ~ con +
                      (0+con | ID) +
                      (0+con | TRIAL_INDEX),
                    data=df,
        family = beta_family(),
        ziformula = ~1)

outcome <- glmmTMB(acc ~ con + pic_percent +
                      (0+con+pic_percent | Q),
                     data = df,
                   family = binomial())

final <- mediate(mediator, outcome, sims=50,
                    treat="con", mediator="pic_percent")
$\endgroup$
0

1 Answer 1

1
$\begingroup$

Why mediation models require a sigma matrix that is symmetric

For real random variables covariance doesn't care which variable comes first:

$\operatorname{Cov}(A,B) = \operatorname{Cov}(B,A)$

(the "Cov" operator is commutative).

This is essentially because multiplication is commutative ($2\times 3 = 3\times 2$ etc) and covariance is the expected value of a product of mean-corrected variables.

Consequently, variance-covariance matrices are symmetric, since

$\operatorname{Cov}(A_i,A_j) = \operatorname{Cov}(A_j,A_i)$.

See https://en.wikipedia.org/wiki/Covariance_matrix#Basic_properties (property 3)

Consequently a matrix that is not symmetric is not a correctly formed variance-covariance matrix. Presumably sigma needs to be a valid variance-covariance matrix.

It's not immediately obvious to me from your code exactly why you encounter the issue. There are various reasons why a numerically-computed set of covariances may end up asymmetric. For example, presence of missing values combined with pairwise deletion, or simple accumulation of floating point errors, or a number of other issues.

If it's caused by something you're supplying, you can take steps to make sure that's symmetric. If it's caused by some internal calculations in those functions you're calling, that's more of a problem.

I don't plan to investigate your code in detail, however.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.