# Derivation in the MLE calculation [duplicate]

In the context of the likelihood ratio test, I was told to use the following formula (1):

$$\sum^n_{i=1}(X_i-\mu_0)^2=\sum^n_{i=1}(X_i-\bar{X})^2 + n(\bar{X}-{\mu}_0)^2 \qquad(1)$$

in order to derive the formula (2) as follows:

\begin{aligned} \log\Lambda & = -\frac{1}{2{\sigma}^2}\left(\sum^n_{i=1}(X_i-\mu_0)^2 - \sum^n_{i=1}(X_i-\bar{X})^2\right) & \quad &\\ & = -\frac{1}{2{\sigma}^2}n(\bar{X}-{\mu}_0)^2 & & (2) \end{aligned}

where $$X_i = \{X_1, \cdots , X_n\}$$ is independent and identically distributed and normally distributed with mean $$\mu$$ and standard deviation $$\sigma$$, $$\mu_0$$ is a certain number such that $$H_0: \mu = \mu_0$$, and $$\bar{X}$$ is the maximal likelihood estimate of $$\mu$$.

I understood how to apply (1) to (2). However, I'm not sure why the left side of (1) can be transformed as its right side. Then, how should I derive the formula (1)?

• This is a form of the Pythagorean theorem. Commented May 9, 2020 at 13:42
• @Xi'an Thank you for your comment. That's an identical question to mine! Commented May 10, 2020 at 3:24

Adding an auxilary $$\bar X$$ inside the expression: \begin{align}\sum^n_{i=1}(X_i-\mu_0)^2&=\sum_{i=1}^n (X_i-\bar{X}+\bar{X}-\mu_0)^2\\&=\sum_{i=1}^n (X_i-\bar{X})^2-2\sum_{i=1}^n(X_i-\bar{X})(\bar{X}-\mu_0)+\sum_{i=1}^n (\bar{X}-\mu_0)^2\\&=\sum_{i=1}^n (X_i-\bar{X})^2 + 2(\bar X - \mu_0)\overbrace{\sum_{i=1}^n (X_i-\bar{X})}^0 + n(\bar X-\mu_0)^2\\&=\sum_{i=1}^n(X_i-\bar{X})^2 + n(\bar X - \mu_0)^2\end{align}

Edit: I feel I need to further explain why $$\sum_{i=1}^n (X_i-\bar X)=0$$ in order to prevent further misunderstandings:

$$\sum_{i=1}^n(X_i-\bar X)=\sum_{i=1}^n X_i - \sum_{i=1}^n \bar X = n\bar X - n\bar X = 0$$

formula (1) can be derived as follow :

$$\begin{array}[cccc] \ \sum_{i = 1}^{n}(X_i - \mu_0)^2 & = & \sum_{i = 1}^{n}(X_i - \overline{X} + \overline{X} - \mu_0)^2 & (1)\\ & = & \sum_{i = 1}^{n}[(X_i - \overline{X})^2 + (\overline{X} - \mu_0)^2 + 2 (X_i - \overline{X})(\overline{X}-\mu_0)] & (2)\\ & = & \sum_{i = 0}^{n}(X_i - \overline{X})^2 + n(\overline{X} - \mu_0)^2 +2(\overline{X} - \mu_0)\sum_{i = 1}^{n}(X_i - \overline{X}) & (3)\\ &= &\sum_{i = 1}^{n}(X_i - \overline{X})^2 + n (\overline{X} - \mu_0)^2 & (4) \end{array}$$

To get from (1) to (2), just expand the expression inside the sum, from (2) to (3) distribute the sum, and take out of the sum all terms which don't depend on $$i$$, and to get from (3) to (4), you must notice that $$\sum_{i = 1}^{n}(X_i - \overline{X}) = 0$$ (expand it to prove it).

here is my derivation of formula (1):

$$$$\begin{split} \sum_{i=1}^{n}(X_i - \mu_0)^2 & = \sum_{i=1}^{n}(X_i^2-2 X_i \mu_0 + \mu_0^2) \\ & = \sum_{i=1}^{n}X_i^2 - 2 n \mu_0\frac{\sum_{i=1}^{n}X_i}{n} + n\mu_0^2 \\ & = \sum_{i=1}^{n}X_i^2 - 2 n \mu_0 \bar{X} + n \mu_0^2 \\ & = \sum_{i=1}^{n}X_i^2 - n \bar{X}^2 + n (\bar{X} - \mu_0)^2 \\ \end{split}$$$$

Now you can easly prove that $$\sum_{i=1}^{n}X_i^2 - n \bar{X}^2 = \sum_{i=1}^{n}(X_i - \bar{X})^2$$ as follow:

$$$$\begin{split} \sum_{i=1}^{n}(X_i - \bar{X})^2 & = \sum_{i=1}^{n}(X_i^2 - 2 \bar{X} X_i + \bar{X}^2) \\ & = \sum_{i=1}^{n}X_i^2 - 2 \bar{X} \sum_{i=1}^{n}X_i + n \bar{X}^2 \\ & = \sum_{i=1}^{n}X_i^2 - 2 n \bar{X}^2 + n \bar{X}^2 \\ & = \sum_{i=1}^{n}X_i^2 - n \bar{X}^2 \end{split}$$$$