
Split sample groups
split_sample_groups.RdSequesters stratified sociodemographic group margin into individual array margins.
Arguments
- sample
an
arrayof samples imported withload_samples()- new_groups
A string vector of names for each new group.
- delimiter
A character that specifies the break between group categories.
Details
When using aggregate_samples() or standardize_samples(), the group/age margin must only feature groups of similar type, e.g., you cannot age-standardize with groups that specify both age and race. split_sample_groups() sequesters each category of group into its own margin to allow group-aggregation and age-standardization of these multiply-stratified groups. Ensure that the delimiter character is only used to split groups. E.g., for an age-sex group named 35-64_m, "_" will split the margins with names "35-64" and "m", whereas for a group named 35_64_m, split_sample_group() will fail.
Examples
dimnames(minsplit)[2] # Can't age-standardize due to age-sex stratification
#> $group
#> [1] "35-44_f" "45-54_f" "55-64_f" "35-44_m" "45-54_m" "55-64_m"
#>
new_groups = c("age", "sex")
delimiter = "_"
sample_split <- split_sample_groups(minsplit, new_groups, delimiter)
dimnames(sample_split)[2:3] # can now age-standardize
#> $age
#> [1] "35-44" "45-54" "55-64"
#>
#> $sex
#> [1] "f" "m"
#>
std_pop <- c(113154, 100640, 95799)
age_margin <- 2
sample_as <- standardize_samples(sample_split, std_pop, age_margin)