ANOVA (Stats)
We also studied this from a different angle in the Math Methods in Biology course: ANOVA (Maths)
Variance decomposition
- Last week, we compared two populations using a t-test. If we want to compare more than two populations, we can't use a t-test.
- One tool to do this is Analysis of Variance (ANOVA)
Law of Total Variance
Since this relation is only true if both come from the same population, we can determine how much the left side differs from the right side and this can tell us how likely it is that our two samples came from the same population.
Example
We will return from our example from last week (comparing whitefish populations in the Baltic Sea).
- Population 1: true mean
and =10, - Sample
- Sample
- Population 2: true mean
and , - Sample
In R, we can create a vector of observed observations and covariates just like we did last week (Comparing two populations through linear regression)
!lecture_notes_week2, p.2
- Sample
The following math term is a way of saying that the expectation of
Since for this example we are pretending we don't know what the true population means are, we can calculate the sample means from both groups and assign these to a vector of the same length:
mu = c() mu[X==0] = mean(Y[X==0]) # this is the same as mean(y)
mu[X==1] = mean(Y[X==1]) # this is the same as mean(z)
Components
Total variance
Since both samples are the same size (
Within Groups Variance
This is equal to the average of the variances within each group. So we add the variance from population 1 and population 2, then divide by two (the number of groups):
Now, doing some algebra, given the formulas for true variance from the maths class, we can simplify this to:
(remember that var(Y - mu). (where mu is our vector of sample means)
Between Groups Variance
The mean of the group means is
This can be simplified to:
And in R, simply var(mu-mean(Y))
Proportion of explained variance
Now that we have decomposed the variance into components, we can analyze the proportion of variance explained by the different groups:
Note that with some algebra you can show that this is actually the same as the multiple r-squared. We can show this in R by comparing doing this calculation manually with the R-squared value from a linear model.
F-statistic
F-statistic
Ok, this is how this ANOVA analysis works with two populations. But the point of this class was to examine more than two. We use the F-statistic to do this, using the Residual sum of squares.
The F-statistic is the quotient of the between groups variance with the within groups variance:
In statistical software, the F test used is a bit different and looks more like:
Where
This term with
is the d.f. between groups is the d.f. in the Residual sum of squares (within groups)