source("http://www.openintro.org/stat/data/present.R")
print(present)
##    year    boys   girls
## 1  1940 1211684 1148715
## 2  1941 1289734 1223693
## 3  1942 1444365 1364631
## 4  1943 1508959 1427901
## 5  1944 1435301 1359499
## 6  1945 1404587 1330869
## 7  1946 1691220 1597452
## 8  1947 1899876 1800064
## 9  1948 1813852 1721216
## 10 1949 1826352 1733177
## 11 1950 1823555 1730594
## 12 1951 1923020 1827830
## 13 1952 1971262 1875724
## 14 1953 2001798 1900322
## 15 1954 2059068 1958294
## 16 1955 2073719 1973576
## 17 1956 2133588 2029502
## 18 1957 2179960 2074824
## 19 1958 2152546 2051266
## 20 1959 2173638 2071158
## 21 1960 2179708 2078142
## 22 1961 2186274 2082052
## 23 1962 2132466 2034896
## 24 1963 2101632 1996388
## 25 1964 2060162 1967328
## 26 1965 1927054 1833304
## 27 1966 1845862 1760412
## 28 1967 1803388 1717571
## 29 1968 1796326 1705238
## 30 1969 1846572 1753634
## 31 1970 1915378 1816008
## 32 1971 1822910 1733060
## 33 1972 1669927 1588484
## 34 1973 1608326 1528639
## 35 1974 1622114 1537844
## 36 1975 1613135 1531063
## 37 1976 1624436 1543352
## 38 1977 1705916 1620716
## 39 1978 1709394 1623885
## 40 1979 1791267 1703131
## 41 1980 1852616 1759642
## 42 1981 1860272 1768966
## 43 1982 1885676 1794861
## 44 1983 1865553 1773380
## 45 1984 1879490 1789651
## 46 1985 1927983 1832578
## 47 1986 1924868 1831679
## 48 1987 1951153 1858241
## 49 1988 2002424 1907086
## 50 1989 2069490 1971468
## 51 1990 2129495 2028717
## 52 1991 2101518 2009389
## 53 1992 2082097 1982917
## 54 1993 2048861 1951379
## 55 1994 2022589 1930178
## 56 1995 1996355 1903234
## 57 1996 1990480 1901014
## 58 1997 1985596 1895298
## 59 1998 2016205 1925348
## 60 1999 2026854 1932563
## 61 2000 2076969 1981845
## 62 2001 2057922 1968011
## 63 2002 2057979 1963747

1, What years are included in this data set? What are the dimensions of the data frame and what are the variable or column names?

present$year[1]
## [1] 1940
present$year[nrow(present)]
## [1] 2002

The second part of the question asks for the dimensions of present

dim(present)[1]
## [1] 63
dim(present)[2]
## [1] 3

The variable or column names are:

names(present)
## [1] "year"  "boys"  "girls"

2, How do these counts compare to Arbuthnot’s? Are they on a similar scale?

summary(present$boys)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
## 1211684 1799857 1924868 1885600 2058524 2186274
summary(present$girls)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
## 1148715 1711405 1831679 1793915 1965538 2082052

answer: compare those data, Arbuthnot clearly shows that we are dealing with much higher numbers of births (over 200 times as many per year).

3, Make a plot that displays the boy-to-girl ratio for every year in the data set. 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

present$boys/(present$boys + present$girls)
##  [1] 0.5133386 0.5131376 0.5141926 0.5138001 0.5135613 0.5134745 0.5142562
##  [8] 0.5134883 0.5131024 0.5130881 0.5130778 0.5126891 0.5124173 0.5130027
## [15] 0.5125423 0.5123716 0.5125011 0.5123550 0.5120462 0.5120713 0.5119269
## [22] 0.5122088 0.5117064 0.5128408 0.5115250 0.5124656 0.5118474 0.5121866
## [29] 0.5130068 0.5129073 0.5133154 0.5126337 0.5124973 0.5127013 0.5133340
## [36] 0.5130513 0.5127982 0.5128057 0.5128266 0.5126110 0.5128692 0.5125792
## [43] 0.5123372 0.5126648 0.5122425 0.5126849 0.5124035 0.5121951 0.5121931
## [50] 0.5121286 0.5121179 0.5112054 0.5121992 0.5121845 0.5116894 0.5119398
## [57] 0.5114951 0.5116337 0.5115255 0.5119072 0.5117182 0.5111665 0.5117154

