library(tidyverse)
library(openintro)

What command would you use to extract just the counts of girls baptized? Try it!

length(arbuthnot$girls)
## [1] 82

There are 82 girls baptized in arbuthnot data set.

Exercise 2

Is there an apparent trend in the number of girls baptized over the years? How would you describe it? (To ensure that your lab report is comprehensive, be sure to include the code needed to make the plot as well as your written interpretation.)

arbuthnot$boys + arbuthnot$girls
##  [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
arbuthnot <- arbuthnot %>%
  mutate(total = boys + girls)

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

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

The girls being baptized from 1640s-1660s was a sharp decreased following by an increased demand of baptized girls from 1665 onward.

Exercise 3

Now, generate a plot of the proportion of boys born over time. What do you see?

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

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

The boys have consistently been bapitzed throughout the years with only a small decrease after 1700s.

Exercise 4

What years are included in this data set? What are the dimensions of the data frame? What are the variable (column) names?

present %>% 
  summarize(min =min(year), max = max(year))
## # A tibble: 1 × 2
##     min   max
##   <dbl> <dbl>
## 1  1940  2002
range(present$year)
## [1] 1940 2002
dim(present)
## [1] 63  3
colnames(present)
## [1] "year"  "boys"  "girls"

The years is from 1940 to 2002. The dimension is 63 column x 3 rows, with 3 columns: years, boys, girls, with 3 custome made: boys_to_girls_ratio, totals, boys_ratio

Exercise 5

How do these counts compare to Arbuthnot’s? Are they of a similar magnitude?

dim(present)
## [1] 63  3
dim(arbuthnot)
## [1] 82  6
sapply(arbuthnot,range)
##      year boys girls total boy_to_girl_ratio boy_ratio
## [1,] 1629 2890  2722  5612          1.010673 0.5026541
## [2,] 1710 8426  7779 16145          1.156075 0.5361942
sapply(present, range)
##      year    boys   girls
## [1,] 1940 1211684 1148715
## [2,] 2002 2186274 2082052

In Artuthnot data there is 82 years of data presented while present has only 63 years of data. I believe that Arthunot has more data to work with.

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.? Include the plot in your response. Hint: You should be able to reuse your code from Exercise 3 above, just replace the dataframe name.

present <- present %>%
  mutate(totals = boys + girls)
present <- present %>%
  mutate(boys_ratio = boys / totals)
ggplot(data = present, aes(x= year, y = boys_ratio)) + geom_line()

From this graph we can see that the boys being born in greater proportion than the girl.

Exercise 7

In what year did we see the most total number of births in the U.S.? Hint: First calculate the totals and save it as a new variable. Then, sort your dataset in descending order based on the total column. You can do this interactively in the data viewer by clicking on the arrows next to the variable names. To include the sorted result in your report you will need to use two new functions: arrange (for sorting). We can arrange the data in a descending order with another function: desc (for descending order). The sample code is provided below.

present[present$totals == max(present$totals), "year"]
## # A tibble: 1 × 1
##    year
##   <dbl>
## 1  1961
LS0tCnRpdGxlOiAiTGFiIDE6IEludHJvIHRvIFIgRmFsbCAyMDIyIERhdGEgNjA2IgphdXRob3I6ICJXaWxzb24gQ2hhdSIKZGF0ZTogIjgvMzEvMjIiCm91dHB1dDogb3BlbmludHJvOjpsYWJfcmVwb3J0Ci0tLQoKYGBge3IgbG9hZC1wYWNrYWdlcywgbWVzc2FnZT1GQUxTRX0KbGlicmFyeSh0aWR5dmVyc2UpCmxpYnJhcnkob3BlbmludHJvKQpgYGAKCldoYXQgY29tbWFuZCB3b3VsZCB5b3UgdXNlIHRvIGV4dHJhY3QganVzdCB0aGUgY291bnRzIG9mIGdpcmxzIGJhcHRpemVkPyBUcnkga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