# Compute the maximum likelihood estimator for $θ$.

Let $$X_1, X_2, . . . , X_n$$ be a random sample from a Bernoulli distribution with parameter $$θ$$. Compute the maximum likelihood estimator for $$θ$$.

In my opinion this is the correct way to solve it:
$$L(\Theta)=\theta_1*(1-\theta_1)*...\theta_n*(1-\theta_n)=\theta^n*(1-\theta)^n$$
$$l(\Theta)=n*ln(\theta)+n*ln(1-\theta)$$
$$l'(\theta)=\frac{n}{\theta}-\frac{n}{1-\theta}=0$$, $$\theta=\frac{1}{2}$$
For the official solution it should be $$\frac{\sum_{i=1}^nX_i}{n}$$, why MLE is incorrect, where should I put the $$x$$ that in my solution is not present?

• bernoulli has no pdf, calculating max with derivatives is here not possible – user620174 Jan 25 '19 at 14:52
• Your likelihood formula is wrong - your formula doesn't depend on the data that you see, only $n$. When you use the correct formula you can differentiate the log likelihood to get the MLE. – Alex Jan 25 '19 at 15:28
• @Alex what do you mean? – Luke Marci Jan 25 '19 at 15:31
• The likelihood should depend on the data you see. E.g. suppose you just had $n = 1$ and observed $X_1 = x_1$. If that was a success ($x_1 = 1$) then the likelihood would be $\theta$, and if it was a failure ($x_1 = 0$) then the likelihood would be $(1 - \theta)$. In the first case the MLE would be $\hat{\theta} = 1$ and in the second case the MLE would be $\hat{\theta} = 0$. – Alex Jan 25 '19 at 15:36

The likelihood function for Bernoulli can be written as follows: $$L(\theta)=\begin{cases}\theta, & X_1=1\cr 1-\theta, & X_1=0\end{cases}\times \begin{cases}\theta, & X_2=1\cr 1-\theta, & X_2=0\end{cases}\times \cdots\times\begin{cases}\theta, & X_n=1\cr 1-\theta, & X_n=0\end{cases}$$ Note that $$\sum_{i=1}^n X_i=n\overline X$$ calculates the number of units in a sample, and $$n-n\overline X$$ calculates the number of zeros. In the above product, $$\theta$$ is multiplied as many times as there are units in the sample. And $$1-\theta$$ is multiplied as many times as there are zeros in the sample. So $$L(\theta) = \theta^{n\overline X}\cdot (1-\theta)^{n-n\overline X}.$$ Starting from here you can calculate MLE with derivatives.