mortality_rate_fun: Mortality rate

Description Usage Arguments Examples

View source: R/Functions.R

Description

This function that takes in weekly or monthly aggreagated causes of deaths and population estimates then it computes mortality rates per 100 000 by country level and provincial level. This function takes output from the aggreagate_fun().

Usage

1
2
3
mortality_rate_fun(df,
                   population_est,
                   scale.aggregate = c("Province", "Countrywide"))

Arguments

df

Aggregated dataframe

population_est

Mid year population estimates. If by_province is TRUE, then provide provincial estimates else countrywide estimates.

by_province

Whether to aggregate by province or country level

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
## The function is currently defined as

mortality_rate_fun <- function(df,
                               population_est,
                               scale.aggregate = c("Province", "Countrywide")) {

  joint_df <- if (scale.aggregate == "Province")
  {left_join(df, population_est, by = c("DeathProv" = "Province", "Year"))}
  else {left_join(df, population_est,by = "Year")}

  joint_df %>%
    mutate(All_deaths_rate = (All_deaths/Pop_estimate)*100000,
           AllRes_deaths_rate = (AllRes_deaths/Pop_estimate)*100000,
           AllResU5_deaths_rate = (AllResU5_deaths/Pop_estimateU5)*100000,
           AllResG5_deaths_rate = (AllResG5_deaths/Pop_estimateG5)*100000,
           PI_deaths_rate = (PI_deaths/Pop_estimate)*100000,
           PIU5_deaths_rate = (PIU5_deaths/Pop_estimateU5)*100000,
           PIG5_deaths_rate = (PIG5_deaths/Pop_estimateG5)*100000,
           POther_deaths_rate = (POther_deaths/Pop_estimate)*100000,
           Flu_deaths_rate = (Flu_deaths/Pop_estimate)*100000,
           RSV_deaths_rate = (RSV_deaths/Pop_estimateU5)*100000)  %>%
    select(-c(All_deaths, AllRes_deaths, AllResU5_deaths, AllResG5_deaths, PI_deaths,
              PIU5_deaths, PIG5_deaths,
              POther_deaths, Flu_deaths, RSV_deaths, Year, Pop_estimate, Pop_estimateU5,
              Pop_estimateG5))
}

EMDominic/SThelperfunctions documentation built on Aug. 4, 2020, 12:02 a.m.