# Calculate unconditional probability of dying # Author: Ivo Rakovac (rakovaci at who dot int), # WHO Regional Office for Europe, # Division of Noncommunicable Diseases and Promoting Health through the Life-course, # WHO European Office for the Prevention and Control of Noncommunicable Diseases (NCD Office) # unconditional probabilty of dying between ages 30 and 69 years probabilityOfDying30_69 <- function(d,p) { m<-d/p q<-m*5/(1+m*2.5) q[8] res<-100*(1-(1-q[8])*(1-q[9])*(1-q[10])*(1-q[11])*(1-q[12])*(1-q[13])*(1-q[14])*(1-q[15])) res return(res) } # probabilty of dying between arbitrary 5 years age groups probabilityOfDying <- function(d.short,p.short) { m<-d.short/p.short q<-m*5/(1+m*2.5) prod<-1; for( i in c(1:length(q))){ prod<-prod*(1-q[i]) } res<-100*(1-prod(1-q)) res<-100*(1-prod) res return(res) } # test data d <- array(c(1,10,14,13,24,33, 45, 86, 142, 344, 727, 1368, 1994, 2959, 4291, 6605, 6635, 10070, 24678), dim=c(19,1)) d.short <- array(c(86, 142, 344, 727, 1368, 1994, 2959, 4291), dim=c(8,1)) p <- array(c(79828, 322939, 403965, 415089, 464268, 545917, 565035, 577713, 544966, 618886, 709478, 682921, 569842, 471089, 422748, 437151, 283721, 216284, 212092),dim=c(19,1)) p.short <- array(c(577713, 544966, 618886, 709478, 682921, 569842, 471089, 422748),dim=c(8,1)) d p # Example use probabilityOfDying30_69(d,p) probabilityOfDying(d.short,p.short)