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
# testing Arriaga with composition. | |
# A little script I wrote for Michael Lachanski. And the world | |
# simiulate 2 groups at two time points, | |
# Gompertz mort, with parameters a and b | |
# we will use functions from a package in development coddecomp | |
# install like so: | |
# remotes::install_github("timriffe/coddecomp") | |
library(coddecomp) |
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(HMDHFDplus) | |
library(tidyverse) | |
library(janitor) | |
d <- readHMDweb("ESP","Deaths_lexis", | |
username = Sys.getenv("us"), | |
password = Sys.getenv("pw")) | |
p <- readHMDweb("ESP","Population", | |
username = Sys.getenv("us"), | |
password = Sys.getenv("pw")) |
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) | |
pop <- read_csv("Data/JPNpop.csv") | |
Exp <- | |
pop |> | |
filter(Type == "C", | |
Year > 1970, | |
Age != "TOT") |> | |
select(Sex, Year, Age, Population) |> |
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
devtools::load_all() | |
# library(HMDHFDplus) | |
# mx <- readHMDweb("USA","mltper_1x1", | |
# username = Sys.getenv("us"), | |
# password = Sys.getenv("pw")) |> | |
# filter(Year == 2000) |> | |
# pull(mx) | |
mx <- c(0.00791, 0.00056, 0.00038, 0.00029, 0.00022, 0.00021, 0.00019, |
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) | |
mx_to_lx <- function(mx){ | |
mx[is.na(mx)] <- 0 | |
lx <- exp(-cumsum(mx)) | |
lx <- c(1,lx) | |
lx[1:length(mx)] | |
} | |
lx_to_dx <- function(lx){ | |
-diff(c(lx,0)) |
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
# 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( |
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
# Testing whether mort component should be identical in decomps where | |
# only prev swaps out | |
library(tidyverse) | |
library(HMDHFDplus) | |
library(DemoDecomp) | |
mlt <- readHMDweb("USA", "mltper_1x1", username = Sys.getenv("us"), password = Sys.getenv("pw")) | |
flt <- readHMDweb("USA", "fltper_1x1", username = Sys.getenv("us"), password = Sys.getenv("pw")) | |
mx2Lx <- function(mx){ |
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
srb <- 1.05 | |
pfb <- 1/ (1 + srb) | |
fxf <- c(0.00000,0.00003,0.00038,0.00146,0.00436,0.01006,0.01963,0.03576, | |
0.06036,0.09112,0.12532,0.15873,0.18765,0.20418,0.20929,0.20586, | |
0.19741,0.18698,0.16816,0.14313,0.12684,0.11769,0.11308,0.10262, | |
0.08831,0.07622,0.06532,0.05493,0.04629,0.03623,0.02455,0.01515, | |
0.00881,0.00494,0.00305,0.00219,0.00174,0.00140,0.00124,0.00065, | |
0.00019,0.00005,0.00001,0.00000) * pfb | |
fxf <- c(rep(0,12),fxf,rep(0,55)) |
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(HMDHFDplus) | |
library(tidyverse) | |
mlt <- readHMDweb("ESP","mltper_1x1",username = Sys.getenv("us"),password = Sys.getenv("pw")) | |
# 1950 Spanish males | |
mx1 <- c(0.08382, 0.01361, 0.00764, 0.00464, 0.0032, 0.00245, 0.00222, |
NewerOlder