library(tidyverse)
library(openintro)
$girls arbuthnot
## [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
Is there an apparent trend in the number of girls baptized over the years? How would you describe it?
The number of girls baptized is increasing over the years. In the first half the number is largely below the mean, in the second half the number is always above the mean.
ggplot(data = arbuthnot, aes(x = year, y = girls)) + geom_line(color = "red") +
geom_line(aes(y = mean(girls)), color = "purple", linetype = "dotted") +
geom_text(aes(mean(year), mean(girls) , label = "Mean"), vjust= -0.5, hjust= 7) +
geom_line(aes(x = mean(year)), color = "purple", linetype = "dotted") +
geom_text(aes(mean(year), mean(girls) , label = "Half"), vjust= -12, hjust= 1.5)
Now, generate a plot of the proportion of boys born over time. What do you see?
The proportion of boys is trending downwards slightly.
<- arbuthnot %>% mutate(total = boys + girls)
arbuthnot <- arbuthnot %>% mutate(boy_ratio = boys / total)
arbuthnot ggplot(data = arbuthnot, aes(x = year, y = boy_ratio)) + geom_line(color = "blue")
What years are included in this data set? What are the dimensions of the data frame? What are the variable (column) names?
The years are from 1940 to 2002. The data frame is 63 rows and 3 columns named “year”, “boys”, “girls”.
%>% summarize(min = min(year), max = max(year)) present
## # A tibble: 1 × 2
## min max
## <dbl> <dbl>
## 1 1940 2002
glimpse(present)
## 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…
How do these counts compare to Arbuthnot’s? Are they of a similar magnitude?
The mean of the present counts is 320 times the mean of the Arbuthnot counts.
<- present %>% mutate(total = boys + girls)
present mean(present$total) / mean(arbuthnot$total)
## [1] 321.5869
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.
The proportion of boys born has gone down from 1940 to 2002 but Arbuthnot’s observation about boys being born in greater proportion than girls holds up in the U.S.
<- present %>% mutate(boy_ratio = boys / total)
present ggplot(data = present, aes(x = year, y = boy_ratio)) + geom_line(color = "blue")
In what year did we see the most total number of births in the U.S.?
1961
%>%
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
## # … with 53 more rows