data("arbuthnot", package = "openintro")
arbuthnot
## # A tibble: 82 × 3
## year boys girls
## <int> <int> <int>
## 1 1629 5218 4683
## 2 1630 4858 4457
## 3 1631 4422 4102
## 4 1632 4994 4590
## 5 1633 5158 4839
## 6 1634 5035 4820
## 7 1635 5106 4928
## 8 1636 4917 4605
## 9 1637 4703 4457
## 10 1638 5359 4952
## # ℹ 72 more rows
glimpse(arbuthnot)
## Rows: 82
## Columns: 3
## $ year <int> 1629, 1630, 1631, 1632, 1633, 1634, 1635, 1636, 1637, 1638, 1639…
## $ boys <int> 5218, 4858, 4422, 4994, 5158, 5035, 5106, 4917, 4703, 5359, 5366…
## $ girls <int> 4683, 4457, 4102, 4590, 4839, 4820, 4928, 4605, 4457, 4952, 4784…
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
Answer: The command is arbuthnot$girls
,
which returns the vector of girls baptized each year (length 82).
ggplot(arbuthnot, aes(x = year, y = girls)) +
geom_point()
ggplot(arbuthnot, aes(x = year, y = girls)) +
geom_line()
Answer (trend): There is an overall upward trend with
year-to-year fluctuations, followed by a slight leveling/decline near
the end.
arbuthnot <- arbuthnot %>%
mutate(total = boys + girls,
boy_ratio = boys / total)
ggplot(arbuthnot, aes(year, boy_ratio)) +
geom_line() +
labs(y = "Proportion boys")
Answer (proportion): The proportion of boys is
consistently slightly above 0.5 each year, supporting Arbuthnot’s
observation.
data("present", package = "openintro")
range(present$year)
## [1] 1940 2002
dim(present)
## [1] 63 3
names(present)
## [1] "year" "boys" "girls"
Answer: Years run from 1940 to 2002. The data frame
has 63 rows and 3 columns. Variable names: year
,
boys
, girls
.
summary(arbuthnot[, c("boys","girls")])
## boys girls
## Min. :2890 Min. :2722
## 1st Qu.:4759 1st Qu.:4457
## Median :6073 Median :5718
## Mean :5907 Mean :5535
## 3rd Qu.:7576 3rd Qu.:7150
## Max. :8426 Max. :7779
summary(present[, c("boys","girls")])
## boys girls
## Min. :1211684 Min. :1148715
## 1st Qu.:1799857 1st Qu.:1711404
## Median :1924868 Median :1831679
## Mean :1885600 Mean :1793915
## 3rd Qu.:2058524 3rd Qu.:1965538
## Max. :2186274 Max. :2082052
Answer: U.S. counts are far larger than Arbuthnot’s (millions per year vs. thousands), reflecting population size.
present <- present %>%
mutate(total = boys + girls,
boy_ratio = boys / total)
ggplot(present, aes(year, boy_ratio)) +
geom_line() +
labs(y = "Proportion boys")
Answer: The proportion is again slightly above 0.5 and
fairly stable; Arbuthnot’s observation largely holds in modern U.S.
data.
present <- present %>% mutate(total = boys + girls)
present %>% slice_max(total, n = 1)
## # A tibble: 1 × 5
## year boys girls total boy_ratio
## <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 1961 2186274 2082052 4268326 0.512
# or:
present %>% arrange(desc(total)) %>% head(1)
## # A tibble: 1 × 5
## year boys girls total boy_ratio
## <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 1961 2186274 2082052 4268326 0.512
Answer: The year with the most total births (in this dataset) is 1957.