library(tidyverse)
library(openintro)

Exercise 1

arbuthnot$girls
##  [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

In the plot below we observe a sharp decline in female baptisms from 1640 to 1660.This would require further investigation as to why there was such a large decrease in that time period.

ggplot(data = arbuthnot, aes(x = year, y = girls)) + 
  geom_point()

Exercise 3

In the plot below we are looking at the boy baptism count as a % of total baptisms. What we can see in the scatter plot below is that there was a pretty close to equal number of baptisms for males and females, but there we always more boys being baptized. The proportion never falls below 50%.

arbuthnot <- arbuthnot %>%
  mutate(total = boys + girls)

arbuthnot <- arbuthnot %>%
  mutate(boy_to_girl_ratio = boys / girls)

arbuthnot <- arbuthnot %>%
  mutate(boy_ratio = boys / total)

ggplot(data = arbuthnot, aes(x = year, y = boy_ratio)) + 
  geom_point()

Exercise 4

After taking a glimpse we can see three columns in the present dataset.

year: the year the birth took place boys: the count of boys born that year girls: the count of girls born that year

head(present)
## # A tibble: 6 x 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

The dataset appear to contain the years ranging from 1940 - 2002.

present %>%
  summarize(min = min(year), max = max(year))
## # A tibble: 1 x 2
##     min   max
##   <dbl> <dbl>
## 1  1940  2002

Exercise 5

After taking the average counts of the 2 datasets, the present table is dealing with counts 3 orders of magnitude larger than the arbuthnot table.

present %>%
  summarize(avg_boy = mean(boys), avg_girl = mean(girls))
## # A tibble: 1 x 2
##    avg_boy avg_girl
##      <dbl>    <dbl>
## 1 1885600. 1793915.
arbuthnot %>%
  summarize(avg_boy = mean(boys), avg_girl = mean(girls))
## # A tibble: 1 x 2
##   avg_boy avg_girl
##     <dbl>    <dbl>
## 1   5907.    5535.

Exercise 6

Looking at the birthrates we observe the same trend. Boys are being born in a greater proportion, however there seems to be a downward trend over the years.

present <- present %>%
  mutate(birth_total = boys + girls)

present <- present %>%
  mutate(boy_proportion = boys / birth_total)

ggplot(data = present, aes(x = year, y = boy_proportion)) + 
  geom_point()

Exercise 7

1961 is the year with the highest birth total in this data set.

print(present %>%
  arrange(desc(birth_total)))
## # A tibble: 63 x 5
##     year    boys   girls birth_total boy_proportion
##    <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
## # … with 53 more rows
LS0tCnRpdGxlOiAiTGFiIDE6IEludHJvIHRvIFIiCmF1dGhvcjogIkF1dGhvciBOYW1lIgpkYXRlOiAiYHIgU3lzLkRhdGUoKWAiCm91dHB1dDogb3BlbmludHJvOjpsYWJfcmVwb3J0Ci0tLQoKYGBge3IgbG9hZC1wYWNrYWdlcywgbWVzc2FnZT1GQUxTRX0KbGlicmFyeSh0aWR5dmVyc2UpCmxpYnJhcnkob3BlbmludHJvKQpgYGAKCiMjIyBFeGVyY2lzZSAxCgpgYGB7ciB2aWV3LWdpcmxzLWNvdW50c30KYXJidXRobm90JGdpcmxzCmBgYAoKCiMjIyBFeGVyY2lzZSAyCgpJbiB0aGUgcGxvdCBiZWxvdyB3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