Skip to content

Instantly share code, notes, and snippets.

@bschneidr
Created February 18, 2021 19:20
Show Gist options
  • Save bschneidr/a5db85900f814d7632989524050f59ac to your computer and use it in GitHub Desktop.
Save bschneidr/a5db85900f814d7632989524050f59ac to your computer and use it in GitHub Desktop.
Survey Package TSL Covariances between Subgroup Estimates
library(survey)
# Get example data
data(api)
dclus1<-svydesign(id=~dnum, weights=~pw, data=apiclus1, fpc=~fpc)
# Estimate means by subpopulation
# Use `covmat = TRUE` to also estimate covariances
mns <- svyby(~api99, ~stype,
dclus1,
svymean,
covmat=TRUE)
# View variance covariance estimates
vcov(mns)
# Estimate contrast
svycontrast(mns, c(E = 1, M = -1))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment