Problem 8.6c

Author

Prof. Eric A. Suess

Problem 8.6c

library(fitdistrplus)
Loading required package: MASS
Loading required package: survival

The data

Simulate \(n\) Bernoulli random values with \(p = 0.45\). For the function fitdist() to work, we need to have more than one data value. So one Binomial value is \(n\) Bernoulli values.

n <- 1200
size <- 1
prob <- 0.45
x <- rbinom(n, size = size, prob = prob)
head(x)
[1] 0 1 1 1 1 0

plot the data

plotdist(x, discrete =  TRUE, demp = TRUE)

fit the data to a binomial distribution to the sample of \(n\) Bernoulli values.

fit.binom <- fitdist(data = x, dist = "binom",
                     method = "mle",
                     fix.arg = list(size = size),
                     start = list(prob=0.1))

summary(fit.binom)
Fitting of the distribution ' binom ' by maximum likelihood 
Parameters : 
      estimate Std. Error
prob 0.4441667 0.01434342
Fixed parameters:
     value
size     1
Loglikelihood:  -824.2793   AIC:  1650.559   BIC:  1655.649 
plot(fit.binom)

compare

denscomp(list(fit.binom), legendtext = c("binomial"))

plot the log-likelihood

llplot(fit.binom)