cascade is similar to summarise, but calculates a summary statistics for the total of a group in addition to each group. The groupings are chosen by "unpeeling" from the end of the groupings, and also expanding out interactions to all terms (eg the interactions of all combinations of subsets of variables as well as each variable on it's own).

cascade(.data, ..., .fill = NA, .fill_level_top = FALSE, .groupings = NULL)

Arguments

.data,

tbl A tbl_svy object

...

Name-value pairs of summary functions

.fill

Value to fill in for group summaries

.fill_level_top

When filling factor variables, whether to put the value `.fill` in the first position (defaults to FALSE, placing it in the bottom).

.groupings

(Experimental) A list of lists of quosures to manually specify the groupings to use, rather than the default.

Examples

library(survey) data(api) dstrata <- apistrat %>% as_survey_design(strata = stype, weights = pw) # Calculates the means by stype and also for the whole # sample dstrata %>% group_by(stype) %>% cascade(api99_mn = survey_mean(api99), api00_mn = survey_mean(api00), api_diff = survey_mean(api00 - api99))
#> # A tibble: 4 × 7 #> stype api99_mn api99_mn_se api00_mn api00_mn_se api_diff api_diff_se #> <fct> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> #> 1 E 636. 13.3 674. 12.5 38.6 2.76 #> 2 H 617. 15.8 626. 15.5 8.46 3.41 #> 3 M 610. 16.8 637. 16.6 26.4 3.05 #> 4 NA 629. 10.1 662. 9.54 32.9 2.08
# Calculates the proportions by the interaction of stype & awards # as well as by each of those variable's groups alone, and finally # the total as well dstrata %>% group_by(interact(stype, awards)) %>% cascade(prop = survey_mean())
#> # A tibble: 12 × 4 #> stype awards prop prop_se #> <fct> <fct> <dbl> <dbl> #> 1 E No 0.193 0.0318 #> 2 E Yes 0.521 0.0318 #> 3 E NA 0.714 0 #> 4 H No 0.0829 0.00812 #> 5 H Yes 0.0390 0.00812 #> 6 H NA 0.122 0 #> 7 M No 0.0855 0.0117 #> 8 M Yes 0.0789 0.0117 #> 9 M NA 0.164 0 #> 10 NA No 0.361 0.0349 #> 11 NA Yes 0.639 0.0349 #> 12 NA NA 1 0
# Can also specify the .groupings manually, though this interface # is a little ugly, as it requires passing a list of quosures or # symbols you've created, rather than the usual syntax dstrata %>% cascade( prop = survey_mean(), .groupings = list(rlang::quos(stype, awards), rlang::quos(NULL)) )
#> # A tibble: 7 × 4 #> # Groups: stype [4] #> stype awards prop prop_se #> <fct> <fct> <dbl> <dbl> #> 1 E No 0.27 0.0446 #> 2 E Yes 0.73 0.0446 #> 3 H No 0.68 0.0666 #> 4 H Yes 0.32 0.0666 #> 5 M No 0.52 0.0714 #> 6 M Yes 0.48 0.0714 #> 7 NA NA 1 0