library(tidyverse)
library(openintro)

Exercise 1

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

*The answer: is 82.

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
length(arbuthnot$girls)
## [1] 82

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.)

*The answer: The number of girls baptized over the years is increasing therefore there is a positive linear

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?

*The answer: The number of boys baptized increased since 1660 and it became a positive linear

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



### Exercise 4

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

*The Answer:

range: 1940 2002
dimensions of the data frame: 63 3
variable: “year” “boys” “girls”


```r
range(present$year)
## [1] 1940 2002
dim(present)
## [1] 63  3
names(present)
## [1] "year"  "boys"  "girls"

Exercise 5

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

*The Answer: no they are different than Arbuthnot’s, they are in millions and ranges from 1940 - 2002 and the Arbuthnot’s in thousands and ranges from 1629 - 1710.

arbuthnot$girls + arbuthnot$boys
##  [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
present$girls + present$boys
##  [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
range(present$year)
## [1] 1940 2002
range(arbuthnot$year)
## [1] 1629 1710

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.

*The Answer: the proportion of boys had increased in the sixties and then decliened in late seventies then increased again in the eighties. and yes Arbuthnot’s observation about boys being born in greater proportion than girls hold up in the U.S is true.

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

plot (present$boys,type="l")

present$boys > present$girls #Arbuthnot’s observation
##  [1] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
## [16] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
## [31] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
## [46] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
## [61] TRUE TRUE TRUE

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.

*The answer: the year with most births is 1961.

present <- present %>%
        mutate(total = boys + girls)
present <- present %>%
        arrange(desc(total))
head(present, 3)
## # A tibble: 3 x 4
##    year    boys   girls   total
##   <dbl>   <dbl>   <dbl>   <dbl>
## 1  1961 2186274 2082052 4268326
## 2  1960 2179708 2078142 4257850
## 3  1957 2179960 2074824 4254784
LS0tCnRpdGxlOiAiTGFiIDE6IEludHJvIHRvIFIiCmF1dGhvcjogIkthcmltIEhhbW1vdWQiCmRhdGU6ICJgciBTeXMuRGF0ZSgpYCIKb3V0cHV0OiBvcGVuaW50cm86OmxhYl9yZXBvcnQKLS0tCgpgYGB7ciBsb2FkLXBhY2thZ2VzLCBtZXNzYWdlPUZBTFNFfQpsaWJyYXJ5KHRpZHl2ZXJzZSkKbGlicmFyeShvcGVuaW50cm8pCmBgYAoKIyMjIEV4ZXJjaXNlIDEKCldoYXQgY29tbWFuZCB3b3VsZCB5b3UgdXNlIHRvIGV4dHJhY3QganVzdCB0aGUgY291bnRzIG9mIGdpcmxzIGJhcHRpemVkPyBUcnkgaXQhCgoqVGhlIGFuc3dlcjogaXMgODIuCgpgYGB7ciB2aWV3LWdpcmxzLWNvdW50c30KYXJidXRobm90JGdpcmxzCmxlbmd0aChhcmJ1dGhub3QkZ2lybHMpCmBgYAoKCiMjIyBFeGVyY2lzZSAyCgpJcyB0aGVyZSBhbiBhcHBhcmVudCB0cmVuZCBpbiB0aGUgbnVtYmVyIG9mIGdpcmxzIGJhcHRpemVkIG92ZXIgdGhlIHllYXJzPyBIb3cgd291bGQgeW91IGRlc2NyaWJlIGl0PyAoVG8gZW5zdXJlIHRoYXQgeW91ciBsYWIgcmVwb3J0IGlzIGNvbXByZW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