we use the library vcd

library(vcd)
## Warning: package 'vcd' was built under R version 3.6.1
## Loading required package: grid

A set of three similar coins are tossed 100 times with the following results

number_of_heads <- c(0,1,2,3)
Frequency <- c(36,40,22,2)
df <- c(rep(0,36),rep(1,40),rep(2,22),rep(3,2))
df
##   [1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
##  [36] 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
##  [71] 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3
gf <- goodfit(df,type="binomial",method="MinChisq",par=list(size=3))
summary(gf)
## Warning in summary.goodfit(gf): Chi-squared approximation may be incorrect
## 
##   Goodness-of-fit test for binomial distribution
## 
##              X^2 df  P(> X^2)
## Pearson 1.152302  2 0.5620577

Here the p value is more than 0.05, so we reject the null hypothesis and say tha the observed distribution follows the expected distribution

Example 2
A set of 4 coins is tossed 64 times, The number of occurrence of heads is as follows. Fit the distribution to binomial number_of_heads <- c(0,1,2,3,4) Frequency <- c(3,15,23,17,6)

number_of_heads <- c(0,1,2,3,4)
Frequency <- c(3,15,23,17,6)
df <- c(rep(number_of_heads,Frequency))
df
##  [1] 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
## [36] 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4
gf <- goodfit(df,type="binomial",method="MinChisq",par=list(size=4))
summary(gf)
## Warning in summary.goodfit(gf): Chi-squared approximation may be incorrect
## 
##   Goodness-of-fit test for binomial distribution
## 
##               X^2 df  P(> X^2)
## Pearson 0.3148184  3 0.9572179

P is more than 0.05, hence the distribution follows binomial

plot(gf)

Fitting a Poisson Distribution

The following mistakes per page were observed in the book

No_of_Mistakes <- c(0,1,2,3,4)
No_of_pages <- c(211,90,19,5,0)
df <- c(rep(No_of_Mistakes,No_of_pages))
df
##   [1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
##  [36] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
##  [71] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [106] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [141] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [176] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [211] 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
## [246] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
## [281] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2
## [316] 2 2 2 2 2 3 3 3 3 3
gf <- goodfit(df,type="poisson",method="MinChisq")
summary(gf)
## Warning in summary.goodfit(gf): Chi-squared approximation may be incorrect
## 
##   Goodness-of-fit test for poisson distribution
## 
##               X^2 df  P(> X^2)
## Pearson 0.9573609  2 0.6196005
gf$par
## $lambda
## [1] 0.4451157