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")
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.
library(vcd)
plot(WomenQueue.fit, type = "hanging")
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
Poissonmodel <- goodfit(newdata.tab, type = "poisson")
plot(Poissonmodel, type = "standing", xlab="Count", main = "Poisson Model")
plot(Poissonmodel, xlab="Count", main = "Rootogram of Poisson 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")
There are deviations from the actual value and data seems to fit Poisson distribution better than Negative-Binomial Distribution.