The `mle`

function from the `stats4`

package will be used for obtaining the MLE from popular distributions such as binomial, normal, and so on. The `fitdistr`

function will be used too, which fits the distributions using the MLEs.

- Load the library package CIT with
`library(stats4)`

. - Specify the number of success in a vector format and the number of observations
with

`x<-rep(c(0,1),c(3,7)); n <- length(x)`

. - Define the negative log-likelihood function with a function:
binomial_nll <- function(prob) -sum(dbinom(x,size=1,prob,log=TRUE))

The code works as follows. The

`dbinom`

function is invoked from the stats package and the option`log=TRUE`

is exercised to indicate that we need a log of the probability ...

Start Free Trial

No credit card required