drizopoulos / GLMMadaptive

GLMMs with adaptive Gaussian quadrature
https://drizopoulos.github.io/GLMMadaptive/
59 stars 14 forks source link

variance-function in family() #14

Closed strengejacke closed 5 years ago

strengejacke commented 5 years ago

Would it be possible for family() to also return an element that contains the variance-function of the model? See https://stat.ethz.ch/R-manual/R-patched/library/stats/html/family.html

drizopoulos commented 5 years ago

For which families you would like to have that? For example, it should be there when you use the build-in binomial() and poisson().

strengejacke commented 5 years ago

If possible, it should be avaiable for all families provided by your packages, so especially the custom families of your package.

The background is that I'm implementing Nakagawa's methods to compute marginal and conditional r-squared as well as ICC for mixed models (Nakagawa et al. 2017). To get the observational-level variance, one method is the log-approximation, which requires to calculate the variance based on the model's variance function.

If you're interested in details of the code, you find it here: https://github.com/easystats/insight/blob/master/R/compute_variances.R especially the part which extracts the distribution-specific variance: https://github.com/easystats/insight/blob/master/R/compute_variances.R#L337

Currently, MixMod-objects are already supported, but for a limited range of families only. For your custom families, the r-suared value is not very reliable when the variance-component is missing.

drizopoulos commented 5 years ago

I could provide it for the custom families negative.binomial(), students.t() and beta.fam() but for the zero-inflated and hurdle/two-part families this is not straightforward as far as I know.

strengejacke commented 5 years ago

If I understand right, glmmTMB uses, for instance, the poisson-family for zero-inflated models and truncated_poission() for hurdle-models (so, families for hurdle-models have a truncated_*-prefix).

I'm not sure whether glmmTMB does any internal modifications, but if not, the variance-function for zero-inflated-poisson is the same as for poisson.

Furthermore, glmmTMB has a variance-function for hurdle-poisson (truncated_poisson), so you may look at this one, but for other truncated-family, glmmTMB also has no variance-functions.

Anyway, any new supported family is welcome and can be implemented in the insight package! :-)

drizopoulos commented 5 years ago

I've implemented the variance functions for some of the families but not all. In the zero-inflated and hurdle/truncated model, I think the variance function is more difficult to be specified because you also have the zero part.