source("more/arbuthnot.R")
arbuthnot$girls
## [1] 4683 4457 4102 4590 4839 4820 4928 4605 4457 4952 4784 5332 5200 4910
## [15] 4617 3997 3919 3395 3536 3181 2746 2722 2840 2908 2959 3179 3349 3382
## [29] 3289 3013 2781 3247 4107 4803 4881 5681 4858 4319 5322 5560 5829 5719
## [43] 6061 6120 5822 5738 5717 5847 6203 6033 6041 6299 6533 6744 7158 7127
## [57] 7246 7119 7214 7101 7167 7302 7392 7316 7483 6647 6713 7229 7767 7626
## [71] 7452 7061 7514 7656 7683 5738 7779 7417 7687 7623 7380 7288
Baptisms generally increase from 1629 to 1640, then decline sharply, reaching a minimum frequency around 1650 until just before 1660, when the number almost doubles in less than five years; by 1670 baptism rates generally increase until 1710, with a notable dip around 1703-1704.
plot(arbuthnot$year, arbuthnot$boys/(arbuthnot$boys + arbuthnot$girls), type = "l",
main="Proportion of Male Births Over Time",
ylab="Percent, Male Births",
xlab="Year")
On Your Own
In the previous few pages, you recreated some of the displays and preliminary analysis of Arbuthnot’s baptism data. Your assignment involves repeating these steps, but for present day birth records in the United States. Load up the present day data with the following command.
source("more/present.R")
The data are stored in a data frame called present
.
summary(present)
## year boys girls
## Min. :1940 Min. :1211684 Min. :1148715
## 1st Qu.:1956 1st Qu.:1799857 1st Qu.:1711405
## Median :1971 Median :1924868 Median :1831679
## Mean :1971 Mean :1885600 Mean :1793915
## 3rd Qu.:1986 3rd Qu.:2058524 3rd Qu.:1965538
## Max. :2002 Max. :2186274 Max. :2082052
cat("The minimum year in the dataset is",min(present$year),
"and the maximum is",max(present$year),"\n\n",
"The dataset consists of",dim(present)[1],
"observations and",dim(present)[2],"columns\n\n",
"The column names are:",colnames(present),"\n")
## The minimum year in the dataset is 1940 and the maximum is 2002
##
## The dataset consists of 63 observations and 3 columns
##
## The column names are: year boys girls
cat("The minimum year in the Arbuthnot dataset is",min(arbuthnot$year),
"and the maximum is",max(arbuthnot$year),"\n\n",
"The minimum year in the contemporary dataset is",min(present$year),
"and the maximum is",max(present$year),"\n\n",
"The Arbuthnot dataset covers",max(arbuthnot$year)-min(arbuthnot$year),
"years",
"while the contemporary dataset covers",max(present$year)-min(present$year),
"years","\n\n",
"The Arbuthnot dataset consists of",dim(arbuthnot)[1],
"observations and",dim(arbuthnot)[2],"columns\n\n",
"The contemporary dataset consists of",dim(present)[1],
"observations and",dim(present)[2],"columns,\n",
"predictably smaller due to the narrower range in years\n\n",
"The column names are:",colnames(arbuthnot),"in both datasets","\n")
## The minimum year in the Arbuthnot dataset is 1629 and the maximum is 1710
##
## The minimum year in the contemporary dataset is 1940 and the maximum is 2002
##
## The Arbuthnot dataset covers 81 years while the contemporary dataset covers 62 years
##
## The Arbuthnot dataset consists of 82 observations and 3 columns
##
## The contemporary dataset consists of 63 observations and 3 columns,
## predictably smaller due to the narrower range in years
##
## The column names are: year boys girls in both datasets
Arbuthnot’s observation is mirrored in US birthrate data.
plot(present$year, present$boys/(present$boys + present$girls), type = "l",
main="Proportion of Male Births Over Time",
ylab="Percent, Male Births",
xlab="Year")
With ggplot:
library(ggplot2)
library(ggthemes)
plot1<-ggplot(present, aes(x=year, y=present$boys/(present$boys + present$girls)))+
geom_line(size=.75)+
theme_bw()+
theme(panel.border = element_blank(),
axis.line = element_line(colour = "black"))+
ggtitle("Boy-to-Girl Ratio by Year, 1940-2002",
subtitle="Data from Centers of Disease Control")+
xlab("year")+
ylab("percent")
print(plot1)
Plotting numbers of births each year for both sexes illustrates how Arbuthnot’s observation also applies in the contemporary U.S. data. Male births exceeded female births in all years of the dataset.
ggplot(present, aes(year)) +
geom_line(aes(y = present$boys, colour = "boys")) +
geom_line(aes(y = present$girls, colour = "girls"))+
theme_bw()+
theme(panel.border = element_blank(),
axis.line = element_line(colour = "black"))+
ggtitle("Births by Year, 1940-2002",
subtitle="Data from Centers of Disease Control")+
xlab("year")+
ylab("percent")
present$totalbirths=present$girls+present$boys
maxyear.df<-present[order(-present$totalbirths),]
maxyear<-maxyear.df$year[1]
cat("The maximum number of births occurred in",maxyear)
## The maximum number of births occurred in 1961
library(ggplot2)
library(ggthemes)
plot2<-ggplot(present, aes(x=year, y=(present$girls+present$boys)))+
geom_line(size=.75)+
theme_bw()+
theme(panel.border = element_blank(),
axis.line = element_line(colour = "black"))+
ggtitle("Total Births by Year, 1940-2002",
subtitle="Data from Centers of Disease Control")+
xlab("year")+
ylab("births")
print(plot2)
These data come from a report by the Centers for Disease Control http://www.cdc.gov/nchs/data/nvsr/nvsr53/nvsr53_20.pdf.