# R code for Chapter 9
# https://minato.sip21c.org/demography-special/Chapter9.R
T9.1 <- data.frame(AG = 2:9*5,
Women = c(4533, 3777, 3101, 2636, 2161, 1793, 1484, 1222)*1000,
TotalBirths = c(9066, 747846, 1045037, 819796, 566182, 353221, 140980, 17108),
FemaleBirths = c(4410, 363738, 508286, 398733, 275380, 171800, 68570, 8321))
# TFR
print(TFR <- sum(T9.1$TotalBirths / T9.1$Women * 5))
# GRR
print(GRR <- sum(T9.1$FemaleBirths / T9.1$Women * 5))
# alternative (approximate. In this case, very close
# because the sex ratio at birth are almost same for
# all age groups of mothers)
TFR * sum(T9.1$FemaleBirths) / sum(T9.1$TotalBirths)
# Confirm the sex ratios for each age group of mothers
# If sex ratio at birth is unknown, "males are 1.05 times
# of females" is usually acceptable (expressed by multiplying 100).
T9.1$FemaleBirths/T9.1$TotalBirths
(SexRatio <- sum(T9.1$TotalBirths-T9.1$FemaleBirths)/sum(T9.1$FemaleBirths)*100)
# NRR, which requires mortality data.
FemaleASFR <- T9.1$FemaleBirths / T9.1$Women
FemaleASFRx <- c(FemaleASFR[-1], 0) + c(FemaleASFR[1], rep(0, 7))
T9.2 <- data.frame(EAG = 3:10*5,
FASFR = FemaleASFRx,
lx = c(0.755, 0.735, 0.709, 0.683, 0.657, 0.628, 0.596, 0.558)
)
T9.2$L5x <- (T9.2$lx + c(T9.2$lx[-1], NA)) / 2 * 5
T9.2$FBSP <- T9.2$FASFR * T9.2$L5x
print(NRR <- sum(T9.2$FBSP, na.rm=TRUE)) # NRR
T9.2$MidpAG <- T9.2$EAG + 2.5
# mean age of age-specific fertility distribution
print(mbar <- sum(T9.2$FASFR * T9.2$MidpAG) / sum(T9.2$FASFR))
lmbar <- T9.2$lx[T9.2$EAG==25]+
(T9.2$lx[T9.2$EAG==30]-T9.2$lx[T9.2$EAG==25])/5*
(mbar-25) # linear interpolation between l25 and l30
GRR*lmbar # very similar to NRR
mu <- sum(T9.2$MidpAG*T9.2$FBSP, na.rm=TRUE)/sum(T9.2$FBSP, na.rm=TRUE)
print(mu)
lmu <- T9.2$lx[T9.2$EAG==25]+
(T9.2$lx[T9.2$EAG==30]-T9.2$lx[T9.2$EAG==25])/5*
(mu-25) # linear interpolation between l25 and l30
GRR*lmu
TB <- c(T9.1$TotalBirths[-1], 0) + c(T9.1$TotalBirths[1], rep(0, 7))
Mbar <- sum(TB*T9.2$MidpAG)/sum(TB)
lMbar <- T9.2$lx[T9.2$EAG==25]+
(T9.2$lx[T9.2$EAG==30]-T9.2$lx[T9.2$EAG==25])/5*
(Mbar-25) # linear interpolation between l25 and l30
GRR*lMbar