Binomial distribution

[Example] In \(n=10\) trials, observe \(x=2\) successes. What is the MLE for \(\pi\)?

# plot the likelhood function for demonstration
n = 10
p = seq(0,1,length.out=100)
L = dbinom(2,10,p)
L.c = 45*p^2*(1-p)^8
identical(L,L.c)
## [1] FALSE
# plot the likelhood function
plot(p,L)
lines(p[which.max(L)], L[which.max(L)],type="h",col="red")

p[which.max(L)]
## [1] 0.2020202

To solve MLE, we often work on log-likelihood function \(l(p) = log(L(p))\). For binomial distribution, \[l(p) = xlog(p) + (n-x) log(1-p).\] The first order derivative gives \[\frac{x}{p} - \frac{n-x}{1-p} = 0.\] Therefore, \(\hat{p} = x/n\).