Skip to content

Instantly share code, notes, and snippets.

@timriffe
Created March 3, 2023 12:34
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/6c417b78033fadbc8af6cdb012ab11d0 to your computer and use it in GitHub Desktop.
Save timriffe/6c417b78033fadbc8af6cdb012ab11d0 to your computer and use it in GitHub Desktop.
A multistate model using Gompertz mortality but that produces a non-monotonic prevalence pattern
gompmx <- function(a,b,x){
a * exp(b*x)
}
a1 <- .0002
a2 <- .0001
b1 <- .06
b2 <- .1
x <- 0:110
# convert to qx
hd <- DemoTools::lt_id_ma_q(gompmx(a1,b1,x),rep(.5,111),AgeInt = rep(1,111))
ud <- DemoTools::lt_id_ma_q(gompmx(a2,b2,x),rep(.5,111),AgeInt = rep(1,111))
# make a linear
hu <- seq(.1,.3,length=111) * (1-hd)
hh <- 1 - hd - hu
uu <- 1 - ud
uh <- rep(0,111)
lu <- rep(0,112)
lh <- rep(0,112)
lh[1] <- 1
n <- 111
for (i in 1:n) {
lu[i + 1] <- lu[i] * uu[i] + lh[i] * hu[i]
lh[i + 1] <- lh[i] * hh[i] + lu[i] * uh[i]
}
lx <- lu+lh
pix <- lh / lx
plot(pix, main = paste("LE =",round(sum(lx),2),"\nHLE =", round(sum(lh),2)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment