Create tibble output with proportion (0-1 range) total estimates and coefficient of variation

srvyr_prop_step_01(design, numerator, denominator)

srvyr_prop_step_02(design, numerator, denominator, numerator_level)

srvyr_prop_step_03(design, numerator, denominator)

serosvy_proportion(design, numerator, denominator)

Arguments

design

srvyr design object

numerator

variable assigned as numerator

denominator

variable assigned as denominator

numerator_level

category inside the variable assigned as numerator

Functions

  • srvyr_prop_step_01: step 01

  • srvyr_prop_step_02: step 02

  • srvyr_prop_step_03: step 03

  • serosvy_proportion: gather all steps in one

References

Greg Freedman Ellis and Ben Schneider (2020). srvyr: 'dplyr'-Like Syntax for Summary Statistics of Survey Data. http://gdfe.co/srvyr, https://github.com/gergness/srvyr.

Examples

if (FALSE) { # inspiracion # https://github.com/gergness/srvyr/issues/13 # solution: https://github.com/gergness/srvyr/issues/13#issuecomment-321407979 # 00 ---------------------------------------------------------------------- library(tidyverse) library(srvyr) library(survey) data(api) dstrata <- apistrat %>% as_survey_design(strata = stype, weights = pw) dstrata2 <- apistrat %>% mutate(pw2=1) %>% as_survey_design(strata = stype, weights = pw2) dstrata %>% summarise(pct = survey_mean(awards=="Yes",proportion = TRUE)) dstrata2 %>% summarise(pct = survey_mean(awards=="Yes",proportion = TRUE)) # 01 ---------------------------------------------------------------------- srvyr_prop_step_01(design = dstrata, numerator = awards, denominator = stype) dstrata %>% srvyr_prop_step_01(numerator = awards, denominator = stype) # 01 + 02 ----------------------------------------------------------------- srvyr_prop_step_01(design = dstrata, numerator = awards, denominator = stype) %>% mutate(resultado=pmap(.l = select(.,design=design, numerator = numerator, denominator = denominator, numerator_level=numerator_level), .f = srvyr_prop_step_02)) %>% unnest(resultado) # 01 + 02 + 03 ------------------------------------------------------------ srvyr_prop_step_01(design = dstrata, numerator = awards, denominator = stype) %>% mutate(resultado=pmap(.l = select(.,design=design, numerator = numerator, denominator = denominator, numerator_level=numerator_level), .f = srvyr_prop_step_02)) %>% unnest(resultado) %>% mutate(crudo=pmap(.l = select(.,design=design, numerator=numerator, denominator=denominator), .f = srvyr_prop_step_03)) %>% unnest(crudo) %>% select(-design:-numerator) %>% filter(numerator_level==awards & denominator_level==stype) # one function ------------------------------------------------------------ serosvy_proportion(design = dstrata, numerator = awards, denominator = stype) }