Description Usage Arguments Details Value Examples
This function creates crosstabs for any number of grouping, filter, and outcome variables.
1 2 3 | surv_prop_table(s, outcome_vars, grouping_vars = NULL,
filter_vars = NULL, new_outcome_name = "outcome",
new_group_name = "group", wrap = F)
|
s |
A tbl_svy object created using the srvyr package. |
outcome_vars |
A character vector naming the column(s) in |
grouping_vars |
A character vector naming the column(s) in |
filter_vars |
character or character vector with names of filter varibles. These must be binary columns in s of type logical or numeric (convert beforehand if needed). Values equal to 1 (true) are retained. They filters will be applied seperately, not in succession, in order to allow one to create multiple overlapping groups. If more elaborate filtering is required, use filter( ) beforehand. |
new_outcome_name |
Character with intended name of the column to hold the names of the outcome variables. Ignored if only 1 outcome. |
new_group_name |
A character with intended name of the column to hold the names of the filter variables being treated as groups. Ignored if less than 2 filter_vars. |
wrap |
A logical indicating to return html code that will print the data to the Viewer window in Rstudio for copy and pasting into other programs. |
This function outputs a wide format table with a column for each grouping variable listing its categories and a column of values for each response category of the outcome(s). Rows will sum to 100 If outcomes are binary only one column of values is shown If there are multiple outcomes, an outcome column is added to indicate which outcome is being used for each row. If multiple filter variables, a filter column is added to indicated which filter is used on each row (this allows you to create groups that overlap)
A long formate tibble, or if wrap = T, a kableExtra table in html. The intial columns are named for the grouping variables (including new groups created from multiple outcomes and filters) and list all of a row's group memberships. The later columns are named for the outcome categories and list the percentages for each. Rows should sum to 100, unless outcome is binary in which case only one column is displayed to avoid redudancy.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | data(ca_school_tbl_svy)
# No groups
ca_school_tbl_svy %>%
surv_prop_table("poverty",
wrap = T)
ca_school_tbl_svy %>%
surv_prop_table("poverty", "size",
wrap = T)
# One grouping, binary outcome (only the "yes" column will be retained)
ca_school_tbl_svy %>%
surv_prop_table("eligible.for.award", "school.level",
wrap = T)
# Multiple groupings
ca_school_tbl_svy %>%
surv_prop_table(outcome_vars = "poverty",
grouping_vars = c("size", "school.level"),
wrap = T)
# Multiple groupings and outcomes
# Note: these outcomes are yes/no variables, so only the "yes" column will be retained
ca_school_tbl_svy %>%
surv_prop_table(outcome_vars = c("sch.wide.imp.goal", "comparative.imp.goal"),
grouping_vars = c("size", "school.level"),
new_outcome_name = "standards met",
wrap = T)
# Overlapping groupting variables
ca_school_tbl_svy %>%
mutate(sch.wide.imp.goal = sch.wide.imp.goal == "Yes",
comparative.imp.goal = comparative.imp.goal == "Yes") %>%
surv_prop_table(outcome_vars = "poverty",
filter_vars = c("sch.wide.imp.goal","comparative.imp.goal"),
new_group_name = "standards met",
wrap = T)
# Delay wrapping in order to modify the output first
ca_school_tbl_svy %>%
surv_prop_table(outcome_vars = c("sch.wide.imp.goal", "comparative.imp.goal"),
grouping_vars = "school.level",
new_outcome_name = "standards met",
wrap = F) %>%
mutate(`standards met` =
recode(`standards met`,
sch.wide.imp.goal = "schoolwide target",
comparative.imp.goal = "comparative improvement target")) %>%
rename(`school level` = school.level) %>%
wrap()
rm(ca_school_tbl_svy)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.