likelihood function

We roll a 4-sided dice 290 times, and count 187 of 1, 35 of 2, 37 of 3, and 31 of 4.

Let’s assume each side should occur with probabilities (9/16) + p, (3/16) - p, (3/16) - p, and (1/16) + p, respectively, where the value of parameter p is what we try to infer.

Therefore, the likelihood function is: L(p) = (((9/16) + p)^187) * (((3/16) - p)^35) * (((3/16) - p)^37) * (((1/16) + p)^31) = (((9/16) + p)^187) * (((3/16) - p)^72) * (((1/16) + p)^31)

library(bbmle)
## Warning: package 'bbmle' was built under R version 3.3.3
## Loading required package: stats4
x <- seq(0.01,0.10,0.001)
y <- (((9/16)+x)^187) * (((3/16)-x)^72) * (((1/16)+x)^31)


plot(x,y,main ="Likelihood Function",xlab="Theta",ylab="Likelihood")

log likelihood function

z <- log(y)
plot(x,z,main ="Log Likelihood Function",xlab="Theta",ylab="Log Likelihood")

maximum likelihood estimate

We need to construct a negative log-likelihood function, as the mle2() R function (which we will use to calculate the maximum likelihood estimate, see below) requires a negative log-likelihood function as input, rather than a likelihood function.

The mles() with yield the parameter estimaion:

myfunc <- function(p)
{ 
  ifelse((0 <= p & p <= 0.1),-log((((9/16)+p)^187) * (((3/16)-p)^72) * (((1/16)+p)^31)),NA) 
}

mle2(myfunc, start=list(p=0.05))
## 
## Call:
## mle2(minuslogl = myfunc, start = list(p = 0.05))
## 
## Coefficients:
##          p 
## 0.05838241 
## 
## Log-likelihood: -302.01