Public-Health-Scotland / phsmethods

An R package to standardise methods used in Public Health Scotland (https://public-health-scotland.github.io/phsmethods/)
https://public-health-scotland.github.io/phsmethods/
54 stars 13 forks source link

`create_age_groups` with bins of custom lengths #93

Open r6lm opened 1 year ago

r6lm commented 1 year ago

Is your feature request related to a problem? Please describe. At my team, we have to create age bands which do not have the same length. Currently, the create_age_groups does not allow this.

Describe the solution you'd like I created a simple version of create_age_groups which allows custom bin lengths by specifying the cut points with a numeric vector.

Moohan commented 5 days ago

@r6lm This is a great idea and something we'd like to see taken forward.

Do you have a suggested implementation? I like the idea of an age_breaks parameter that would take a vector of integers, and override the default behaviour of create_age_groups.

@Nic-Chr suggested providing 'common' age bands - https://github.com/Public-Health-Scotland/phsmethods/issues/54#issuecomment-2006825615 however, I think these are already easy enough to do with create_age_groups and the advantage to be had here would be to allow 'non-systematic' groupings e.g. 0-18, 18-40, 40-65, 65+ etc. Nic's implementation does allow that - https://phs-git.nhsnss.scot.nhs.uk/Nic-Chr/rtemethods/src/branch/master/R/age_band.R so I think those ideas could be brought into phsmethods::create_age_groups