source("http://www.openintro.org/stat/data/arbuthnot.R")

type arbuthnot

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
7  1635 5106  4928
8  1636 4917  4605
9  1637 4703  4457
10 1638 5359  4952
11 1639 5366  4784
12 1640 5518  5332
13 1641 5470  5200
14 1642 5460  4910
15 1643 4793  4617
16 1644 4107  3997
17 1645 4047  3919
18 1646 3768  3395
19 1647 3796  3536
20 1648 3363  3181
21 1649 3079  2746
22 1650 2890  2722
23 1651 3231  2840
24 1652 3220  2908
25 1653 3196  2959
26 1654 3441  3179
27 1655 3655  3349
28 1656 3668  3382
29 1657 3396  3289
30 1658 3157  3013
31 1659 3209  2781
32 1660 3724  3247
33 1661 4748  4107
34 1662 5216  4803
35 1663 5411  4881
36 1664 6041  5681
37 1665 5114  4858
38 1666 4678  4319
39 1667 5616  5322
40 1668 6073  5560
41 1669 6506  5829
42 1670 6278  5719
43 1671 6449  6061
44 1672 6443  6120
45 1673 6073  5822
46 1674 6113  5738
47 1675 6058  5717
48 1676 6552  5847
49 1677 6423  6203
50 1678 6568  6033
51 1679 6247  6041
52 1680 6548  6299
53 1681 6822  6533
54 1682 6909  6744
55 1683 7577  7158
56 1684 7575  7127
57 1685 7484  7246
58 1686 7575  7119
59 1687 7737  7214
60 1688 7487  7101
61 1689 7604  7167
62 1690 7909  7302
63 1691 7662  7392
64 1692 7602  7316
65 1693 7676  7483
66 1694 6985  6647
67 1695 7263  6713
68 1696 7632  7229
69 1697 8062  7767
70 1698 8426  7626
71 1699 7911  7452
72 1700 7578  7061
73 1701 8102  7514
74 1702 8031  7656
75 1703 7765  7683
76 1704 6113  5738
77 1705 8366  7779
78 1706 7952  7417
79 1707 8379  7687
80 1708 8239  7623
81 1709 7840  7380
82 1710 7640  7288
dim(arbuthnot)
[1] 82  3
names(arbuthnot)
[1] "year"  "boys"  "girls"
arbuthnot$boys
 [1] 5218 4858 4422 4994 5158 5035 5106 4917 4703 5359 5366 5518 5470 5460
[15] 4793 4107 4047 3768 3796 3363 3079 2890 3231 3220 3196 3441 3655 3668
[29] 3396 3157 3209 3724 4748 5216 5411 6041 5114 4678 5616 6073 6506 6278
[43] 6449 6443 6073 6113 6058 6552 6423 6568 6247 6548 6822 6909 7577 7575
[57] 7484 7575 7737 7487 7604 7909 7662 7602 7676 6985 7263 7632 8062 8426
[71] 7911 7578 8102 8031 7765 6113 8366 7952 8379 8239 7840 7640

Exercise 1 The number of girls baptised each year

plot(x=arbuthnot$year, y=arbuthnot$girls)

plot of chunk unnamed-chunk-4

or to connect them with a line we use the third “l” and other variables for fun, for instance:

plot(x=arbuthnot$year, y=arbuthnot$girls, type="l")

plot of chunk unnamed-chunk-5

plot(x=arbuthnot$year, y=arbuthnot$girls, type="c")

plot of chunk unnamed-chunk-5

plot(x=arbuthnot$year, y=arbuthnot$girls, type="b")

plot of chunk unnamed-chunk-5

Exercise 2 Is there an apparent trend in the number of girls baptized over the years? Yes, there is a definite increase in girls baptisms over this sample. Basic R calculator example:

5218+4683
[1] 9901

To see the total number of baptisms for boys and girls, R will compute all sums simultaneously

arbuthnot$boys+arbuthnot$girls
 [1]  9901  9315  8524  9584  9997  9855 10034  9522  9160 10311 10150
