ngreifer / WeightIt

WeightIt: an R package for propensity score weighting
https://ngreifer.github.io/WeightIt/
102 stars 12 forks source link

Multilevel data #51

Open lucasxteixeira opened 1 year ago

lucasxteixeira commented 1 year ago

Hello @ngreifer, First, I want to thank you for the great effort you've put into this package.

I have a question that I'm not entirely sure is suited here: does WeightIt offer any support for IPW with multilevel data? https://doi.org/10.1002/sim.5786 https://doi.org/10.1080/00273171.2021.1925521

I was wondering if it could be as straightforward as including a simple if clause with lme4::glmer instead of stats::glm. In any case, if you believe it's a viable and worthwhile addition, I'd gladly implement this. Any guidance on where to begin would be immensely helpful.

Best regards,

ngreifer commented 1 year ago

I have thought about it and attempted to implement it, but right now it is not supported. Unfortunately it is not as simple as detecting whether the model has a random effect and then supplying it to glmer() if it does. This is high on my list of features to add (probably the next big feature), so thank you for suggesting it and reminding me that there is demand for it. I've been focusing on MatchIt lately and haven't updated WeightIt in a while. I don't normally accept pull requests, but if you want to try making a version that supports multilevel PS I would consider it. For now, if you have multilevel data, you can always estimate the propensity scores with glmer() outside WeightIt and then supply the propensity scores to the ps argument of WeightIt or to get_w_from_ps().

lucasxteixeira commented 1 year ago

Awesome, understood. While I'm not a specialist in statistics and may not be familiar with every minor detail of the method, I am proficient in coding and can help with that aspect. I would just need some general directions of where to change (files, folders, ...) so that I can proper keep your current organization.