Exercise 3.3 Use the data set WomenQueue to:

  1. Produce analogous plots
library(vcd)
## Warning: package 'vcd' was built under R version 3.5.1
## Loading required package: grid
data("WomenQueue", package="vcd")
barplot(WomenQueue, xlab= "Number of Women in Queues of 10", ylab= "Frequency")

  1. Check for goodness-of-fit to the binomial distribution using the goodfit(). What do you think about these numbers?
library(vcd)
WomenQueue.fit <- goodfit(WomenQueue, type="binomial",  par = list(size = 10))
WomenQueue.fit
## 
## Observed and fitted values for binomial distribution
## with parameters estimated by `ML' 
## 
##  count observed     fitted pearson residual
##      0        1  0.3315007        1.1610708
##      1        3  2.5522622        0.2802600
##      2        4  8.8425721       -1.6284964
##      3       23 18.1546613        1.1371822
##      4       25 24.4605946        0.1090641
##      5       19 22.5989918       -0.7570705
##      6       18 14.4993531        0.9193354
##      7        5  6.3789822       -0.5459878
##      8        1  1.8417194       -0.6202341
##      9        1  0.3151024        1.2201121
##     10        0  0.0242601       -0.1557565
summary(WomenQueue.fit)
## 
##   Goodness-of-fit test for binomial distribution
## 
##                       X^2 df  P(> X^2)
## Likelihood Ratio 8.650999  8 0.3725869

The numbers show that there are deviations from the actual value.

  1. Draw the binomial distribution
library(vcd)
plot(WomenQueue.fit, type = "hanging")

Exercise 3.5 Mosteller and Wallace (1963) give the frequencies, nk, of counts k = 0, 1, . . . of other selected marker words in 247 blocks of text known to have been written by Alexander Hamilton.

  1. Create a one-way table of frequencies of counts or a matrix or data frame with frequencies in the first column and the corresponding counts in the second column, suitable for use with goodfit().
count <- 0:5
Freq <- c(129, 83, 20, 9, 5, 1)
x<-"count"
y<-"Freq"
newdata <-data.frame(count,Freq)
names(newdata) <- c(x,y)
newdata.tab <- xtabs(Freq ~ count, newdata)
head(newdata.tab)
## count
##   0   1   2   3   4   5 
## 129  83  20   9   5   1
  1. Fit and plot the Poisson model for these frequencies and plot the rootogram and fitted model.
Poissonmodel <- goodfit(newdata.tab, type = "poisson")
plot(Poissonmodel, type = "standing", xlab="Count", main = "Poisson Model")

plot(Poissonmodel, xlab="Count", main = "Rootogram of Poisson Model")

  1. Fit and plot the negative binomial model for these frequencies and plot the rootogram and fitted model.
negativebinomial <- goodfit(newdata.tab, type = "nbinomial")
plot(negativebinomial, type = "standing", xlab="Count", main = "Negative Binomial Model")

plot(negativebinomial, xlab="Count", main = "Rootogram of Negative Bimomial Model")

  1. What do you conclude?

There are deviations from the actual value and data seems to fit Poisson distribution better than Negative-Binomial Distribution.