A function for empirical method, input is a age distribution, output is a large number of ages at mortality.
library(fitdistrplus)
## Loading required package: survival
## Loading required package: splines
age.estimate<-function(ages){
temp<-c()
for(i in 1:(nrow(ages)-1)){
x=round(max(0,ages$dist[i]-ages$dist[i+1])*999999)
temp=c(temp,rep(ages$age[i],x))
}
output<-fitdist(temp,'weibull')$estimate
}
Read demographical data: developed countries, 2000. Source: UN
raw.dev<-read.csv('/Users/feimeng/Dropbox/Papers_FeiMeng/NetStructSim/age_data/developed.csv')
raw.dev[,2]<-as.vector(raw.dev[,2])
for (i in 1:nrow(raw.dev)){raw.dev[i,2]<-gsub(" ","",raw.dev[i,2], fixed=TRUE)}
raw.dev[,2]<-as.integer(raw.dev[,2])
ages<-1:100
lo.developed<-loess(raw.dev$no~raw.dev$age)
sizes<-predict(lo.developed,newdata=ages)
developed<-data.frame(ages = ages,dist=sizes)
developed<-developed[complete.cases(developed),]
developed$dist<-developed$dist/sum(developed$dist)
weibull.developed<-age.estimate(developed)
## Warning in dweibull(c(36L, 36L, 36L, 36L, 36L, 36L, 37L, 37L, 37L, 37L, :
## NaNs produced
plot(raw.dev[,1],raw.dev[,2]/sum(raw.dev[,2]), main="Age distribution 2000, developed countries",xlab='Age',ylab='Freq',type='l')
Distribution of life span
weibull.developed
## shape scale
## 5.344469 78.177617
hist(rweibull(1000,weibull.developed[1],weibull.developed[2]),main='Estimated life span, developed countries',xlab='Age',ylab="Freq")
Read demographical data: less developed countries, 2000. Source: UN
raw.undev<-read.csv('/Users/feimeng/Dropbox/Papers_FeiMeng/NetStructSim/age_data/undeveloped.csv')
raw.undev[,2]<-as.vector(raw.undev[,2])
for (i in 1:nrow(raw.undev)){raw.undev[i,2]<-gsub(" ","",raw.undev[i,2], fixed=TRUE)}
raw.undev[,2]<-as.integer(raw.undev[,2])
ages<-1:100
lo.undeveloped<-loess(raw.undev$no~raw.undev$age)
unsizes<-predict(lo.undeveloped,newdata=ages)
undeveloped<-data.frame(ages = ages,dist=unsizes)
undeveloped<-undeveloped[complete.cases(undeveloped),]
undeveloped$dist<-undeveloped$dist/sum(undeveloped$dist)
weibull.undeveloped<-age.estimate(undeveloped)
## Warning in dweibull(c(4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
## : NaNs produced
## Warning in dweibull(c(4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
## : NaNs produced
plot(raw.undev[,1],raw.undev[,2]/sum(raw.undev[,2]), main="Age distribution 2000, less developed countries",xlab='Age',ylab='Freq',type='l')
Distribution of life span
weibull.undeveloped
## shape scale
## 1.810879 45.134255
hist(rweibull(1000,weibull.undeveloped[1],weibull.undeveloped[2]),main='Estimated life span, less developed countries',xlab='Age',ylab="Freq")