Skip to content

Instantly share code, notes, and snippets.

@timriffe
Created October 30, 2023 15:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timriffe/da1c78f0d0ff01bf77982d43f0942acb to your computer and use it in GitHub Desktop.
Save timriffe/da1c78f0d0ff01bf77982d43f0942acb to your computer and use it in GitHub Desktop.
quick diagnostic of INE COD data
# https://www.ine.es/jaxiT3/Tabla.htm?t=7947
library(tidyverse)
ine <- read_tsv("Data/INE7947.csv",locale = locale(grouping_mark = "."))
ine |>
rename(cause = `Cause of death`) |>
mutate(cause = if_else(cause=="001-102 I-XXII.All causes","All",cause)) |>
filter(!grepl("-",cause),
Age != "All ages") |>
mutate(
Age = if_else(Age == "Under 1 year old" ,"0",Age),
Age = parse_number(Age)) |>
group_by(Periodo, Sex, Age) |>
mutate(N = Total[cause == "All"],
margin = sum(Total[cause!="All"]),
UNK = N - margin,
garbage = sum(Total[cause%in% c("087 Senility",
"057 Heart failure")]),
bad = UNK + garbage,
pgarbage = garbage / N,
pUNK = UNK / N,
pbad = bad / N) |>
ungroup() |>
filter(cause == "All",
Periodo < 2020) |>
ggplot(aes(x=Periodo, y = pgarbage, color = Sex)) +
geom_line() +
facet_wrap(~Age) +
theme_minimal()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment