library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(ggplot2)
library(statsr)
The required datasets for this lab are
data("arbuthnot")
data("present")
How many variables are included in this data set (data set: arbuthnot)? 1) 2 2) 3 3) 4 4) 82 5) 1710
dim(arbuthnot)
## [1] 82 3
names(arbuthnot)
## [1] "year" "boys" "girls"
Answer: 3
What command would you use to extract just the counts of girls born? 1) arbuthnot$boys 2) \(girls 3) arbuthnot\)girls 4) girls 5) arbuthnot[girls]
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 : arbuthnot$girls
Which of the following best describes the number of girls baptised over the years included in this dataset?
ggplot(data = arbuthnot, aes(x = year, y = girls)) +
geom_point()
Answer : There is initially an increase in number of girls baptised. which peaks around 1640. After 1640 there is a decrease in the number of girls baptised, but the number begins to increase again in 1640. Overall the trend is an in crease in the number of girls baptised
How many variables are included in this data set (data set: present)? 1) 74 2) 2 3) 2013 4) 4 5) 3
dim(present)
## [1] 74 3
Answer : 3
Calculate the total number of births for each year and store these values in a new variable called total in the present dataset. Then, calculate the proportion of boys born each year and store these values in a new variable called prop_boys in the same dataset. Plot these values over time and based on the plot determine if the following statement is true or false: The proportion of boys born in the US has decreased over time.
present <- present %>% mutate(total = boys + girls)
present <- present %>% mutate(prop_boys = boys/total)
ggplot(present, aes(x=year,y=prop_boys)) + geom_line() + geom_point()
Answer : True
Create a new variable called more_boys which contains the value of either TRUE if that year had more boys than girls, or FALSE if that year did not. Based on this variable which of the following statements is true?
present <- present %>% mutate(more_boys = boys > girls)
present$more_boys
## [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 TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
Answer : Every year there are more boys than girls
Calculate the boy-to-girl ratio each year, and store these values in a new variable called prop_boy_girl in the present dataset. Plot these values over time. Which of the following best describes the trend?
present <- present %>% mutate(prop_boy_girl = boys/girls)
ggplot(present, aes(x=year,y=prop_boy_girl)) + geom_line() + geom_point()
Answer : There is initially decrease in the boy-to-girl ratio, and then an increase between 1960 and 1970, followed by a decrease
In what year did we see the most total number of births in the U.S.?
present$year[which.max(present$total)]
## [1] 2007
Answer : 2007