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.
x<-rep(c(0,1),c(3,7)); n <- length(x).
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 ...