Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug - keep population filter and nsu pop not working #878

Merged
merged 5 commits into from
Dec 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions R/add_keep_population_flag.R
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,16 @@
nsu_keep_lookup <- individual_file %>%
dplyr::filter(gender == 1 | gender == 2) %>%
dplyr::filter(!is.na(locality), !is.na(age)) %>%
# Remove people who died before the mid-point of the calender year.
# This will make our numbers line up better with the methodology used for the mid-year population estimates.
dplyr::filter(death_date > mid_year | is.na(death_date) | nsu != 0) %>%
dplyr::mutate(
# Flag service users who were dead at the mid year date.
flag_to_remove = dplyr::if_else(death_date <= mid_year & nsu == 0, 1, 0),
# If the death date is missing, keep those people.
flag_to_remove = dplyr::if_else(is.na(death_date), 0, flag_to_remove),
# If they are a non-service-user we want to keep them
flag_to_remove = dplyr::if_else(nsu == 1, 0, flag_to_remove)
) %>%
# Remove anyone who was flagged as 1 from above.
dplyr::filter(flag_to_remove == 0) %>%
# Calculate the populations of the whole SLF and of the NSU.
dplyr::group_by(locality, age_group, gender) %>%
dplyr::mutate(
Expand All @@ -94,10 +101,11 @@
scaling_factor > 1 ~ 1,
.default = scaling_factor
),
keep_nsu = rbinom(1, 1, scaling_factor)
keep_nsu = rbinom(nsu_population, 1, scaling_factor)
) %>%
dplyr::filter(keep_nsu == 1L) %>%
dplyr::ungroup()
dplyr::ungroup() %>%
dplyr::select(-flag_to_remove)

Check notice on line 108 in R/add_keep_population_flag.R

View workflow job for this annotation

GitHub Actions / Check Spelling

`Line` matches candidate pattern `(?:^|[\t ,"'`=(])-[DPWXYLlf](?=[A-Z]{2,}|[A-Z][a-z]|[a-z]{2,})` (candidate-pattern)

# step 3: match the flag back onto the slf
individual_file <- individual_file %>%
Expand Down
Loading