We created this variable before df0$person <- 1 “person” is a “variable” with constant value=1 I use “person” to calculate mean in total sample using svyby instead of svymean()
# svyby(~outcome, ~person, survey_design, svymean)
svyby(~outcome, ~person, survey_design, svymean)
## person outcome se
## 1 1 19.8146 0.2964862
svyby(~outcome, ~exposure, survey_design, svymean)
## exposure outcome se
## Low Low 19.78772 0.6054778
## Mid Mid 19.78517 0.3667705
## High High 19.89291 0.6933440
svyby(~outcome, ~exposure, survey_design, svymean, vartype=c("se","ci"),
deff=TRUE)
## exposure outcome se ci_l ci_u DEff.outcome
## Low Low 19.78772 0.6054778 18.60101 20.97444 4.084561
## Mid Mid 19.78517 0.3667705 19.06632 20.50403 3.238398
## High High 19.89291 0.6933440 18.53398 21.25184 3.811599
svyby(~outcome+m4p3, ~person, survey_design, svymean, vartype=c("se","ci"),
deff=TRUE)
## person outcome m4p3 se.outcome se.m4p3 ci_l.outcome ci_l.m4p3 ci_u.outcome
## 1 1 19.8146 NA Inf NaN -Inf NA Inf
## ci_u.m4p3 DEff.outcome DEff.m4p3
## 1 NA Inf NaN
survey_design <- subset(survey_design,
!is.na(m4p3))
svyby(~outcome+m4p3, ~person, survey_design, svymean, vartype=c("se","ci"),
deff=TRUE)
## person outcome m4p3 se.outcome se.m4p3 ci_l.outcome ci_l.m4p3
## 1 1 19.83054 82.72041 0.2970905 5.388483 19.24825 72.15918
## ci_u.outcome ci_u.m4p3 DEff.outcome DEff.m4p3
## 1 20.41283 93.28164 3.753644 0.9830649
svyby(~outcome+m4p3, ~exposure+Age, survey_design, svymean, vartype=c("se","ci"),
deff=TRUE)
## exposure Age outcome m4p3 se.outcome se.m4p3 ci_l.outcome
## Low.17-24 Low 17-24 21.60786 86.27520 1.9839076 5.566215 17.71948
## Mid.17-24 Mid 17-24 19.11087 82.02461 0.6840735 1.434332 17.77011
## High.17-24 High 17-24 20.94545 81.42157 1.4188238 1.286227 18.16461
## Low.25-44 Low 25-44 21.84417 98.56459 1.4273233 2.615225 19.04667
## Mid.25-44 Mid 25-44 20.80340 84.64787 0.5526297 7.986028 19.72026
## High.25-44 High 25-44 19.38793 87.47051 0.9628617 2.633382 17.50076
## Low.45-64 Low 45-64 24.83429 99.06341 3.3245625 2.579077 18.31827
## Mid.45-64 Mid 45-64 19.26649 99.47203 0.8574700 1.918700 17.58588
## High.45-64 High 45-64 15.75892 89.81648 1.4281759 2.800615 12.95975
## Low.65+ Low 65+ 19.06233 58.26738 0.5973700 29.388717 17.89151
## Mid.65+ Mid 65+ 18.18289 94.86977 0.6623262 1.244440 16.88475
## High.65+ High 65+ 21.65193 97.28270 1.4038781 2.580228 18.90038
## ci_l.m4p3 ci_u.outcome ci_u.m4p3 DEff.outcome DEff.m4p3
## Low.17-24 75.3656194 25.49625 97.18478 1.189552 1.91358502
## Mid.17-24 79.2133702 20.45163 84.83585 2.054094 2.27250427
## High.17-24 78.9006088 23.72630 83.94253 3.142143 1.99727737
## Low.25-44 93.4388446 24.64168 103.69034 2.601413 2.76890737
## Mid.25-44 68.9955381 21.88653 100.30019 3.066284 0.59066486
## High.25-44 82.3091729 21.27511 92.63184 4.039315 0.09325816
## Low.45-64 94.0085146 31.35031 104.11831 5.581114 3.06628755
## Mid.45-64 95.7114454 20.94710 103.23261 2.820480 3.78884125
## High.45-64 84.3273732 18.55810 95.30558 1.720665 2.16689926
## Low.65+ 0.6665534 20.23316 115.86821 3.298001 1.64098556
## Mid.65+ 92.4307102 19.48102 97.30883 2.708724 3.56503931
## High.65+ 92.2255449 24.40348 102.33985 3.040342 3.48554822