drizopoulos / GLMMadaptive

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

Implement more S3-standard methods #3

Closed strengejacke closed 5 years ago

strengejacke commented 5 years ago

Would it be possible to implement more methods like family() or formula()?

drizopoulos commented 5 years ago

The formula() method is already implemented in the development version on GitHub. I could easily do the family() as well.

On 1/15/2019 9:09 PM, Daniel wrote:

Would it be possible to implement more methods like |family()| or |formula()|?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/drizopoulos/GLMMadaptive/issues/3, or mute the thread https://github.com/notifications/unsubscribe-auth/AMn5z_XeXxRWf4ho6xNbSZEodf8l95L3ks5vDjV2gaJpZM4aBuI-.

-- Dimitris Rizopoulos Professor of Biostatistics Department of Biostatistics Erasmus University Medical Center

Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands Tel: +31/(0)10/7043478 Fax: +31/(0)10/7043014 Web (personal): http://www.drizopoulos.com/ Web (work): http://www.erasmusmc.nl/biostatistiek/ Blog: http://iprogn.blogspot.nl/

strengejacke commented 5 years ago

That would be nice, as it makes integration into other package routines easier if you don't need to write your own wrapper for each model class. :-)

drizopoulos commented 5 years ago

Both family() and formula() are now implemented on the current version on GitHub.

On 1/15/2019 9:22 PM, Daniel wrote:

That would be nice, as it makes integration into other package routines easier if you don't need to write your own wrapper for each model class. :-)

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/drizopoulos/GLMMadaptive/issues/3#issuecomment-454537466, or mute the thread https://github.com/notifications/unsubscribe-auth/AMn5zxfDMD9zZYxY21PRykOdTkGxB6xlks5vDjiXgaJpZM4aBuI-.

-- Dimitris Rizopoulos Professor of Biostatistics Department of Biostatistics Erasmus University Medical Center

Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands Tel: +31/(0)10/7043478 Fax: +31/(0)10/7043014 Web (personal): http://www.drizopoulos.com/ Web (work): http://www.erasmusmc.nl/biostatistiek/ Blog: http://iprogn.blogspot.nl/

strengejacke commented 5 years ago

Thanks! Just another question: How can I easily access other formulas, like random effects or zero-inflation component? I know I get these via oject$call$zi_fixed or oject$call$random ... is this reliable, or is there a more robust way to get these information?

drizopoulos commented 5 years ago

In the previous version, it was possible to get the formula for the random-effects part using formula(..., type = "random"). In the current version, you also have the options in the type argument for type = "zi_fixed" and type = "zi_random".

strengejacke commented 5 years ago

Ok thanks!

strengejacke commented 5 years ago

I'm re-opening this issue because I have questions regarding the random effects. Taking the example model from the vignette (I added a variable education for testing-purposes):

gm1 <- mixed_model(
  y ~ sex * time, 
  random = ~ 1 | id, 
  data = DF,
  family = zi.negative.binomial(), 
  zi_fixed = ~ education
)

Following functions don't seem to work as expected:

model.frame(gm1, type = "random") %>% head()
#> data frame with 0 columns and 6 rows

(expected: data from id).

formula(gm1, type = "random")
#> ~1

(expected: ~1 | id or something similar)

It looks like an issue with the random parts of the model, especially the grouping factor.

drizopoulos commented 5 years ago

The formula() method should now give you the expected behavior for the random-effects parts. With regard to the model.frame(), this interprets the formula without the conditioning variable, i.e., in this case, you only have an intercept and no covariates, and this is why you get 0 rows in the resulting model frame.

strengejacke commented 5 years ago

But how do I access the data for id?

drizopoulos commented 5 years ago

You can obtain the name of the grouping variable using object$id_name (e.g., if you wanted to find this same variable in another data.frame), and you can obtain the grouping variable itself from the original data.frame used to fit the model (omitting any missing values you had) using object$id.

strengejacke commented 5 years ago

Ok, thanks! Another follow-up: If I have nested random effects, $id_name returns the name of all grouping factors, however, $id only of the first (highest) hierarchy of the grouping factors.

drizopoulos commented 5 years ago

The package does not work with nested random effects yet. This is in my future plans to include.

strengejacke commented 5 years ago

Ah, ok thanks! Maybe you should warn the user when fitting a model with nested random effects? Because the model fits w/o any warning or errors when using nested RE-notation in the formula.

I think this issue can be closed from my side now...