Show that $$ \sum\left(Y_{i}-\mu\right)^{2} / \sigma^{2}=(n-1) S^{2} / \sigma^{2}+\left[(\bar{Y}-\mu)^{2} n / \sigma^{2}\right] $$
can be changed into a form $$ \frac{1}{\sigma^{2}} \widehat{S}_{1}=\frac{1}{\sigma^{2}} \sum_{j=1}^{2} \sum_{k=1}^{20}\left(Y_{j k}-\mu_{j}\right)^{2}-\frac{20}{\sigma^{2}} \sum_{k=1}^{20}\left(\bar{Y}_{j}-\mu_{j}\right)^{2} $$ and deduce that $$ \frac{1}{\sigma^{2}} \widehat{S}_{1} \sim \chi^{2}(38) $$ Similarly show that $$ \frac{1}{\sigma^{2}} \widehat{S}_{0}=\frac{1}{\sigma^{2}} \sum_{j=1}^{2} \sum_{k=1}^{20}\left(Y_{j k}-\mu\right)^{2}-\frac{40}{\sigma^{2}} \sum_{j=1}^{2}(\bar{Y}-\mu)^{2} $$ and if $\mathrm{H}_{0}$ is true then $$ \frac{1}{\sigma^{2}} \widehat{S}_{0} \sim \chi^{2}(39) $$
Provided that $$ \begin{array}{l} \hat{S}_{0}=\sum \sum\left(Y_{j k}-\bar{Y}\right)^{2}, \text { where } \bar{Y}=\sum_{j=1}^{2} \sum_{k=1}^{K} Y_{j k} / 40 \\ \hat{S}_{1}=\sum \sum\left(Y_{j k}-\bar{Y}_{j}\right)^{2}, \text { where } \bar{Y}_{j}=\sum_{k=1}^{K} Y_{j k} / 20 \end{array} $$ for $j=1,2$
Intuitively I can explain why $\hat{S_0}/\sigma^2$ would look the way it is as we can simply consider $$ \sum\left(Y_{i}-\mu\right)^{2} / \sigma^{2}=(n-1) S^{2} / \sigma^{2}+\left[(\bar{Y}-\mu)^{2} n / \sigma^{2}\right] $$ is the expression for one gender, group, so for this to be true for both gender group, we have to sum across two genders. However, I am unable to show why $ \hat{S}_1$ looks the way it is. Also, Suppose the expression is true, why Chi-square distribution is with a degree of freedom 38 and 39?