library(tidyverse)
library(openintro)
Exercise 1
What command would you use to extract just the counts of girls
baptized?
## [1] 4683 4457 4102 4590 4839 4820 4928 4605 4457 4952 4784 5332 5200 4910 4617
## [16] 3997 3919 3395 3536 3181 2746 2722 2840 2908 2959 3179 3349 3382 3289 3013
## [31] 2781 3247 4107 4803 4881 5681 4858 4319 5322 5560 5829 5719 6061 6120 5822
## [46] 5738 5717 5847 6203 6033 6041 6299 6533 6744 7158 7127 7246 7119 7214 7101
## [61] 7167 7302 7392 7316 7483 6647 6713 7229 7767 7626 7452 7061 7514 7656 7683
## [76] 5738 7779 7417 7687 7623 7380 7288
Exercise 2
Is there an apparent trend in the number of girls baptized over the
years? How would you describe it?
The plot shows that there is an increasing trend in the number of
girls baptized over the years from 4683 baptized girls in the year 1629
to 7288 baptized girls in the year 1710, however in the year 1640, there
was a sudden drop in the number of baptized girls, with the number
rising again between the years 1660 and 1664.
ggplot(data = arbuthnot, aes(x = year, y = girls)) +
geom_line()

Exercise 3
Now, generate a plot of the proportion of boys born over time. What
do you see?
This plot shows a fluctuating proportion of boys born over time, with
the highest ratio of boys born in 1663, and the lowest ratio of boys
born in 1703. There is no noticeable upward or downward trend of boys
being born.
arbuthnot <- arbuthnot %>%
mutate(total = boys + girls)
arbuthnot <- arbuthnot %>%
mutate(boy_ratio = boys / total)
ggplot(data = arbuthnot, aes(x = year, y = boy_ratio)) +
geom_line()

Exercise 4
What years are included in this data set? 1940 to 2002
What are the dimensions of the data frame? 63 x 3
What are the variable (column) names? year, boys, girls
## # A tibble: 63 × 3
## year boys girls
## <dbl> <dbl> <dbl>
## 1 1940 1211684 1148715
## 2 1941 1289734 1223693
## 3 1942 1444365 1364631
## 4 1943 1508959 1427901
## 5 1944 1435301 1359499
## 6 1945 1404587 1330869
## 7 1946 1691220 1597452
## 8 1947 1899876 1800064
## 9 1948 1813852 1721216
## 10 1949 1826352 1733177
## # ℹ 53 more rows
Exercise 5
How do these counts compare to Arbuthnot’s? Are they of a similar
magnitude?
The present count for girls and boys show similar upward trends
compared with Arbuthnot’s at first, and they both show the similar
sudden drop in birth rates for a few years followed by a rise again,
however, in the present day counts, the birth rates for girls and boys
do not exceed the births from before the sudden drop, whereas in
Arbuthnot’s, the birth rates for girls and boys continue their upward
trend as if the drop had little effect on their increase of births over
the years.
The present birth rates are also on a much larger magnitude compared
to Arbuthnot’s counts in the 1600s, with present birth rates reaching up
to 4.2 million, whereas Arbuthnot’s birth rates only reached to the 16
thousands.
ggplot(data = present, aes(x = year, y = girls)) +
geom_line()

ggplot(data = present, aes(x = year, y = boys)) +
geom_line()

Exercise 6
Make a plot that displays the proportion of boys born over time. What
do you see? Does Arbuthnot’s observation about boys being born in
greater proportion than girls hold up in the U.S.?
There is a downward trend in the proportion of boys being born in the
United States, however, the ratio of boys born over time stays above
0.51, which suggests that Arbuthnot’s observation about boys being born
in greater proportion than girls does hold up in the present day U.S.,
despite its downward trend.
present <- present %>%
mutate(total = boys + girls)
present <- present %>%
mutate(boy_ratio = boys / total)
ggplot(data = present, aes(x = year, y = boy_ratio)) +
geom_line()

Exercise 7
We saw the most total number of births in the U.S. in the year 1961
with a total of 4268326 births.
present <- present %>%
mutate(total = boys + girls)
present %>%
arrange(desc(total))
## # A tibble: 63 × 5
## year boys girls total boy_ratio
## <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 1961 2186274 2082052 4268326 0.512
## 2 1960 2179708 2078142 4257850 0.512
## 3 1957 2179960 2074824 4254784 0.512
## 4 1959 2173638 2071158 4244796 0.512
## 5 1958 2152546 2051266 4203812 0.512
## 6 1962 2132466 2034896 4167362 0.512
## 7 1956 2133588 2029502 4163090 0.513
## 8 1990 2129495 2028717 4158212 0.512
## 9 1991 2101518 2009389 4110907 0.511
## 10 1963 2101632 1996388 4098020 0.513
## # ℹ 53 more rows
LS0tCnRpdGxlOiAiTGFiIDE6IEludHJvIHRvIFIiCmF1dGhvcjogIkNhcm9saW5hIEFjZXJvIgpkYXRlOiAiYHIgU3lzLkRhdGUoKWAiCm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