Lab 1

Introduction

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…

Exercise 1

The command to view the counts of the girls baptized will be sum(arbuthnot$girls) output seen below

sum(arbuthnot$girls)
[1] 453841

Data visualization

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

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

Exercise 2

Analyzing the previous plots shows us that the amount of baptisms for girls shrunk dramatically between 1640 and 1650. However, in 1660 the amount of girls baptized began to shoot up and had a fairly consistent trend into the early 1700s with a few down years that never met the lows of pre 1660.

R as a calculator

arbuthnot$boys + arbuthnot$girls
 [1]  9901  9315  8524  9584  9997  9855 10034  9522  9160 10311 10150 10850
[13] 10670 10370  9410  8104  7966  7163  7332  6544  5825  5612  6071  6128
[25]  6155  6620  7004  7050  6685  6170  5990  6971  8855 10019 10292 11722
[37]  9972  8997 10938 11633 12335 11997 12510 12563 11895 11851 11775 12399
[49] 12626 12601 12288 12847 13355 13653 14735 14702 14730 14694 14951 14588
[61] 14771 15211 15054 14918 15159 13632 13976 14861 15829 16052 15363 14639
[73] 15616 15687 15448 11851 16145 15369 16066 15862 15220 14928
# |> as a piping tool is just a bit easier to type 
arbuthnot <- arbuthnot |> 
  mutate(total = boys + girls)

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

5218 / 4683
[1] 1.114243
5218 / (5218 + 4683)
[1] 0.5270175
arbuthnot <- arbuthnot |>
  mutate(boy_ratio = boys / total)

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

mean(arbuthnot$boy_ratio)
[1] 0.5169751
max(arbuthnot$boy_ratio)
[1] 0.5361942

Exercise 3

When looking at the ratio of boys to girls I can see that it is consistently above the 50 percent mark with the mean being 51.6% and reaching a peak of 53.6%

More Practice

data('present', package='openintro')

arbuthnot |> 
  summarize(min=min(boys), max=max(boys))
# A tibble: 1 × 2
    min   max
  <int> <int>
1  2890  8426
present |> 
  summarize(min=min(year), max=max(year))
# A tibble: 1 × 2
    min   max
  <dbl> <dbl>
1  1940  2002
years<-present |> 
  summarize(min=min(year), max=max(year))

dim(present)
[1] 63  3
names(present)
[1] "year"  "boys"  "girls"

Exercise 4

The years included in the dataset are 1940, 2002, the dimensions of the dataset are 63, 3, and the names of the columns in the dataset are year, boys, girls

Exercise 5

present$total <- present$boys + present$girls

ggplot(data = present, aes(x = year, y = total) ) + 
         geom_line()

The magnitude is on a completely different scale when comparing the 1600s dataset to the modern day dataset. The modern day dataset is several times larger than the Arbuthnot dataset

Exercise 6

present <- present |> 
  mutate( boys_ratio = boys / total )

ggplot( data = present, aes( x = year, y = boys_ratio)) +
  geom_line()

The margin in which boys are born more often than girls is much lower, but it seems to show a trend that boys have continued to be born slightly more than girls.

Exercise 7

present[  which(present$total == max(present$total)), 'year']
# A tibble: 1 × 1
   year
  <dbl>
1  1961
#or to follow the exercise suggestion 

present |> 
  arrange(desc(total))
# A tibble: 63 × 5
    year    boys   girls   total boys_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

The highest number of births come from the baby boomer generation of 1961