# ML for Bernoulli trials

When reading up this page, I couldn't follow how the log of $$L(p;x)$$ for Bernoulli trials would be maximised at $$\hat{p}$$ = $$\sum_{i=1}^nx_i/n$$. Could you please explain the steps, particularly the differentiation of the log of $$L(p;x)$$, to arrive at that conclusion? Thanks in advance. The log-likelihood is $$f(p)=\log L(p;x) = \sum_{i=1}^n (x_i\log p + (1-x_i)\log (1-p))\\$$
When we differentiate wrt $$p$$, we have \begin{align}\frac{\partial \log L}{\partial p}&=\sum_{i=1}^n\left(\frac{x_i}{p} - \frac{1-x_i}{1-p}\right)=\sum_{i=1}^n\frac{(1-p)x_i-(1-x_i)p}{p(1-p)}=0\\&\rightarrow(1-p)\sum_{i=1}^n x_i-p\sum_{i=1}^n (1-x_i)=0\\&\rightarrow \sum_{i=1}^nx_n=np\rightarrow \hat p=\frac{1}{n}\sum_{i=1}^n x_i\end{align}
• Thank you for your succinct explanation. Just to be sure my understanding how you could derive the first expression in your answer, would you please confirm: log$L(p;x)$ = log$\prod_{i=1}^{n}p^x(1-p)^{1-x}$ = $\sum_{i=1}^{n}$log$p^x_i(1-p)^{1-x_i}$ = $\sum_{i=1}^{n}($log$p^x_i$ + log$(1-p)^{1-x_i})$?
• Correct (except $p_i$ which should be p, and $x$ which should be $x_i$) Aug 9 '20 at 6:13