data('arbuthnot', package='openintro')
What command would you use to extract just the counts of girls baptized? Try it!
Answer:
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
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.)
Answer:
There is an apparent overall upward trend in the number of girls baptized over the years. Although the number fluctuates from year to year, the number of girls baptized generally increases from the early years toward the later years of the dataset.
# Load library
library(ggplot2)
ggplot(arbuthnot, aes(x = year, y = girls)) +
geom_line(color = "orange") +
geom_point(color = "red") +
labs(
title = "Number of Girls Baptized Over Time",
x = "Year",
y = "Number of Girls"
) +
theme_minimal()
Now, generate a plot of the proportion of boys born over time. What do you see?
Answer:
To effectively visualize the proportion of boys baptized over time, a line plot is appropriate, with the x-axis representing the years and the y-axis representing the proportion of boys. The plot shows that the proportion of boys generally remains above 50% over the given time period, although it fluctuates from year to year.
# Load library
library(dplyr)
# Calculate the proportion of boys baptized each year
arbuthnot <- arbuthnot %>%
mutate(proportion_boys = boys / (boys + girls))
# Create a plot of the proportion of boys baptized over time
ggplot(arbuthnot, aes(x = year, y = proportion_boys)) +
geom_line(color = "blue") +
geom_point(color = "blue") +
labs(
title = "Proportion of Boys Baptized Over Time",
x = "Year",
y = "Proportion of Boys"
) +
theme_minimal()
What years are included in this data set? What are the dimensions of the data frame? What are the variable (column) names?
Answer:
The present dataset includes data from 1940 to 2002. The data frame contains 63 observations and 3 variables. The variable names are year, boys, and girls.
data('present', package='openintro')
arbuthnot %>%
summarize(min = min(boys), max = max(boys))
## # A tibble: 1 × 2
## min max
## <int> <int>
## 1 2890 8426
range(present$year)
## [1] 1940 2002
dim(present)
## [1] 63 3
colnames(present)
## [1] "year" "boys" "girls"
How do these counts compare to Arbuthnot’s? Are they of a similar magnitude?
Answer:
To compare the two datasets, I calculated the minimum, maximum, and mean birth counts for boys and girls in both the arbuthnot and present datasets. The results show that the birth counts in the present dataset are much larger than those in Arbuthnot’s dataset. Therefore, the two datasets are not of a similar magnitude. The larger counts in the present dataset reflect the much larger population represented by the U.S. birth records.
# Summary statistics for the arbuthnot dataset
arbuthnot %>%
summarize(
min_boys = min(boys),
max_boys = max(boys),
mean_boys = mean(boys),
min_girls = min(girls),
max_girls = max(girls),
mean_girls = mean(girls) )
## # A tibble: 1 × 6
## min_boys max_boys mean_boys min_girls max_girls mean_girls
## <int> <int> <dbl> <int> <int> <dbl>
## 1 2890 8426 5907. 2722 7779 5535.
# Summary statistics for the present dataset
present %>% summarize(
min_boys = min(boys),
max_boys = max(boys),
mean_boys = mean(boys),
min_girls = min(girls),
max_girls = max(girls),
mean_girls = mean(girls) )
## # A tibble: 1 × 6
## min_boys max_boys mean_boys min_girls max_girls mean_girls
## <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 1211684 2186274 1885600. 1148715 2082052 1793915.
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.
Answer:
The overall trend in male birth rates over time has remained consistent, showing no significant deviations or anomalies in the observed patterns.
# Calculate the proportion of boys born each year
present <- present %>%
mutate(proportion_boys = boys / (boys + girls))
# Create a plot of the proportion of boys born over time
ggplot(present, aes(x = year, y = proportion_boys)) +
geom_line(color = "orange") +
geom_point(color = "black") +
labs(title = "Proportion of Boys Born Over Time",
x = "Year",
y = "Proportion of Boys") +
theme_minimal()
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.
Answer:
The year with the highest total number of births in the U.S. was 1961. I calculated the total number of births by adding the number of boys and girls born each year and then sorted the data in descending order. The results show that 1961 had the highest total number of births.
present<- present %>%
mutate(total = boys + girls)
present %>%
arrange(desc(total))
## # A tibble: 63 × 5
## year boys girls proportion_boys total
## <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 1961 2186274 2082052 0.512 4268326
## 2 1960 2179708 2078142 0.512 4257850
## 3 1957 2179960 2074824 0.512 4254784
## 4 1959 2173638 2071158 0.512 4244796
## 5 1958 2152546 2051266 0.512 4203812
## 6 1962 2132466 2034896 0.512 4167362
## 7 1956 2133588 2029502 0.513 4163090
## 8 1990 2129495 2028717 0.512 4158212
## 9 1991 2101518 2009389 0.511 4110907
## 10 1963 2101632 1996388 0.513 4098020
## # ℹ 53 more rows
present$year[which.max(present$boys + present$girls)]
## [1] 1961
present %>%
filter(year == 1961)
## # A tibble: 1 × 5
## year boys girls proportion_boys total
## <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 1961 2186274 2082052 0.512 4268326
This analysis examined historical baptism records from John Arbuthnot (1629–1710) and compared them with modern U.S. birth records (1940–2002). The analysis revealed several important patterns in the number and proportion of boys and girls born over time.
• The number of girls baptized steadily declined over time.
•
This could be due to population changes, societal shifts, or data
recording practices.
• Arbuthnot originally observed that more boys than girls were
baptized.
• This trend remains consistent in modern U.S. birth
records, with the proportion of boys consistently above 50%.
• While Arbuthnot’s dataset records thousands of births per year,
• the present dataset records millions—a result of population
growth.
The highest number of births was recorded in 1961, reflecting the post-war Baby Boom.
• The pattern of slightly more boys than girls being born is
consistent between Arbuthnot’s historical data and the modern U.S.
data.
• Birth counts have increased substantially over time, largely
reflecting changes in population size. • Data visualization and basic R
functions such as mutate(), arrange(), and ggplot() make it possible to
identify and explore these patterns effectively.