tilltnet / egor

R Package for importing and analysing ego-centered-network data.
http://egor.tillt.net
GNU Affero General Public License v3.0
23 stars 4 forks source link

Are there resources how to use the package for multilevel modeling available? #56

Closed PCK1992 closed 3 years ago

PCK1992 commented 3 years ago

The package has a lot of great features but I can't quite wrap my head around how to do MLM using the data structure and I couldn't find a reference in the documentation.

library(egor)
library(lme4)

data("alters32")
data("egos32")
data("aaties32") 

e1 <- egor(alters = alters32,
           egos = egos32,
           aaties = aaties32,
           ID.vars = list(
             ego = ".EGOID",
             alter = ".ALTID",
             source = ".SRCID",
             target = ".TGTID"))
e1

lmer(income ~  (1|.egoID), data = e1$ego)

This doesn't work and I tried different variations of this formula but perhaps a short example of how to get this to work (or how to work with this package for MLM in general) would be highly appreciated!

raffaelevacca commented 3 years ago

Hi @PCK1992, below is a reference on multilevel models for ego-networks, and you can contact me via email for the code used in the article's examples (which we've been using for some recent workshops). We're trying to incorporate all this in a vignette as soon as possible.

Vacca, R. (2018). Multilevel models for personal networks: Methods and applications. Statistica Applicata - Italian Journal of Applied Statistics, 1, 59–97. https://doi.org/10.26398/IJAS.0030-003

tilltnet commented 3 years ago

This should work for your example.

alters_egos <- as_alters_df(e1, include.ego.vars = TRUE)
fitintensity <- lmer(income ~ (1 | .egoID), data = alters_egos) 

Currently egor does not provide a method for lme4::lmer(), but I can look into adding a method for that.

PCK1992 commented 3 years ago

Thank you, this is super helpful! I think in my use case it's really the only functionality that I wish was there. Thank you for your quick responses!

tilltnet commented 3 years ago

Thank you very much for the feedback @PCK1992 !

My thoughts on adding an lmer.egor() and glmer.egor() methods:

PCK1992 commented 3 years ago

That's true, especially if you want to interface it with any package outside of lme4. I think a vignette should be enough for the most common use cases and this could be then easily extended to other packages (e.g. brms, etc.).