glmmTMB / glmmTMB

glmmTMB
281 stars 57 forks source link

[Feature Request] Support of additional covariance structures (ARH(1) and TOEP) #1095

Open pzhou-cims opened 1 week ago

pzhou-cims commented 1 week ago

Hi, thank you for the incredible work on developing glmmTMB, it's an invaluable tool for many of us working with mixed models!

I'm currently working on a project aimed at replicating the SAS PROC GLIMMIX procedure in R using glmmTMB for categorical MMRM (e.g. where the outcome variable is binomial). While glmmTMB supports several covariance structures, I have encountered a limitation: specifically, ARH(1) and TOEP (Toeplitz, homogenous) are not currently available, but are essential and commonly used for the MMRM analysis that I am trying to replicate.

I’m wondering if it might be possible to include these covariance structures in a future release of glmmTMB, or if you could provide suggestions on how we might implement them?

Thank you in advance for your help.

bbolker commented 1 week ago

Neither of these sound too hard. There are some brief pointers on how to add covariance structures to glmmTMB in the "Hacking glmmTMB" vignette (In the "Adding a covariance structure") section.

In the case of homogeneous Toeplitz, this can already be done (as suggested in the "Covariance structures" vignette):

Homogenous versions of some structures (e.g. Toeplitz, compound symmetric) can be implemented by using the map argument to set all log-SD parameters equal to each other.

That is, if you were (for example) fitting a model with a single (heterogeneous) Toeplitz-structured RE with n levels, you would specify map = list(theta = factor(c(rep(1, n), 2:n))) (I think). (That said, it would be more convenient to implement a new covariance structure and shouldn't be terribly difficult ... I guess we would call it homtoep for consistency with homdiag ?

Of course, you can't do ARH that way because that's an extension in the opposite direction (from homogeneous to heterogenous) ...

It should be relatively easy to implement these because they represent fairly minor modifications of existing structures.

The fastest way to get this done (if you feel up to it) would be to implement these yourself in a GitHub fork and then send a pull request. Otherwise we can add it to the wish list, but it's a long list ...

pzhou-cims commented 5 days ago

Thank you for the suggestions.

We will try the map() argument for the homogeneous Toeplitz as you recommended. However, for adding other structures like ARH1, as described in the "Hacking glmmTMB" vignette, this would require modification to the C++ code, which is beyond our current capabilities.

That said, we appreciate your quick response on this issue, and it would great if this could be added to the wishlist for a future standard implementation. Thank you!

bbolker commented 2 days ago

I did a preliminary implementation of heterogeneous AR1 here. It is not tested at all (yet) ... but I have at least nominally gone through all the steps in the "hacking vignette" (except adding documentation), so it might work ...

SchmidtPaul commented 2 days ago

Hi I would simply like to chime in and say that I am also using glmmTMB() a lot but since people in my area grew up with SAS I am still longing for ARH(1) as well as Factor-Analytic FA(q) - see SAS documentation

bbolker commented 2 days ago

I think FA(q) is approximately equivalent to rr(..., d=q) ?