Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(HMDHFDplus) # on CRAN
- library(DecompHoriuchi) # on github
- # define your HMD username and password as objects, us, and pw
- mlt <- readHMDweb("USA","mltper_1x1",username=us,password = pw)
- flt <- readHMDweb("USA","fltper_1x1",username=us,password = pw)
- mxm1 <- mlt$mx[mlt$Year == 1950]
- mxm2 <- mlt$mx[mlt$Year == 2000]
- mxf1 <- flt$mx[flt$Year == 1950]
- mxf2 <- flt$mx[flt$Year == 2000]
- # translate into initial conditions versus change.
- minit <- mxm1
- finit <- mxf1
- mchg <- mxm2 - mxm1
- fchg <- mxf2 - mxf1
- # cheap e0 function of initial conditions and change
- mye0 <- function(mxinit, mxchg){
- mx <- mxinit + mxchg
- sum(exp(-cumsum(mx)))
- }
- # need the same thing but that takes a single vector of rates.
- mye0vec <- function(mxvec){
- # clearly the vecs need to be of the same length
- mxinit <- mxvec[1:(length(mxvec)/2)]
- mxchg <- mxvec[(length(mxvec)/2+1):length(mxvec)]
- mye0(mxinit, mxchg)
- }
- # now decompose:
- males <- c(minit,mchg)
- females <- c(finit,fchg)
- results <- DecompContinuousOrig(mye0vec, females, males, 20)
- initial <- results[1:111]
- change <- results[112:222]
- # take a quick look.
- barplot(rbind(initial,change),space=0,border=NA)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement