glmmtmb - How to solve non-numeric argument to binary operator in R? - Stack Overflow

admin2025-04-18  3

it's my first time using R. I did a panel data beta regression with logit link function (default). I tried clustered robust standard error and got an error as below:

> robust_se <- vcovCR(mixed_logit, cluster = data_used$id, type = "CR2")
Error in nobs0(x) * vcov0(x, ...) : 
  non-numeric argument to binary operator

Then I checked whether the number of observations and the variance-covariance matrix are numeric.

nobs(mixed_logit)
[1] 3544

str(vcov(mixed_logit))
List of 1
 $ cond: num [1:9, 1:9] 6.69e-02 1.45e-04 -3.86e-06 9.66e-05 -3.37e-03 ...
  ..- attr(*, "dimnames")=List of 2
  .. ..$ : chr [1:9] "(Intercept)" "female" "fparl" "fisc_indep" ...
  .. ..$ : chr [1:9] "(Intercept)" "female" "fparl" "fisc_indep" ...
 - attr(*, "class")= chr [1:2] "vcov.glmmTMB" "matrix"

From the results, (1) is the problem coming from vcov(model)? Because the numeric is in the list. (2) How to solve this problem? It is using glmmTMB package. Thank you

it's my first time using R. I did a panel data beta regression with logit link function (default). I tried clustered robust standard error and got an error as below:

> robust_se <- vcovCR(mixed_logit, cluster = data_used$id, type = "CR2")
Error in nobs0(x) * vcov0(x, ...) : 
  non-numeric argument to binary operator

Then I checked whether the number of observations and the variance-covariance matrix are numeric.

nobs(mixed_logit)
[1] 3544

str(vcov(mixed_logit))
List of 1
 $ cond: num [1:9, 1:9] 6.69e-02 1.45e-04 -3.86e-06 9.66e-05 -3.37e-03 ...
  ..- attr(*, "dimnames")=List of 2
  .. ..$ : chr [1:9] "(Intercept)" "female" "fparl" "fisc_indep" ...
  .. ..$ : chr [1:9] "(Intercept)" "female" "fparl" "fisc_indep" ...
 - attr(*, "class")= chr [1:2] "vcov.glmmTMB" "matrix"

From the results, (1) is the problem coming from vcov(model)? Because the numeric is in the list. (2) How to solve this problem? It is using glmmTMB package. Thank you

Share Improve this question edited Jan 30 at 5:42 Vinka Defitri asked Jan 30 at 5:32 Vinka DefitriVinka Defitri 11 bronze badge 1
  • 3 Are you using clubSandwich::vcovCR? glmmTMB fits don't seem to be listed as supported in the documentation. – Roland Commented Jan 30 at 6:40
Add a comment  | 

1 Answer 1

Reset to default 1

As @Roland commented, clubSandwich::vcovCR does not support glmmTMB fits. The proximal problem that causes the error would be easy to fix: glmmTMB::vcov() returns a list of covariance matrices (for the conditional, zero-inflation, and dispersion submodels), so trying to multiply by it leads to multiplying a numeric value and a list ... but that's not the biggest problem.

There are going to be several barriers to implementing this support:

  • In response to a request for GLMM support in clubSandwich, the author says:

nobody has yet worked out small-sample corrected CRVE for GLMMs (if you know of relevant work, please point me to it!). Even the notion of basic cluster-robust SEs in GLMMs is a bit fuzzy---it seems like one can certainly compute sandwich estimators for GLMMs, but what forms of model misspecification are they robust to?

(that is, support for mixed models in clubSandwich is limited to LMMs)

  • if the computation needs to have hat values/leverages from the model, this seems as though it's going to be hard to implement for glmmTMB (there is a very experimental implementation, but it's a long way from ready for prime time)

The mixed models task view lists clubSandwich, merDeriv, mlmhelpr, glmmrBase as possibilities for robust variance-covariance matrices from mixed models; I don't know which (if any) support GLMMs and/or glmmTMB.

You might need to ask for more help on Cross Validated on this one (i.e., "how do I get robust var-cov matrices for a random-effects panel beta regression?")

转载请注明原文地址:http://anycun.com/QandA/1744936733a89729.html