library(fitdistrplus)
Loading required package: MASS
Loading required package: survival
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.
<- 1200
n <- 1
size <- 0.45
prob <- rbinom(n, size = size, prob = prob)
x 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.
<- fitdist(data = x, dist = "binom",
fit.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)