lab 0

source("more/arbuthnot.R")

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

#Number of girls baptized each year
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
#Total accumulated number of girls baptized over the years
sum(arbuthnot$girls)
## [1] 453841

2. 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")

I would describe there is overall trend in the number baptized girls. From 1640 to 1660, the number of baptized girls shows downward slope with significant drop. After 1660, it shows upward sloping with general increase with a few steep drops.

3. Now, make a plot of the proportion of boys over time. What do you see?

boys.prop <- arbuthnot$boys/(arbuthnot$girls+arbuthnot$boys)
plot(x = arbuthnot$year, y = boys.prop, ylim=c(0.50, 0.55),
     type = "l", xlab = "year", ylab = "baptized proportion of boys")
abline(lm(boys.prop ~ arbuthnot$year))

The graph above shows that the proportion of baptized boys generally decreases over time, however, the number of baptized boys are larger than the number of baptized girls as it is still above 0.50.

On Your Own

source("more/present.R")
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?

table(present$year)
## 
## 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 
##    1    1    1    1    1    1    1    1    1    1    1    1    1    1    1 
## 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 
##    1    1    1    1    1    1    1    1    1    1    1    1    1    1    1 
## 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 
##    1    1    1    1    1    1    1    1    1    1    1    1    1    1    1 
## 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 
##    1    1    1    1    1    1    1    1    1    1    1    1    1    1    1 
## 2000 2001 2002 
##    1    1    1
min(present$year)
## [1] 1940
max(present$year)
## [1] 2002
# The dataset is from year 1940 ~ 2002
dim(present)
## [1] 63  3
# The dimensions of the dataset is 63 rows X 3 columns

str(present)
## 'data.frame':    63 obs. of  3 variables:
##  $ year : num  1940 1941 1942 1943 1944 ...
##  $ boys : num  1211684 1289734 1444365 1508959 1435301 ...
##  $ girls: num  1148715 1223693 1364631 1427901 1359499 ...
# the column names as follows: year, boys, girls

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

arbutnot.mean <- mean(arbuthnot$boys + arbuthnot$girls)
present.mean <- mean(present$boys + present$girls)
present.mean/arbutnot.mean
## [1] 321.5869

This can be compared by looking at the mean of total number of arbutnot and present data. The difference shows that the counts are not at all on a similar scale.

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.

present.boy.prop <- present$boys / (present$boys + present$girls)
plot(present$year, present.boy.prop, type = "l", ylim=c(0.50, 0.52), xlab = "year", ylab = "proportion of boys")
abline(lm(present.boy.prop ~ present$year))

As it shows, the proportion of boys to girls population is bigger than 0.5 which means that Arbuthnot’s observation is valid in the U.S.

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$total <- present$boys + present$girls
plot(present$year, present$total, type = "b", xlab = "year", ylab = "total number of birth")

The graph displays that the most total number of birth peaked around 1960.

To find the precise year, we can find maximum number from total column that matches to the year as follows. It is 1961 that showed the most number of birth in the U.S.

present$year[present$total == max(present$total)]
## [1] 1961