ukhsa-collaboration / PHEindicatormethods

GNU General Public License v3.0
26 stars 15 forks source link

phe_dsr returns error for groups with 0 population #32

Open andrewbillett opened 4 years ago

andrewbillett commented 4 years ago

I am generating hospital admission dsrs for each IMD quintile within each upper tier English LA. Some UTLAs e.g. Barking and Dagenham, have no LSOAs in quintiles 4 and 5. When I run the phe_dsr function on a grouped dataframe it complains that it can't handle groups with zero population/denominator. Statistically, this is correct, but could an error capture be built in to the function so that it ignores groups where the population/denominator is zero and simply returns a NA rate for these groups?

PHEgeorginaanderson commented 2 years ago

Unsure of exact requirements. A reprex would be helpful to demonstrate the issue.

johnmackintosh commented 1 year ago

I ran into this error message yesterday, but got round it using tidyr::replace_na() - I didn't see how else to keep the group lengths consistent without converting the NAs to 0 in the relevant columns. Not sure how this could be handled within the functions (this is the first time I've needed to use this package) but perhaps there could be an addition to the error message to suggest that NAs are replaced prior to use?