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

We can see that the girls were steadily getting baptized over the years with a sharp increase just after the 1660s and then there was a major decrease right after the 1700s, but it immediately shot right back up the same year.

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

## I redefined the columns as the R markdown couldnt knit it with the object i.e object not found without defining these 
arbuthnot <- arbuthnot %>%
  mutate(total = boys + girls)
## I redefined the columns as the R markdown couldnt knit it with the object i.e object not found without defining these 
arbuthnot <- arbuthnot %>%
  mutate(boy_ratio = boys/total)

Exercise 3

This is the plot for the proportion of the boys over time. I see a lot of fluctuations in the graph as there were sharp increases and decreases to boys getting baptized notably there were a sharp increase in the years leading up to 1660s.

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

Exercise 4

We can see that there are 63 objects and 3 variables in this data frame. The column names in the present data set are year,boys,and girls. The years spanning from 1940 to 2002.

# Insert code for Exercise 4 here

data('present', package='openintro')
glimpse(present)
## Rows: 63
## Columns: 3
## $ year  <dbl> 1940, 1941, 1942, 1943, 1944, 1945, 1946, 1947, 1948, 1949, 1950~
## $ boys  <dbl> 1211684, 1289734, 1444365, 1508959, 1435301, 1404587, 1691220, 1~
## $ girls <dbl> 1148715, 1223693, 1364631, 1427901, 1359499, 1330869, 1597452, 1~

Exercise 5

I made a new column called total for the present data frame and I compared the total values between arbuthnot data and the present data we can see that the present data frame is magnitudes greater than the arbuthnot data like the data has counts of over a million compared to the thousands of arbuthnot.

# Insert code for Exercise 5 here
present <-present %>%
  mutate(total=boys+girls)

## Total for arbuthnot
arbuthnot$total
##  [1]  9901  9315  8524  9584  9997  9855 10034  9522  9160 10311 10150 10850
## [13] 10670 10370  9410  8104  7966  7163  7332  6544  5825  5612  6071  6128
## [25]  6155  6620  7004  7050  6685  6170  5990  6971  8855 10019 10292 11722
## [37]  9972  8997 10938 11633 12335 11997 12510 12563 11895 11851 11775 12399
## [49] 12626 12601 12288 12847 13355 13653 14735 14702 14730 14694 14951 14588
## [61] 14771 15211 15054 14918 15159 13632 13976 14861 15829 16052 15363 14639
## [73] 15616 15687 15448 11851 16145 15369 16066 15862 15220 14928
## Total for present
present$total
##  [1] 2360399 2513427 2808996 2936860 2794800 2735456 3288672 3699940 3535068
## [10] 3559529 3554149 3750850 3846986 3902120 4017362 4047295 4163090 4254784
## [19] 4203812 4244796 4257850 4268326 4167362 4098020 4027490 3760358 3606274
## [28] 3520959 3501564 3600206 3731386 3555970 3258411 3136965 3159958 3144198
## [37] 3167788 3326632 3333279 3494398 3612258 3629238 3680537 3638933 3669141
## [46] 3760561 3756547 3809394 3909510 4040958 4158212 4110907 4065014 4000240
## [55] 3952767 3899589 3891494 3880894 3941553 3959417 4058814 4025933 4021726

Exercise 6

Arbuthnot’s observation doesn’t seem to hold up in the United States as it seems there has been a gradual decrease in the amount of boys being baptized. Al tough the ratio for boys is just above 50 percent.

present <- present %>%
  mutate(boy_ratio=boys/total)
## Insert plot
library(ggplot2)
ggplot(data = present, aes(x=year,y=boy_ratio)) + 
  geom_line()

.

Exercise 7

The year we saw the most births in the US is 1961 with the total being 4268326.

present %>%
  arrange(desc(total))