the proportion of gilrs

present$girls/(present$boys + present$girls)
##  [1] 0.4866614 0.4868624 0.4858074 0.4861999 0.4864387 0.4865255 0.4857438
##  [8] 0.4865117 0.4868976 0.4869119 0.4869222 0.4873109 0.4875827 0.4869973
## [15] 0.4874577 0.4876284 0.4874989 0.4876450 0.4879538 0.4879287 0.4880731
## [22] 0.4877912 0.4882936 0.4871592 0.4884750 0.4875344 0.4881526 0.4878134
## [29] 0.4869932 0.4870927 0.4866846 0.4873663 0.4875027 0.4872987 0.4866660
## [36] 0.4869487 0.4872018 0.4871943 0.4871734 0.4873890 0.4871308 0.4874208
## [43] 0.4876628 0.4873352 0.4877575 0.4873151 0.4875965 0.4878049 0.4878069
## [50] 0.4878714 0.4878821 0.4887946 0.4878008 0.4878155 0.4883106 0.4880602
## [57] 0.4885049 0.4883663 0.4884745 0.4880928 0.4882818 0.4888335 0.4882846

compare the proportion of boys and girls

(present$boys/(present$boys + present$girls)) > (present$girls/(present$boys + present$girls))
##  [1] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
## [15] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
## [29] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
## [43] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
## [57] TRUE TRUE TRUE TRUE TRUE TRUE TRUE

Make a plot that displays the boy-to-girl ratio for every year in the data set

present$boys/present$girls
##  [1] 1.054817 1.053969 1.058429 1.056767 1.055757 1.055391 1.058698
##  [8] 1.055449 1.053820 1.053760 1.053716 1.052078 1.050934 1.053399
## [15] 1.051460 1.050742 1.051286 1.050672 1.049374 1.049480 1.048873
## [22] 1.050057 1.047948 1.052717 1.047188 1.051137 1.048540 1.049964
## [29] 1.053417 1.052997 1.054719 1.051845 1.051271 1.052129 1.054797
## [36] 1.053605 1.052538 1.052569 1.052657 1.051749 1.052837 1.051615
## [43] 1.050597 1.051976 1.050199 1.052061 1.050876 1.050000 1.049991
## [50] 1.049720 1.049676 1.045849 1.050017 1.049955 1.047877 1.048928
## [57] 1.047062 1.047643 1.047190 1.048791 1.047998 1.045686 1.047986
plot(x = present$year, y = present$boys/present$girls, type = "l")

#4, In what year did we see the most total number of births in the U.S.?

present$totals = present$girls + present$boys
sort.int(present$totals, index.return = TRUE)
## $x
##  [1] 2360399 2513427 2735456 2794800 2808996 2936860 3136965 3144198
##  [9] 3159958 3167788 3258411 3288672 3326632 3333279 3494398 3501564
## [17] 3520959 3535068 3554149 3555970 3559529 3600206 3606274 3612258
## [25] 3629238 3638933 3669141 3680537 3699940 3731386 3750850 3756547
## [33] 3760358 3760561 3809394 3846986 3880894 3891494 3899589 3902120
## [41] 3909510 3941553 3952767 3959417 4000240 4017362 4021726 4025933
## [49] 4027490 4040958 4047295 4058814 4065014 4098020 4110907 4158212
## [57] 4163090 4167362 4203812 4244796 4254784 4257850 4268326
## 
## $ix
##  [1]  1  2  6  5  3  4 34 36 35 37 33  7 38 39 40 29 28  9 11 32 10 30 27
## [24] 41 42 44 45 43  8 31 12 47 26 46 48 13 58 57 56 14 49 59 55 60 54 15
## [47] 63 62 25 50 16 61 53 24 52 51 17 23 19 20 18 21 22
present$year[22]
## [1] 1961