Create a g6tr.cohorts cohort set from a model shelf by combining the
segment assignments stored in the shelf with respondent ids and weights.
Each segment becomes an individual cohort so that downstream cohort helpers
can be reused for segment–level summaries.
Arguments
- shelf
A model shelf as returned by
rack_extract_shelf(). The shelf must contain asegmentsvector with segment assignments and adatadata frame withidandweightcolumns.- population
Logical. If
TRUE, the cohort set will include overall population cohort.
Value
A tibble produced by g6tr.cohorts::create_cohort_set() where every
row corresponds to a single segment‑based cohort. The segment column is a
factor that preserves the original segment ordering.
Details
Internally the function is a thin wrapper around
g6tr.cohorts::create_cohort_set(). It performs three simple steps:
Bind the segment assignments from the shelf together with the respondent ids and weights.
Pass the resulting data frame to
g6tr.cohorts::create_cohort_set()specifyingsegmentas the grouping column.Tidy up the output by dropping helper columns generated by
create_cohort_set()and restoring the original segment level order.
Examples
# Extract the first shelf from an example rack and turn segments into cohorts
shelf <- rack_extract_shelf(example_seg_rack_extended)
segment_cohorts <- shelf_make_cohort_set(shelf)
segment_cohorts
#> Cohort Set
#> # A tibble: 4 × 5
#> label level cohort n weighted_n
#> <chr> <fct> <list> <int> <dbl>
#> 1 Overall population population <cohort [100 × 2]> 100 103.
#> 2 nmf_3 1 <cohort [22 × 2]> 22 23.7
#> 3 nmf_3 2 <cohort [50 × 2]> 50 49.6
#> 4 nmf_3 3 <cohort [28 × 2]> 28 29.2