This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# these come from here: https://www.who.int/data/data-collection-tools/who-mortality-database | |
icd_base_url <-"https://cdn.who.int/media/docs/default-source/world-health-data-platform/mortality-raw-data/" | |
icd_files <- c("mort_country_codes.zip","morticd10_part1.zip","morticd10_part2.zip", | |
"morticd10_part3.zip","morticd10_part4.zip","morticd10_part5.zip") | |
for (i in 1:length(icd_files)){ | |
url_i <- paste0(icd_base_url,icd_files[i]) | |
local_i <- file.path(icd_files[i]) | |
download.file(url_i, destfile = local_i, overwrite = TRUE) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
library(readxl) | |
library(zoo) | |
IN <- read_excel("/home/tim/Data/grafico rp ambiental.xlsx", | |
sheet = 2, | |
range = "B6:F71") %>% | |
mutate(Variable = na.locf(Variable)) %>% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
library(readxl) | |
dat <- read_excel("Data/Gráficos.xlsx", sheet = "table") | |
p <- | |
dat %>% | |
ggplot(aes(y = origen, | |
x = Valor, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
library(readxl) | |
IN <- read_excel("RAZONES DE PREVALENCIA.xlsx")[-c(1,2),-c(1,4,6,8)] | |
colnames(IN) <- c("Grupo","TABACO EN GENERAL_Hombres","TABACO EN GENERAL_Mujeres", "TABACO DE LIAR_Hombres","TABACO DE LIAR_Mujeres") | |
IN$Grupo[1] <- "General" | |
redux <- | |
IN %>% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(eurostat) | |
library(tidyverse) | |
library(countrycode) | |
IN <- get_eurostat("demo_r_mwk_05") | |
db_eurs <- | |
IN %>% | |
mutate(time = as.character(time)) %>% | |
separate(time, sep = "W", into = c("year","week"), convert = TRUE) %>% | |
dplyr::filter(year >= 2016, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
conditions <- structure(list(idno = c(1, 2, 3, 4, 5), cvd = c(1, 1, 0, 1, 1 | |
), depression = c(0, 1, 1, 0, 0), diabetes = c(0, 1, 0, 1, 1)), class = "data.frame", row.names = c(NA, | |
-5L)) | |
data <- conditions | |
RS_adj_mat <- function(data, the_conditions = c("cvd","depression","diabetes")){ | |
stopifnot(all(the_conditions %in% colnames(data))) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
library(readxl) | |
library(colorspace) | |
# convertir a formato tidy y crear coordinatas centricas | |
ISF_tidy <- | |
read_excel("ISF_PC.xlsx", sheet = "simplified") %>% | |
pivot_longer(`2015-2011`:`1930-1926`, names_to = "YOB", values_to = "ASFR") %>% | |
filter(!is.na(ASFR)) %>% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
# example: uses Ohio, March 1 (dunno why), | |
# and population is actually 2018, because I can't find 2020 pops yet. | |
# slightly less of a problem because I grouped to 5-year intervals. | |
X <-tibble(Sex = c(rep("f",21),rep("m",21)), | |
Age = c(seq(0,100,by=5),seq(0,100,by=5)), | |
Deaths = c(0.9, 1.5, 2.5, 4, 3.4, 5.6, 14.2, 24.8, 35.1, 63.9, | |
111.9, 213.5, 363.8, 566.4, 811.4, 1076.6, 1271.3, 1012.5, 1990.5, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rm(list = ls()) | |
getwd() | |
load("Data/Smoothing.RData") | |
library(MortalitySmooth) | |
library(ungroup) | |
# ?Mort2Dsmooth | |
x <- c(0,1,seq(5,85,by=5)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(DemoTools) | |
calc_stable <- function(nLx, asfr, Age_nLx, Age_asfr){ | |
asfr_vec <- rep(0,length(Age_nLx)) | |
names(asfr_vec) <- Age_nLx | |
asfr_vec[as.character(Age_asfr)] <- asfr | |
int <- age2int(Age_nLx) | |
int[length(int)] <- int[(length(int)-1)] | |
x <- Age_nLx + int / 2 |