# Supplementary material for 20170427
# Reading excel file requires the XLConnect package in x64 Windows
# In addition, the excel file must exist in the local file system (not in Internet).
# If you copy the http://minato.sip21c.org/demography-special/Bangladesh1974.xls to
# C:/Users/minato/Desktop/Bangladesh1974.xls, you can read that file by the following code.
# x4.1 <- readWorksheetFromFile("C:/Users/minato/Desktop/Bangladesh1974.xls", 1)
# If you can open the file using Microsoft Excel or compatible software,
# you can also use the following code after selecting and copying the data area
# x4.1 <- read.delim("clipboard") # in Windows
# x4.1 <- read.table(pipe("pbpaste")) # in MacOS X
# After the class, I have converted all excel files to tab-delimited text, so that
# now you can directly use read.delim() function to read data from URLs.
x4.1 <- read.delim("http://minato.sip21c.org/demography-special/Bangladesh1974.txt")
x4.2 <- read.delim("http://minato.sip21c.org/demography-special/Bangladesh1974ASFR.txt")
x4.3 <- read.delim("http://minato.sip21c.org/demography-special/US1984MASFR.txt")
x4.4 <- read.delim("http://minato.sip21c.org/demography-special/HutteriteMASFR.txt")
x4.5 <- read.delim("http://minato.sip21c.org/demography-special/CoaleIf-US1984.txt")
x4.6 <- read.delim("http://minato.sip21c.org/demography-special/CoaleIg-US1984.txt")
x4.7 <- read.delim("http://minato.sip21c.org/demography-special/CoaleIm-US1984.txt")
# Child/Woman ratio (CWR) for 1974 Bangladesh
(x4.1$Males000s[1]+x4.1$Females000s[1])/sum(x4.1$Females000s[4:9])
# (cf.) CWR for 2010 Japan
library(fmsb)
sum(Jpopl$M2010[1:5]+Jpopl$F2010[1:5])/sum(Jpopl$F2010[16:45])
# (cf.) CWR for 2015 Japan
sum(Jpopl$M2015[1:5]+Jpopl$F2015[1:5])/sum(Jpopl$F2015[16:45])
# Crude Birth Rate (CBR) in 1974 Bangladesh
sum(x4.2$Births)/sum(x4.1$Males000s+x4.1$Females000s)
# (cf.) CBR for 2010 Japan
sum(Jfert$ASFR2010*Jpopl$F2010[16:55])/sum(Jpopl$M2010+Jpopl$F2010)*1000
# (cf.) CBR for 2015 Japan
sum(Jfert$ASFR2015*Jpopl$F2015[16:55])/sum(Jpopl$M2015+Jpopl$F2015)*1000
# General Fertility Rate (GFR) for 1974 Bangladesh
sum(x4.2$Births)/sum(x4.1$Females000s[4:9]) # for Mothers aged 15-44
sum(x4.2$Births)/sum(x4.1$Females000s[4:10]) # for Mothers aged 15-49
# (cf.) GFR for 2010 Japan
sum(Jfert$ASFR2010*Jpopl$F2010[16:55])/sum(Jpopl$F2010[16:45])*1000 # for Mothers aged 15-44
sum(Jfert$ASFR2010*Jpopl$F2010[16:55])/sum(Jpopl$F2010[16:50])*1000 # for Mothers aged 15-49
sum(Jfert$ASFR2010*Jpopl$F2010[16:55])/sum(Jpopl$F2010[16:55])*1000 # for Mothers aged 15-54
# (cf.) GFR for 2015 Japan
sum(Jfert$ASFR2015*Jpopl$F2015[16:55])/sum(Jpopl$F2015[16:45])*1000 # for Mothers aged 15-44
sum(Jfert$ASFR2015*Jpopl$F2015[16:55])/sum(Jpopl$F2015[16:50])*1000 # for Mothers aged 15-49
sum(Jfert$ASFR2015*Jpopl$F2015[16:55])/sum(Jpopl$F2015[16:55])*1000 # for Mothers aged 15-54
# Age-Specific Fertility Rate (ASFR) for 1974 Bangladesh
x4.2$Births/x4.2$Women*1000 # It's already given as x4.2$ASFRper1000
# Drawing ASFR graph for Bangladesh 1974
barplot(x4.2$ASFRper1000) # This is better than line graph
plot(ASFRper1000 ~ AgeGroup, data=x4.2, type="l") # This is also better than Figure 4.1
plot(x4.2$ASFRper1000, type="l", xlab="Age", ylab="ASFR", axes=FALSE)
axis(2, 0:4*100)
axis(1, 1:7, lab=x4.2$AgeGroup) # These 3 line codes can give a correct line graph, instead of Figure 4.1
# (cf.) Drawing ASFR graph for Japan 2010
plot(ASFR2010*1000 ~ Age, data=Jfert, type="l", ylab="ASFR")
# (cf.) Drawing ASFR graph for Japan 2015
plot(ASFR2015*1000 ~ Age, data=Jfert, type="l", ylab="ASFR")
sum(x4.2$ASFRper1000)*5/1000
sum(x4.2$Births/x4.2$Women)*5
sum(x4.3$LegitimateBirths)/sum(x4.3$MarriedWomen)*1000
sum(Jfert$ASMFR2010)
sum(x4.3$LegitimateBirths)
sum(x4.5$ExpectedBirths)
3659176/sum(x4.5$ExpectedBirths)
sum(x4.3$LegitimateBirths)/sum(x4.6$ExpectedBirths)
3659176-sum(x4.3$LegitimateBirths)
sum(x4.5$ExpectedBirths)-sum(x4.6$ExpectedBirths)
761280/8213561
x4.7$MarriedFemales/x4.7$TotalFemales
x4.7$HutteriteStandard
x4.7$MarriedFemales/x4.7$TotalFemales*x4.7$HutteriteStandard
sum(x4.7$MarriedFemales/x4.7$TotalFemales*x4.7$HutteriteStandard)/sum(x4.7$HutteriteStadard)
sum(x4.7$MarriedFemales/x4.7$TotalFemales*x4.7$HutteriteStandard)/sum(x4.7$HutteriteStandard)
sum(x4.7$TotalFemales*x4.7$HutteriteStandard)
sum(x4.7$MarriedFemales*x4.7$HutteriteStandard)/sum(x4.7$TotalFemales*x4.7$HutteriteStandard)
#
# Exercises for Chapter 4
#
# Reading data of Table 4E.1 and 4E.2
T4E.1 <- read.delim("http://minato.sip21c.org/demography-special/Seychelles1975P.txt")
T4E.2 <- read.delim("http://minato.sip21c.org/demography-special/Seychelles1975B.txt")
# Drawing pyramid
library(pyramid)
pyramids(Left=T4E.1$Males, Right=T4E.1$Females, Center=T4E.1$AgeGroup, Laxis=0:5*1000)
# Child/Woman Ratio
(T4E.1$Males[1]+T4E.1$Females[1])/sum(T4E.1$Females[4:9])
# Crude Birth Rate
ASNB <- rowSums(T4E.2[, 2:16]) # Calculate "Total" for each age group
sum(ASNB)/sum(T4E.1$Males+T4E.2$Females) # Crude Birth Rate
# General Fertility Rate
sum(ASNB)/sum(T4E.1$Females[4:9]) # GFR for women aged 15-44
sum(ASNB)/sum(T4E.1$Females[4:10]) # GFR for women aged 15-49
# Age-Specific Fertility Rates
ASFR <- ASNB/T4E.1$Females[3:11] # assuming "<15" is "10-14", "50+" is "50-54"
print(ASFR)
plot(ASFR)
# Total Fertility Rate
sum(ASFR) # for all age groups
sum(ASFR[2:8]) # for ages 15-49
# Calculation of TFR needs ASFR, which needs decomposition of births by mothers' age
# And, TFR can mean the number of predicted total births for each woman only if
# the ASFRs are stable and most females survive until age 50. In 1975 Seychelles,
# the births decomposed by mothers' age and parity impose doubtful records: e.g.,
# 15-19 aged mother cannot have parity of 8. And from the population structure,
# most females cannot survive until age 50. In this case, CBR is more reliable than TFR.
#
# Exercise 2
T4E.3 <- read.delim("http://minato.sip21c.org/demography-special/Bangladesh1974CI.txt")
# Coale's If
3689/sum(x3$Females*x3$Hutterite)
# Coale's Ig
3689/sum(x3$Married*x3$Hutterite)
# Based on "there was a negligible amount of illegitimacy", we don't calculate Ih
# Coale's Im
sum(x3$Married*x3$Hutterite)/sum(x3$Females*x3$Hutterite)
# Coale's indices do not need the decomposition of births by mother's age
# It's necessary to calculating ASFR and TFR.
# And, it's can be applicable to several populations over time/area,
# where population structure varies.
T4E.4 <- read.delim("http://minato.sip21c.org/demography-special/German18C.txt")
208/sum(T4E.4$MarriedWomen*T4E.3$Hutterite[2:7]) # Ig
208/sum(T4E.4$MarriedWomen)*1000 # GFR
# Ig and GFR are very high. It means that 18C's German fertility was actually
# high, very close to Hutterits' level, or there were subsatantial births for
# women aged less than 20 or more than 50.
# Cohort Fertility by directly entering figures
(15+103+136+84+46+13+1)/1000*5
# Cohort Fertility by file
T5.1 <- read.delim("http://minato.sip21c.org/demography-special/EnglandWales1940.txt")
# Calculate CFR for 1920-4 birth cohort
sum(diag(as.matrix(T5.1[,2:8])))*5/1000
# Calculate CFR for 1925-9 birth cohort
sum(diag(as.matrix(T5.1[,3:9])))*5/1000
# Calculate CFR for 1930-4 birth cohort
sum(diag(as.matrix(T5.1[,4:10])))*5/1000
# Calculate CFR for 1935-9 birth cohort
sum(diag(as.matrix(T5.1[,5:11])))*5/1000
# Calculate CFR for 1940-4 birth cohort
sum(diag(as.matrix(T5.1[,6:12])))*5/1000
# Since 1945-9 birth cohort, the data are censored.