O'Reilly logo

R Statistical Application Development by Example Beginner's Guide by Prabhanjan Narayanachar Tattar

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action – finding the MLE using mle and fitdistr functions

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.

  1. Load the library package CIT with library(stats4).
  2. 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).
  3. 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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required