Learn R Programming

RSTr (version 1.1.4)

split_sample_groups: Split sample groups

Description

Sequesters stratified sociodemographic group margin into individual array margins.

Usage

split_sample_groups(sample, new_groups, delimiter = "_")

Value

An array of samples with separate margins for stratified groups.

Arguments

sample

an array of samples imported with load_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

Run this code
dimnames(minsplit)[2] # Can't age-standardize due to age-sex stratification
new_groups = c("age", "sex")
delimiter = "_"
sample_split <- split_sample_groups(minsplit, new_groups, delimiter)
dimnames(sample_split)[2:3] # can now age-standardize
std_pop <- c(113154, 100640, 95799)
age_margin <- 2
sample_as <- standardize_samples(sample_split, std_pop, age_margin)

Run the code above in your browser using DataLab