Builds a cohort set by using all predictor columns as grouping variables.
If x is an lx_model, predictor data are taken from x$data. If x is an
lx_data, it is used directly. The function uses id and weight; when
weight is missing, equal weights of 1 are used.
Arguments
- x
An object of class
lx_model(with parseddata) orlx_data.- predictors
Optional character vector with predictor column names to use for cohort grouping.
NULLand"predictors"are equivalent: both use all predictor columns and include"population". For explicit predictor vectors, include"population"explicitly to add the overall population cohort (including a population-only cohort set viapredictors = "population").
Examples
lx_cohort_set_from_predictors(example_lx_model)
#> Cohort Set
#> # A tibble: 11 × 6
#> column label level cohort n weighted_n
#> <chr> <chr> <chr> <list> <int> <dbl>
#> 1 population Overall population population <cohort [500 × 2]> 500 500
#> 2 d_gender Gender male <cohort [244 × 2]> 244 238.
#> 3 d_gender Gender female <cohort [256 × 2]> 256 262.
#> 4 d_age Age group 18-30 <cohort [104 × 2]> 104 147.
#> 5 d_age Age group 31-45 <cohort [159 × 2]> 159 152.
#> 6 d_age Age group 46-64 <cohort [144 × 2]> 144 123.
#> 7 d_age Age group 65+ <cohort [93 × 2]> 93 77.9
#> 8 d_hhincome Household income <$25k <cohort [110 × 2]> 110 151.
#> 9 d_hhincome Household income $25k-$50k <cohort [151 × 2]> 151 125.
#> 10 d_hhincome Household income $50k-$100k <cohort [148 × 2]> 148 147.
#> 11 d_hhincome Household income 100k+ <cohort [91 × 2]> 91 77.4
lx_cohort_set_from_predictors(example_lx_model, predictors = "predictors")
#> Cohort Set
#> # A tibble: 11 × 6
#> column label level cohort n weighted_n
#> <chr> <chr> <chr> <list> <int> <dbl>
#> 1 population Overall population population <cohort [500 × 2]> 500 500
#> 2 d_gender Gender male <cohort [244 × 2]> 244 238.
#> 3 d_gender Gender female <cohort [256 × 2]> 256 262.
#> 4 d_age Age group 18-30 <cohort [104 × 2]> 104 147.
#> 5 d_age Age group 31-45 <cohort [159 × 2]> 159 152.
#> 6 d_age Age group 46-64 <cohort [144 × 2]> 144 123.
#> 7 d_age Age group 65+ <cohort [93 × 2]> 93 77.9
#> 8 d_hhincome Household income <$25k <cohort [110 × 2]> 110 151.
#> 9 d_hhincome Household income $25k-$50k <cohort [151 × 2]> 151 125.
#> 10 d_hhincome Household income $50k-$100k <cohort [148 × 2]> 148 147.
#> 11 d_hhincome Household income 100k+ <cohort [91 × 2]> 91 77.4
lx_cohort_set_from_predictors(example_lx_model, predictors = c("d_gender", "d_age"))
#> Cohort Set
#> # A tibble: 6 × 6
#> column label level cohort n weighted_n
#> <chr> <chr> <chr> <list> <int> <dbl>
#> 1 d_gender Gender male <cohort [244 × 2]> 244 238.
#> 2 d_gender Gender female <cohort [256 × 2]> 256 262.
#> 3 d_age Age group 18-30 <cohort [104 × 2]> 104 147.
#> 4 d_age Age group 31-45 <cohort [159 × 2]> 159 152.
#> 5 d_age Age group 46-64 <cohort [144 × 2]> 144 123.
#> 6 d_age Age group 65+ <cohort [93 × 2]> 93 77.9
lx_cohort_set_from_predictors(example_lx_model, predictors = c("population", "d_gender"))
#> Cohort Set
#> # A tibble: 3 × 6
#> column label level cohort n weighted_n
#> <chr> <chr> <chr> <list> <int> <dbl>
#> 1 population Overall population population <cohort [500 × 2]> 500 500
#> 2 d_gender Gender male <cohort [244 × 2]> 244 238.
#> 3 d_gender Gender female <cohort [256 × 2]> 256 262.