library(tidyverse)
library(openintro)
Exercise 1
## [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
There is an overall positive trend in the number of girls baptized
over the years. During years 1640 to 1650 and 1655 to 1660, there was a
decrease in baptisms of girls. However, from 1660 to 1710, there was a
general, strong increase in the number of girls baptized.
ggplot(data = arbuthnot, aes(x = year, y = girls)) +
geom_point()

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

Exercise 3
arbuthnot <- arbuthnot %>%
mutate(total = boys + girls)
arbuthnot <- arbuthnot %>%
mutate(boy_ratio = boys / total)
ggplot(data = arbuthnot, aes(x = year, y = boy_ratio)) +
geom_line()

Exercise 4
In this data set, years 1940 to 2002 are portrayed. The dimensions of
the data frame are 63 rows and 3 columns. The variable names are year,
number of boys, and the number of girls within the birth records in the
United States.
present %>%
summarize(min = min(year),
max = max (year)
)
## # A tibble: 1 × 2
## min max
## <dbl> <dbl>
## 1 1940 2002
## 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
Within the birth records in the United States, there is a drastic
increase in numbers of boys and girls born in a year compared to
Artbutnot’s data. They are not similar in magnitude, with a calculated
magnitude ratio of 321.59 .
present <- present %>%
mutate (total = boys + girls)
magnitude_ratio = mean(present$total)/mean(arbuthnot$total)
print(magnitude_ratio)
## [1] 321.5869
Exercise 6
Within the plot that displays the proportion of boys born over time,
I see a general decrease in the boy ratio according to the birth records
in the United States. Yes, Arbuthnot’s observation about boys being born
in greater proportion than girls holds up in the U.S. as the boy ratio
values are above 0.5, indicating that more boys are born in comparison
to girls.
present <- present %>%
mutate(total = boys + girls)
present <- present %>%
mutate(boy_ratio = boys / total)
ggplot(data = present, aes(x = year, y = boy_ratio)) +
geom_line()

Exercise 7
The year that we see the most total number of births in the U.S. is
within 1961, with a peak total of 4268326 births of children that
year.
present %>%
arrange(desc(total))
## # A tibble: 63 × 5
## year boys girls total boy_ratio
## <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
## # ℹ 53 more rows
LS0tCnRpdGxlOiAiUiBMYWIgMSIKYXV0aG9yOiAiQmV0dHkgV29uZGUiCmRhdGU6ICJgciBTeXMuRGF0ZSgpYCIKb3V0cHV0OiBvcGVuaW50cm86OmxhYl9yZXBvcnQKLS0tCgpgYGB7ciBsb2FkLXBhY2thZ2VzLCBtZXNzYWdlPUZBTFNFfQpsaWJyYXJ5KHRpZHl2ZXJzZSkKbGlicmFyeShvcGVuaW50cm8pCmBgYAoKIyMjIEV4ZXJjaXNlIDEKCgpgYGB7ciB2aWV3LWdpcmxzLWNvdW50c30KYXJidXRobm90JGdpcmxzCmBgYAoKCiMjIyBFeGVyY2lzZSAyClRoZXJlIGlzIGFuIG92ZXJhbGwgcG9zaXRpdmUgdHJlbmQgaW4gdGhlIG51bWJlciBvZiBnaXJscyBiYXB0aXplZC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