[12] 10850 10670 10370  9410  8104  7966  7163  7332  6544  5825  5612
[23]  6071  6128  6155  6620  7004  7050  6685  6170  5990  6971  8855
[34] 10019 10292 11722  9972  8997 10938 11633 12335 11997 12510 12563
[45] 11895 11851 11775 12399 12626 12601 12288 12847 13355 13653 14735
[56] 14702 14730 14694 14951 14588 14771 15211 15054 14918 15159 13632
[67] 13976 14861 15829 16052 15363 14639 15616 15687 15448 11851 16145
[78] 15369 16066 15862 15220 14928

To make a “l” plot of total Baptisms per year we can execute these commands: Also, as shown you do not have to specify the arguments that x is first and y is next as we did on last plot. It is assumed to come in this order.

plot(arbuthnot$year, arbuthnot$boys+arbuthnot$girls,type="l")

plot of chunk unnamed-chunk-8 We can compute the baptism ratio in 1629 by using the numbers and / like below:

5218/4683
## [1] 1.114

or we can type out or act on the vectors for each year to do the same task

arbuthnot$boys/arbuthnot$girls
 [1] 1.114 1.090 1.078 1.088 1.066 1.045 1.036 1.068 1.055 1.082 1.122
[12] 1.035 1.052 1.112 1.038 1.028 1.033 1.110 1.074 1.057 1.121 1.062
[23] 1.138 1.107 1.080 1.082 1.091 1.085 1.033 1.048 1.154 1.147 1.156
[34] 1.086 1.109 1.063 1.053 1.083 1.055 1.092 1.116 1.098 1.064 1.053
[45] 1.043 1.065 1.060 1.121 1.035 1.089 1.034 1.040 1.044 1.024 1.059
[56] 1.063 1.033 1.064 1.072 1.054 1.061 1.083 1.037 1.039 1.026 1.051
[67] 1.082 1.056 1.038 1.105 1.062 1.073 1.078 1.049 1.011 1.065 1.075
[78] 1.072 1.090 1.081 1.062 1.048

Here we compute the proprtion of newborns that are boys:

5218/(5218+4683)
## [1] 0.527

or for all years at the same time also:

arbuthnot$boys/(arbuthnot$boys+arbuthnot$girls)
 [1] 0.5270 0.5215 0.5188 0.5211 0.5160 0.5109 0.5089 0.5164 0.5134 0.5197
[11] 0.5287 0.5086 0.5127 0.5265 0.5094 0.5068 0.5080 0.5260 0.5177 0.5139
[21] 0.5286 0.5150 0.5322 0.5255 0.5193 0.5198 0.5218 0.5203 0.5080 0.5117
[31] 0.5357 0.5342 0.5362 0.5206 0.5257 0.5154 0.5128 0.5200 0.5134 0.5220
[41] 0.5274 0.5233 0.5155 0.5129 0.5106 0.5158 0.5145 0.5284 0.5087 0.5212
[51] 0.5084 0.5097 0.5108 0.5060 0.5142 0.5152 0.5081 0.5155 0.5175 0.5132
[61] 0.5148 0.5200 0.5090 0.5096 0.5064 0.5124 0.5197 0.5136 0.5093 0.5249
[71] 0.5149 0.5177 0.5188 0.5120 0.5027 0.5158 0.5182 0.5174 0.5215 0.5194
[81] 0.5151 0.5118

Exercise 3 Now, make a plot of the proportion of boys over time.

plot (arbuthnot$boys/(arbuthnot$boys+arbuthnot$girls),type="l")

plot of chunk unnamed-chunk-13 It looks like the proportion of boys over the same time period has declined a bit. Using R for comparisons like: <, >, = Do boys outnumber girls in each year?

arbuthnot$boys>arbuthnot$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 TRUE TRUE TRUE TRUE TRUE TRUE TRUE
[71] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE

HOW COOL!! It is showing logical data, TRUE or FALSE

X out and SAVE