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(DemoTools) | |
library(readxl) | |
IN <-read_excel("Data/Saddaf_New_file.xlsx")|> | |
mutate(age = parse_number(Age), | |
lx = parse_number(lx)) | |
lx2qx <- function(lx){ | |
-diff(c(lx,0)) / lx | |
} |
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
ex = c(84.18, 83.55, 82.58, 81.59, 80.6, 79.61, 78.62, 77.62, | |
76.63, 75.64, 74.64, 73.64, 72.65, 71.66, 70.67, 69.68, 68.7, | |
67.71, 66.72, 65.74, 64.76, 63.78, 62.8, 61.81, 60.83, 59.85, | |
58.88, 57.89, 56.91, 55.94, 54.96, 53.98, 53, 52.03, 51.06, | |
50.08, 49.11, 48.14, 47.17, 46.2, 45.24, 44.27, 43.3, 42.34, | |
41.39, 40.44, 39.48, 38.53, 37.59, 36.65, 35.72, 34.79, 33.87, | |
32.95, 32.03, 31.12, 30.22, 29.32, 28.43, 27.54, 26.66, 25.79, | |
24.92, 24.06, 23.21, 22.37, 21.53, 20.7, 19.88, 19.06, 18.27, | |
17.47, 16.68, 15.92, 15.18, 14.44, 13.71, 12.99, 12.28, 11.59, | |
10.93, 10.29, 9.65, 9.03, 8.44, 7.88, 7.33, 6.81, 6.32, 5.85, |
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
gompmx <- function(a,b,x){ | |
a * exp(b*x) | |
} | |
a1 <- .0002 | |
a2 <- .0001 | |
b1 <- .06 | |
b2 <- .1 | |
x <- 0:110 |
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) | |
library(wpp2010) | |
library(sjmisc) | |
library(tidyverse) | |
library(janitor) | |
help(wpp2010) | |
#age-sex-specific mortality rates | |
data(mxM) | |
data(mxF) |
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) | |
# dd <- | |
# structure(list(n = structure(c(10, 10, 10, 10, 10, 20, 5, 1), format.spss = "F8.2"), | |
# contin = c(1, 2, 3, 4, 5, 1, 2, 3), esp = c(0, 0.5, 0.25, | |
# 1, 1, 0, 0.5, 0.25), eur = c(0.5, 0, 0.75, 1, 1, 0.5, 0, | |
# 0.75), ame = c(0.25, 0.75, 0, 0.75, 0.75, 0.25, 0.75, 0), | |
# afr = c(1, 1, 0.75, 0, 0.75, 1, 1, 0.75), asi = c(1, 1, 0.75, | |
# 0.75, 0, 1, 1, 0.75), cont_def = c(NA, NA, NA, NA, NA, NA, |
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://covid.ourworldindata.org/data/owid-covid-data.csv" | |
download.file("https://population.un.org/wpp/Download/Files/1_Indicators%20(Standard)/EXCEL_FILES/3_Mortality/WPP2019_MORT_F07_2_LIFE_EXPECTANCY_0_MALE.xlsx", | |
destfile = "Data/wpp2019_male_e0.xlsx") | |
download.file("https://population.un.org/wpp/Download/Files/1_Indicators%20(Standard)/EXCEL_FILES/3_Mortality/WPP2019_MORT_F07_3_LIFE_EXPECTANCY_0_FEMALE.xlsx", | |
destfile = "Data/wpp2019_female_e0.xlsx") | |
library(readr) | |
library(readxl) | |
library(tidyverse) |
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
# a little exercise for Angelo and me | |
library(VGAM) | |
library(markovchain) | |
library(tidyverse) | |
source("https://raw.githubusercontent.com/timriffe/PHDS_HLE_2021/main/Functions.R") | |
# read in original transition estimates | |
TR <- read_csv("https://raw.githubusercontent.com/timriffe/PHDS_HLE_2021/main/Data/TRv6.csv") |
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(lubridate) | |
# options for a truly monotonic case: | |
set.seed(1) | |
values <- runif(100) %>% cumsum() %>% '*'(100) %>% round() | |
all_dates <- seq(dmy("01.01.2020"),today(), by = "days") | |
my_dates <- sample(all_dates, size = 100, replace = FALSE) %>% sort() | |
plot(my_dates, main = "irregularly spaced dates") | |
sum(day(my_dates) == 1) # just 4 days are 1st of month |
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(HMDHFDplus) | |
library(ungroup) | |
getwd() | |
# B <- readRDS("Data/SWE_final.Rdata") | |
# Bt <- B %>% | |
# group_by(Year) %>% | |
# summarize(Births = sum(Births)) | |
# | |
# SWEpop <- readHMDweb("SWE","Population5") |
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
UK <- structure(list(country = c("United Kingdom", "United Kingdom", | |
"United Kingdom", "United Kingdom", "United Kingdom", "United Kingdom", | |
"United Kingdom", "United Kingdom", "United Kingdom", "United Kingdom", | |
"United Kingdom", "United Kingdom", "United Kingdom", "United Kingdom", | |
"United Kingdom", "United Kingdom", "United Kingdom", "United Kingdom", | |
"United Kingdom", "United Kingdom", "United Kingdom", "United Kingdom", | |
"United Kingdom", "United Kingdom", "United Kingdom", "United Kingdom", | |
"United Kingdom", "United Kingdom", "United Kingdom", "United Kingdom", | |
"United Kingdom", "United Kingdom", "United Kingdom", "United Kingdom", | |
"United Kingdom", "United Kingdom", "United Kingdom", "United Kingdom" |