library(tidyverse)
library(openintro)
Exercise 1
I would use the arbuthnot$boys command.
## [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
## [1] 5218 4858 4422 4994 5158 5035 5106 4917 4703 5359 5366 5518 5470 5460 4793
## [16] 4107 4047 3768 3796 3363 3079 2890 3231 3220 3196 3441 3655 3668 3396 3157
## [31] 3209 3724 4748 5216 5411 6041 5114 4678 5616 6073 6506 6278 6449 6443 6073
## [46] 6113 6058 6552 6423 6568 6247 6548 6822 6909 7577 7575 7484 7575 7737 7487
## [61] 7604 7909 7662 7602 7676 6985 7263 7632 8062 8426 7911 7578 8102 8031 7765
## [76] 6113 8366 7952 8379 8239 7840 7640
ggplot(data = arbuthnot, aes(x = year, y = girls)) +
geom_point()

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

Exercise 2
There is a trend in the number of girls baptized over the years. The
graph is shows a tremendous increase over time, representing a positive
linear trend between girls being baptized and year.
# Insert code for Exercise 2 here
?ggplot
5218 + 4683
## [1] 9901
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 = total)) +
geom_line()

## [1] 1.114243
arbuthnot <- arbuthnot %>%
mutate(boy_to_girl_ratio = boys / girls)
5218 / (5218 + 4683)
## [1] 0.5270175
arbuthnot <- arbuthnot %>%
mutate(boy_ratio = boys / total)
Exercise 3
The graph for boys baptized over time shows more sporadic trends, as
the amount of baptized boys seems to frequently fluctuate. After 1660, a
postive linear trend can be observed.
arbuthnot <- arbuthnot %>%
mutate(more_boys = boys > girls)
Insert any text here.
# Insert code for Exercise 3 here
Exercise 4
## # 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
The range of this data set is from 1940-2002. The dimensions are 63
and the variables are years, boys, and girls.
# Insert code for Exercise 4 here ?ggplot
Exercise 5
These counts differ from Arbuthnot’s. These counts are represented in
millions, whereas Arbuthnot’s are in thousands. Additionally, the ranges
of the data are differing where the present range from 1940 - 2002 and
Arbuthnot’s range from 1629 - 1710.
# Insert code for Exercise 5 here
Exercise 6
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
Yes, Arbuthnot’s observation about boys being born in greater
proportion than girls holds up in the U.S. The plot shows the proportion
of boys increased around 1960 and then decreased in late seventies just
to increase again around 1980.
``` r
### Exercise 7
present <- present %>%
mutate(total = boys + girls)
present <- present %>%
arrange(desc(total))
head(present, 3)
## # A tibble: 3 × 4
## year boys girls total
## <dbl> <dbl> <dbl> <dbl>
## 1 1961 2186274 2082052 4268326
## 2 1960 2179708 2078142 4257850
## 3 1957 2179960 2074824 4254784
1961 was the year with the most births.
LS0tCnRpdGxlOiAiTGFiIDE6IEludHJvIHRvIFIiCmF1dGhvcjogIkthdGllIFJ1c3NlbGwiCmRhdGU6ICJgciBTeXMuRGF0ZSgpYCIKb3V0cHV0OiBvcGVuaW50cm86OmxhYl9yZXBvcnQKLS0tCgpgYGB7ciBsb2FkLXBhY2thZ2VzLCBtZXNzYWdlPUZBTFNFfQpsaWJyYXJ5KHRpZHl2ZXJzZSkKbGlicmFyeShvcGVuaW50cm8pCmBgYAoKIyMjIEV4ZXJjaXNlIDEKSSB3b3VsZCB1c2UgdGhlIGFyYnV0aG5vdCRib3lzIGNvbW1hbmQuCmBgYHtyIHZpZXctZ2lybHMtY291bnRzfQphcmJ1dGhub3QkZ2lybHMKYXJidXRobm90JGJveXMKZ2dwbG90KGRhdGEgPSBhcmJ1dGhub3QsIGFlcyh4ID0geWVhciwgeSA9IGdpcmxzKSkgKyAKICBnZW9tX3BvaW50KCkKZ2dwbG90KGRhdGEgPSBhcmJ1dGhub3QsIGFlcyh4ID0geWVhciwgeSA9IGdpcmxzKSkgKwogIGdlb21fbGluZSgpCmBgYAoKYGBge3J9CgpgYGAKCgojIyMgRXhlcmNpc2UgMgpUaGVyZSBpcyBhIHRyZW5kIGluIHRoZSBudW1iZXIgb2YgZ2lybHMgYmFwdGl6ZWQgb3ZlciB0aGUgeWVhcnMuIFRoZSBncmFwaCBpcyBzaG93c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