Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@ajdamico
Created February 28, 2019 17:11
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ajdamico/9b3232a1d986b3460baaa90f5fed3402 to your computer and use it in GitHub Desktop.
Save ajdamico/9b3232a1d986b3460baaa90f5fed3402 to your computer and use it in GitHub Desktop.
incorrect standard errors when not including the full design information
library(survey)
data(api)
x <- apistrat
x <- subset( x , comp.imp == 'Yes' )
dstrat_before<-svydesign(id=~1,strata=~stype, weights=~pw, data=x, fpc=~fpc)
dstrat_after<-svydesign(id=~1,strata=~stype, weights=~pw, data=apistrat, fpc=~fpc)
dstrat_after <- subset( dstrat_after , comp.imp == 'Yes' )
SE( svymean( ~ api00 , dstrat_after ) )
SE( svymean( ~ api00 , dstrat_before ) )
@nstjhp
Copy link

nstjhp commented Feb 20, 2023

possibly a dumb question but which one is incorrect @ajdamico ?

@ajdamico
Copy link
Author

@nstjhp dstrat_before is incorrect. subsetting a complex sample must happen after svydesign

@nstjhp
Copy link

nstjhp commented Feb 21, 2023

Thanks for swift reply @ajdamico !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment