Exercise 3.1

library(HistData)
library(magrittr)
library(plotly)
## Loading required package: ggplot2
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
library(vcd)
## Loading required package: grid
maxRatio=max(Arbuthnot$Ratio) 
minRatio=min(Arbuthnot$Ratio)
meanRatio=mean(Arbuthnot$Ratio)
plot_ly(Arbuthnot, x = ~Year, y = ~Ratio, name = 'Ratio: Newborn boys vs. Newborn girls',type = 'scatter', mode = 'lines',line = list(color = 'blue', width = 1.5))%>%
add_trace(y = ~maxRatio, name = 'Maximum', mode = 'lines',line = list(color = 'green', width = 2)) %>%
add_trace(y = ~minRatio, name = 'Minimum', mode = 'lines',line = list(color = 'red', width = 2)) %>%
add_trace(y = ~meanRatio, name = 'Mean', mode = 'lines',line = list(color = 'black', width = 2))

The ratio during the whole analysis period is above 1, with the mean is 1.07. It shows more boys were born between 1629 and 1710. The peak is 1653 and the lowest is 1703.

maximum=max(Arbuthnot$Total) 
minimum=min(Arbuthnot$Total)

plot_ly(Arbuthnot, x = ~Year, y = ~Total, name = 'Total Number of Christenings (in 000s))', type = 'scatter', mode = 'line',line = list(color = 'blue', width = 1.5)) %>%
add_trace(y = ~maximum, name = 'Max Christening', line = list(color = 'green', width = 2)) %>%
add_trace(y = ~minimum, name = 'Min Christening', line = list(color = 'red', width = 2)) %>%
layout(xaxis = list(title = "Year"), 
       yaxis = list (title = "Total Number of Christenings (in 000s)"))
## A line object has been specified, but lines is not in the mode
## Adding lines to the mode...
## A line object has been specified, but lines is not in the mode
## Adding lines to the mode...
## A line object has been specified, but lines is not in the mode
## Adding lines to the mode...

There is a big drop between 1648 and 1658, as well as 1704, which worth deeper research on it.

Exercise 3.3

Fit1= goodfit(WomenQueue, type = "binomial", par = list(size = 10))
plot(Fit1,type = "hanging")

Fit2= goodfit(WomenQueue, type = "binomial", par = list(prob = .5,size = 10))
plot(Fit2,type = "hanging", shade = TRUE)
## Warning in max.c * pmax(pmin(interpolate(abs(res)), 1), 0): longer object
## length is not a multiple of shorter object length

## Warning in max.c * pmax(pmin(interpolate(abs(res)), 1), 0): longer object
## length is not a multiple of shorter object length

distplot(WomenQueue, type = c("binomial"), conf_level = 0.95)
## Warning in distplot(WomenQueue, type = c("binomial"), conf_level = 0.95):
## size was not given, taken as maximum count

Fit3 = goodfit(Saxony, type = "binomial", par = list(prob = .5,size = 12))
Fit4 = goodfit(Saxony, type = "binomial", par = list(size = 12))
plot(Fit3, xlab="Number of Male Children", main = 'p = 0.5')

plot(Fit3, xlab="Number of Male Children", main = 'p = p')

Exercise 3.4

gfS1=goodfit(Saxony, type = "binomial", par = list(size = 12))
gfS=goodfit(Saxony, type = "binomial", par = list(prob = 0.5, size = 12))
plot(gfS1,main = "Families in Saxony" ,xlab= "Number of Males")

plot(gfS)