Dulranga's Notes
Semester 3MathematicsApplied Statistics

ANOVA

ANalysis Of VAriance

What it does

This is used to explain if the Regression Line we got from doing a Linear Regression, actually does fit the data well, or is it just due to pure randomness.

If the line actually does fit well, by knowing the considered independent variable (wind speed in below graph) should be able to explain the dependent variable with some confidence level (like 95% confidently)

anova-variance-decomposition.png

yi−yˉ⏟total=y^i−yˉ⏟explained by the line+yi−y^i⏟left over (residual)\underbrace{y_i-\bar{y}}_{\text{total}}=\underbrace{\hat{y}_i-\bar{y}}_{\text{explained by the line}}+\underbrace{y_i-\hat{y}_i}_{\text{left over (residual)}}
  • total - This is the total deviation of the yiy_i from mean of y
  • explained by line - This part is explained entirely by the line got from regression. i.e. just by knowing the xix_i, we can get this part (y^i\hat y_i).
  • residual - Left over part that cannot be determined by the regression line. If the line is really a good fit, this part should be minimal as much as possible.

ANOVA Identity

ANOVA identity uses this relation with Sum of Squares. (just summing up cancel +/- errors otherwise)

∑(yi−yˉ)2⏟TSS, df=n−1=∑(y^i−yˉ)2⏟RSS, df=1+∑(yi−y^i)2⏟ESS, df=n−2\underbrace{\sum(y_i-\bar{y})^2}_{TSS,\ df=n-1}=\underbrace{\sum(\hat{y}_i-\bar{y})^2}_{RSS,\ df=1}+\underbrace{\sum(y_i-\hat{y}_i)^2}_{ESS,\ df=n-2}
  • TSS - Total Sum of Squares
  • RSS - Regression Sum of Squares
  • ESS - Error Sum of Squares
SourceSum of SquaresdfWhy this dfMean SS (SS/df)
Total (TSSTSS)
∑(yi−yˉ)2\sum(y_i-\bar{y})^2

| n−1n-1 | nn points minus yˉ\bar{y} | - | | Regression (RSSRSS) |

∑(y^i−yˉ)2\sum(\hat{y}_i-\bar{y})^2

| 11 | one slope. Line passes thru xˉ,yˉ\bar x, \bar y |

RSS1\frac{RSS}{1}

| | Error (ESSESS) |

∑(yi−y^i)2\sum(y_i-\hat{y}_i)^2

| n−2n-2 | nn points minus α^\hat{\alpha} and β^\hat{\beta} |

ESSn−2\frac{ESS}{n-2}

| A "mean square" is SS/dfSS/df, and the division is chosen so that it is an unbiased estimate of σ2\sigma^2:

ESSσ2∼χn−22andRSSσ2∼χ12\frac{ESS}{\sigma^2}\sim\chi^2_{n-2} \qquad and \qquad \frac{RSS}{\sigma^2}\sim\chi^2_{1}

From these two chi square distributions, we can get the following F distribution, which we can use to determine how good of a line we got from regression. i.e. How confidently we can estimate the value of yiy_i from xix_i

F=χ12/v1χ22/v2 ⇒ Fcal=(RSS/σ2)/1(ESS/σ2)/(n−2)=RSS/1ESS/(n−2)∼F1, n−2F=\frac{\chi^2_1/v_1}{\chi^2_2/v_2}\ \Rightarrow\ F_{cal}=\frac{(RSS/\sigma^2)/1}{(ESS/\sigma^2)/(n-2)}=\boxed{\frac{RSS/1}{ESS/(n-2)}\sim F_{1,\,n-2}}

How to find TSS, RSS, ESS

TSS=∑i=1n(yi−yˉ)2total variation of yRSS=∑i=1n(y^i−yˉ)2explained by the lineESS=∑i=1n(yi−y^i)2left over (residual)TSS=RSS+ESS\begin{align*} TSS&=\sum_{i=1}^{n}(y_i-\bar{y})^2 &&\text{total variation of } y\\ RSS&=\sum_{i=1}^{n}(\hat{y}_i-\bar{y})^2 &&\text{explained by the line}\\ ESS&=\sum_{i=1}^{n}(y_i-\hat{y}_i)^2 &&\text{left over (residual)} \end{align*} \\ \\ TSS=RSS+ESS

TSS

This one is pretty obvious from the data, since this is just the sum of squares of all yy values w.r.t. mean of yy

TSS=∑(yi−yˉ)2=SSyyTSS = \sum(y_i-\bar{y})^2 = SS_{yy}

To see how to calculate SSyySS_{yy} Linear Regression#Useful formulas

RSS

This can be calculated using the regression line slope β^\hat \beta. Regression Line goes thru (xˉ,yˉ)(\bar x, \bar y)

For any point xix_i we can get the y^i\hat y_i from regression equation. anova-rss-slope-geometry.png

β^=y^i−yˉ(xi−xˉ)\hat{\beta}=\frac{\hat{y}_i-\bar{y}}{(x_i-\bar{x})} RSS=β^2 SSxx=SSxy2SSxxRSS=\hat{\beta}^2\,SS_{xx} =\frac{SS_{xy}^2}{SS_{xx}}\\

ESS

This is the quantity we cannot determine using a formula. So we have to derive it by computing TSS and RSS

ESS=TSS−RSSESS = TSS - RSS

Coefficient of Determination (R2R^2)

R2R^2 is the fraction of the total variation in yy that the line explains

This number determines if the regression line is much more closer to data points. Higher the better. This tells as 98% of the yy variable is correctly explained by the regression r-squared-comparison.png

R2=RSSTSS=1−ESSTSS=SSxy2SSxx SSyyR^2=\frac{RSS}{TSS}=1-\frac{ESS}{TSS}=\frac{SS_{xy}^2}{SS_{xx}\,SS_{yy}}

0≤R2≤10 \leq R^2 \leq 1:

  • R2=0R^2=0 means the line explains nothing (flat line, β^=0\hat{\beta}=0).
  • R2=1R^2=1 means every point lies exactly on the line (ESS=0ESS=0).

Hypothesis testing with the FF ratio in ANOVA

Decision Rule

H0H_0​: regression line does not fit the data

H1H_1: regression line fits the data

For the null hypothesis, if the regression line does not fit the data that means,

β^=0\hat \beta = 0 Fcal=RSS/1ESS/(n−2)=explained variation per dfunexplained variation per df=signalnoise levelF_{cal}=\frac{RSS/1}{ESS/(n-2)}=\frac{\text{explained variation per df}}{\text{unexplained variation per df}}=\frac{\text{signal}}{\text{noise level}}
FcalF_{cal}Meaning
≈1\approx1the line explains about as much as pure noise would. No evidence of a real slope.
≫1\gg1the line explains far more than noise could. Strong evidence of a real slope.
near 00the line explains almost nothing, which is exactly what H0:β=0H_0:\beta=0 predicts.

anova-f-critical-region.png

So if the computed FF ratio fall within the rejection region, we can reject the null hypothesis.

The rejection region always goes to the right due to the FF ratio must be larger if alternative hypothesis is true, i.e. noise should be less compared to the actual data. But if the null hypothesis is true, regression line does not fit the data, then F ratio can be close to 11 or fall below 11

Our chosen significance level determines what is the minimum FF ratio we need to have in order to reject the null hypothesis.

Output|577

On this page