source("C:/Users/Georgia/Documents/Lab0/more/arbuthnot.R")
source("C:/Users/Georgia/Documents/Lab0/more/present.R")
library(ggplot2)

Exercise 1

What command would you use to extract just the counts of girls baptized?

names(arbuthnot)
## [1] "year"  "boys"  "girls"
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

Exercise 2

Is there an apparent trend in the number of girls baptized over the years? How would you describe it?

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

arbplot = data.frame(arbuthnot$year, arbuthnot$girls)
ggplot(arbplot, aes(arbuthnot$year,arbuthnot$girls)) + geom_point() + geom_smooth()
## `geom_smooth()` using method = 'loess'

I would describe it as polynomial. If, by chance the years between 1640 and 1660 were all a fluke, I might consider it being exponential after the year 1660, but I believe there are too many data points there to consider them outliers, so I believe that the trend is third degree polynomial.

Exercise 3

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

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

The graph looks like a time-series. Overall, though the proportion of boy that are baptised seem pretty steady (between 0.5 and 0.54).

ON YOUR OWN

  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?
("more/present.R")
## [1] "more/present.R"
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
names(present)
## [1] "year"  "boys"  "girls"
  1. How do these counts compare to Arbuthnot’s? Are they on a similar scale?
# Comparing years
range(present$year)
## [1] 1940 2002
range(arbuthnot$year)
## [1] 1629 1710
# Comparing dimensions
dim(present)
## [1] 63  3
dim(arbuthnot)
## [1] 82  3
# Comparing variables
names(present)
## [1] "year"  "boys"  "girls"
names(arbuthnot)
## [1] "year"  "boys"  "girls"

Only the variable names are on a similar scale. Both the dimensions and the years are not on the same scale. Present’s data is newer and smaller dimension-wise than Arbuthnot’s.

  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.? Plot included.
sex_prop = present$boys/present$girls
plot(present$year, sex_prop, type = "l")

Arbuthnot’s observation seems to hold for the mid 1940s, however even that proportion of (at its highest 1.058) isn’t particularly high and it overall decreases as the years pass.

  1. In what year did we see the most total number of births in the U.S.?
total = present$boys+ present$girls
new_pres = matrix(c(present$year,total), ncol = 2, byrow = F)
colnames(new_pres) = c("Year", "Births")
head(as.table(new_pres))
##      Year  Births
## A    1940 2360399
## B    1941 2513427
## C    1942 2808996
## D    1943 2936860
## E    1944 2794800
## F    1945 2735456
x = row(new_pres)[new_pres == max(new_pres)]
new_pres[x,]
##    Year  Births 
##    1961 4268326

Year 1961 where the total number of births was 4,268,326.