# 最大似然估计法举例

$P(X=x)=(1-p)^{1-x}p^x, x=0,1$

\begin{align*}L(\theta)=\prod_{i=1}^{n}(1-p)^{1-x_i}p^{x_i}\\&=(1-p)^{1-x_1}p^{x_1}\cdot (1-p)^{1-x_2}p^{x_2}\cdots(1-p)^{1-x_n}p^{x_n}\\ &=(1-p)^{\sum_{i=1}^n(1-x_i)}\cdot p^{\sum_{i=1}^nx_i}\end{align*}

$\frac{d \ln L(\theta)}{d\theta}=-\frac{\sum_{i=1}^n(1-x_i)}{1-p}+\frac{\sum_{i=1}^nx_i}{p}$

\begin{array}{lll}\frac{d \ln L(\theta)}{d\theta}=0&\Rightarrow& \frac{\sum_{i=1}^n(1-x_i)}{1-p}=\frac{\sum_{i=1}^nx_i}{p}\\ &\Rightarrow& p\sum_{i=1}^n(1-x_i)=(1-p)\sum_{i=1}^nx_i\\ &\rightarrow& pn=\sum_{i=1}^nx_i\\ &\Rightarrow& \hat{p}=\frac{1}{n}\sum_{i=1}^nx_i=\bar{x}\end{array}

\begin{align*}L(\mu,\sigma^2)&=\prod_{i=1}^n\frac{1}{\sqrt{2\pi}\sigma}e^{-\frac{(x_i-\mu)^2}{2\sigma^2}}\\ &=(2\pi)^{-\frac{n}{2}}(\sigma^2)^{-\frac{n}{2}}e^{-\frac{1}{2\sigma^2}\sum_{i=1}^n(x_i-\mu)^2}\end{align*}

$\ln L(\mu,\sigma^2)=-\frac{n}{2}\ln(2\pi)-\frac{n}{2}\ln(\sigma^2)-\frac{1}{2\sigma^2}\sum_{i=1}^n(x_i-\mu)^2$

\begin{align*}\frac{\partial \ln L(\mu,\sigma^2)}{\partial\mu}&=-\frac{1}{2\sigma^2}\sum_{i=1}^n2(x_i-\mu)\cdot(-1)\\ &=\frac{1}{\sigma^2}\sum_{i=1}^n(x_i-\mu)=\frac{1}{\sigma^2}\sum_{i=1}^nx_i-n\mu\end{align*}

\begin{align*}\frac{\partial \ln L(\mu,\sigma^2)}{\partial \sigma^2}&=-\frac{n}{2}\cdot\frac{1}{\sigma^2}+\frac{1}{2}\cdot\frac{1}{(\sigma^2)^2}\sum_{i=1}^n(x_i-\mu)^2\end{align*}

\begin{cases}\frac{1}{\sigma^2}\sum_{i=1}^nx_i-n\mu=0\\ -\frac{n}{2}\cdot\frac{1}{\sigma^2}+\frac{1}{2}\cdot\frac{1}{(\sigma^2)^2}\sum_{i=1}^n(x_i-\mu)^2=0\end{cases}

$\hat{\sigma^2}=\frac{1}{n}\sum_{i=1}^n(x_i-\mu)^2$