# NOT RUN {
library(dplyr)
## A simple example
df <- data.frame(startage = c(0L, 1L, 5L, 10L, 15L, 20L, 25L, 30L, 35L, 40L, 45L, 50L, 55L,
60L, 65L, 70L, 75L, 80L, 85L, 90L),
pops = c(7060L, 35059L, 46974L, 48489L, 43219L, 38561L, 46009L, 57208L,
61435L, 55601L, 50209L, 56416L, 46411L, 39820L, 37978L,
37039L, 33288L, 23306L, 11936L, 11936L),
deaths = c(17L, 9L, 4L, 8L, 20L, 15L, 24L, 33L, 50L, 71L, 100L, 163L,
263L, 304L, 536L, 872L, 1390L, 1605L, 1936L, 1937L))
phe_life_expectancy(df, deaths, pops, startage)
## OR
phe_life_expectancy(df, deaths, pops, startage, le_age = c(5, 25), type = "standard")
## Unordered age bands example
df <- data.frame(startage = c("0", "1-4", "5-9", "10 - 14", "15 - 19", "20 - 24", "25 - 29",
"30 - 34", "35 - 39", "40 - 44", "45 - 49", "50 - 54",
"55 - 59", "60 - 64", "65 - 69", "75 - 79", "80 - 84",
"85 - 89", "90 +", "70 - 74"),
pops = c(7060L, 35059L, 46974L, 48489L, 43219L, 38561L, 46009L, 57208L,
61435L, 55601L, 50209L, 56416L, 46411L, 39820L, 37039L,
23306L, 11936L, 11936L, 37978L, 33288L),
deaths = c(17L, 9L, 4L, 8L, 20L, 15L, 24L, 33L, 50L, 71L, 100L, 163L,
263L, 304L, 872L, 1605L, 1936L, 1937L, 536L, 1390L))
phe_life_expectancy(df, deaths, pops, startage,
age_contents = c("0", "1-4", "5-9",
"10 - 14", "15 - 19",
"20 - 24", "25 - 29",
"30 - 34", "35 - 39",
"40 - 44", "45 - 49",
"50 - 54", "55 - 59",
"60 - 64", "65 - 69",
"70 - 74", "75 - 79",
"80 - 84", "85 - 89",
"90 +"))
df <- data.frame(area = c(rep("Area 1", 20), rep("Area 2", 20)),
startage = rep(c(0L, 1L, 5L, 10L, 15L, 20L, 25L, 30L, 35L, 40L, 45L, 50L, 55L,
60L, 65L, 70L, 75L, 80L, 85L, 90L), 2),
pops = rep(c(7060L, 35059L, 46974L, 48489L, 43219L, 38561L, 46009L, 57208L,
61435L, 55601L, 50209L, 56416L, 46411L, 39820L, 37978L,
37039L, 33288L, 23306L, 11936L, 11936L), 2),
deaths = rep(c(17L, 9L, 4L, 8L, 20L, 15L, 24L, 33L, 50L, 71L, 100L, 163L,
263L, 304L, 536L, 872L, 1390L, 1605L, 1936L, 1937L), 2))
df %>%
group_by(area) %>%
phe_life_expectancy(deaths, pops, startage)
# }
Run the code above in your browser using DataLab