Skip to contents

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.

Usage

shelf_make_cohort_set(shelf, population = TRUE)

Arguments

shelf

A model shelf as returned by rack_extract_shelf(). The shelf must contain a segments vector with segment assignments and a data data frame with id and weight columns.

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:

  1. Bind the segment assignments from the shelf together with the respondent ids and weights.

  2. Pass the resulting data frame to g6tr.cohorts::create_cohort_set() specifying segment as the grouping column.

  3. Tidy up the output by dropping helper columns generated by create_cohort_set() and restoring the original segment level order.

Lifecycle

[Experimental]

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