gergness / srvyr

R package to add 'dplyr'-like Syntax for Summary Statistics of Survey Data
209 stars 27 forks source link

any way to implement svy* functions for survey wrapper packages? #22

Closed ajdamico closed 6 years ago

ajdamico commented 8 years ago

hi, question, i'm curious if there's any way that survey functions not written by dr. lumley (two examples below) could ever be incorporated into srvyr? like, could a user call of survey_gini(...) look for the svygini function? thanks!

# from ?lavaan.survey:::lavaan.survey
library(lavaan.survey)
data(ess.dk)
dk.model <- "
  socialTrust ~ 1 + systemTrust + fearCrime
  systemTrust ~ 1 + socialTrust + efficacy
  socialTrust ~~ systemTrust
"
lavaan.fit <- lavaan(dk.model, data=ess.dk, auto.var=TRUE, estimator="MLM")
summary(lavaan.fit)
survey.design <- svydesign(ids=~intnum, prob=~1, data=ess.dk)

survey.fit <- lavaan.survey(lavaan.fit=lavaan.fit, survey.design=survey.design)
summary(survey.fit)

# from ?convey:::svygini
library(convey)
library(vardpoor)
data(eusilc) ; names( eusilc ) <- tolower( names( eusilc ) )
# linearized design
des_eusilc <- svydesign( ids = ~rb030 , strata = ~db040 ,  weights = ~rb050 , data = eusilc )
des_eusilc <- convey_prep(des_eusilc)
svygini( ~eqincome , design = des_eusilc )
gergness commented 8 years ago

I will definitely consider. Before implementing databases, my hope was that you would be able to just use those functions on srvyr objects with their current syntax. However, databases won't work this way, so it might be worth it.

The stuff from convey would probably come first. I still struggle with how to treat regressions, one of my favorite part of dplyr is that it outputs to a data.frame which made this important to me while creating srvyr. I think broom will be a good guide for regressions, but I don't have a ton of experience with it though.

gergness commented 8 years ago

And would definitely consider a PR :), but the code base is a bit of a mess right now, I hope to do some cleaning so it is either to get through.

gergness commented 6 years ago

Hey @ajdamico, finally got around to allowing extensions (in the rlang branch). I wrote the documentation in vignette form to gather my thoughts, but you're probably the main audience of it, so let me know if you have any questions or suggestions.

ajdamico commented 6 years ago

hi, do you lay out the recommended usage somewhere, or how would i run the two examples above? thanks

gergness commented 6 years ago

Oops, sorry, thought I put a link last time. Hopefully this helps, but let me know anything doesn't make sense! https://github.com/gergness/srvyr/blob/master/vignettes/extending-srvyr.Rmd

ajdamico commented 6 years ago

thanks, this is great. probably more practical to convince package authors to add these functions rather than end users.. https://github.com/DjalmaPessoa/convey/issues/267 cc @daob