library('DATA606')  
## 
## Welcome to CUNY DATA606 Statistics and Probability for Data Analytics 
## This package is designed to support this course. The text book used 
## is OpenIntro Statistics, 3rd Edition. You can read this by typing 
## vignette('os3') or visit www.OpenIntro.org. 
##  
## The getLabs() function will return a list of the labs available. 
##  
## The demo(package='DATA606') will list the demos that are available.
## 
## Attaching package: 'DATA606'
## The following object is masked from 'package:utils':
## 
##     demo
source("http://www.openintro.org/stat/data/arbuthnot.R")

Take a look at the data first

head(arbuthnot)
##   year boys girls
## 1 1629 5218  4683
## 2 1630 4858  4457
## 3 1631 4422  4102
## 4 1632 4994  4590
## 5 1633 5158  4839
## 6 1634 5035  4820

1)What command would you use to extract just the counts of girls baptized? Try it!

arbuthnot$girls
##  [1] 4683 4457 4102 4590 4839 4820 4928 4605 4457 4952 4784 5332 5200 4910
## [15] 4617 3997 3919 3395 3536 3181 2746 2722 2840 2908 2959 3179 3349 3382
## [29] 3289 3013 2781 3247 4107 4803 4881 5681 4858 4319 5322 5560 5829 5719
## [43] 6061 6120 5822 5738 5717 5847 6203 6033 6041 6299 6533 6744 7158 7127
## [57] 7246 7119 7214 7101 7167 7302 7392 7316 7483 6647 6713 7229 7767 7626
## [71] 7452 7061 7514 7656 7683 5738 7779 7417 7687 7623 7380 7288
  1. Is there an apparent trend in the number of girls baptized over the years?
    How would you describe it?
plot(x = arbuthnot$year, y = arbuthnot$girls, type = "l")

The number of girls baptized fluctuates over time. The minimum number of girls baptized occured rouhgly in 1650 and the maximum number of girls baptized occured roughly in 1705. The trend of baptizms sharply increases after 1660.

  1. Now, make a plot of the proportion of boys over time. What do you see? Tip: If you use the up and down arrow keys, you can scroll through your previous commands, your so-called command history. You can also access it by clicking on the history tab in the upper right panel. This will save you a lot of typing in the future.
plot(x = arbuthnot$year, y = arbuthnot$boys / (arbuthnot$boys + arbuthnot$girls), type = "l")

The minimum for the proporition of boys is found in 1703. The maximum for the proporition of boys is found in 1661.The proportion seems to decrease over time.

On Your own Section:

Read in the data

source("http://www.openintro.org/stat/data/present.R")
  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] 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953
## [15] 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967
## [29] 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981
## [43] 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995
## [57] 1996 1997 1998 1999 2000 2001 2002
dim(present)
## [1] 63  3
head(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
  1. How do these counts compare to Arbuthnot’s? Are they on a similar scale?

We can show this through a top level summary

summary(present$boys)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
## 1211684 1799857 1924868 1885600 2058524 2186274
summary(arbuthnot$boys)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##    2890    4759    6073    5907    7576    8426

The counts are very different. Lets try some more exploration

summary(present$girls)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
## 1148715 1711404 1831679 1793915 1965538 2082052
summary(arbuthnot$girls)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##    2722    4457    5718    5535    7150    7779

The counts are still showing a large numerical difference. The abornamlly large difference in metrics is a good indicator that they are not on a similar scale.

  1. 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.
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
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
(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
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")

Arbuthnot’s observation about boys being born in greater proportion does not hold up. We can see that the proportion of boys decreases over time.

4)In what year did we see the most total number of births in the U.S.? You can refer to the help files or the R reference card http://cran.r-project.org/doc/contrib/Short-refcard.pdf to find helpful commands.

present$year[(present$boys + present$girls) == max(present$boys + present$girls)]
## [1] 1961