The RMarkdown file for this lesson can be found here.
This lesson will follow Chapter 8 in Quinn and Keough (2002).
Load the packages we will be using in this lesson
Comparing groups or treatments
- Analysis of variance (ANOVA) is a statistical technique to partition and analyze the variation of a continuous response variable
- Previously we used ANOVA to partition the variation in a response variable into that explained by the linear regression with one or more continuous predictor variables and that unexplained by the regression model
- The statistical distinction between “classical regression” and “classical ANOVA” is artificial, which is why we can use the
lm()
withanova()
or theaov
function in R - Two prime reasons to use classical ANOVA:
- examine the relative contribution of sources of variation to the total amount of the variability in the response variable
- test the null hypothesis (H0) that population group or treatment means are equal
Single factor
- A single factor or one way design = single factor or predictor
- factor can comprise several levels
- completely randomized (CR) designs (no restriction on the random allocation of experimental or sampling units to factor levels)
Types of predictors
- Two types of factors
- Fixed - all the levels of the factor that are of interest are included in the analysis
- cannot extrapolate beyond these levels, repeat experiment keep same levels
- called: fixed effect models or Model 1 ANOVAs
- conclusions for a fixed factor are restricted to those specific groups we used in the experiment or sampling program
- Random - we are only using a random selection of all the possible levels of the factor
- usually make inferences about all the possible groups from our sample of groups
- called: random effect models or Model 2 ANOVAs
- analogous to Model 2 regression
- draw conclusions about the population of groups from which we have randomly chosen a subset (like site or time)
- Fixed - all the levels of the factor that are of interest are included in the analysis
Lets begin exploring this in R, using the medley
data
This data includes:
- STREAM - name of streams in the Rocky Mountain region of Colorado, USA
- ZINC - categorical zinc concentration level (HIGH=high, MED=medium, LOW=low, BACK=background)
- DIVERSTY - Shannon-Wiener species diversity of diatoms
- ZNGROUP - alternative categorical zinc concentration level (1=background, 2=low, 3=medium, 4=high)
ANOVA - Fixed effects
Remember we can partition the total sum of squares \( SS_{T} \) can be partitioned into two components
-
ZINC
represents variation due to the difference between group means - calculated as \( \bar{y_i} \) - \( \bar{y} \); df is the number of groups minus 1 Residuals
difference between the observations within each group- calculated as \( y_{ij} \) - \( \bar{y_i} \); df is sum of the sample sizes minus the number of groups
- The mean squares from the ANOVA are sample variances
- \( MS_{residuals} \) estimates \( \alpha_{\epsilon}^2 \) , the pooled population variance of the error terms within groups. (Assumes homogeneity of error variances)
- \( MS_{groups} \) estimates the pooled variance of the error terms across groups plus: - a component representing the squared effects of the chosen groups if the factor is fixed - the variance between all possible groups if the factor is random
Null hypothesis
- Fixed effects: the null hypothesis tested in a single factor ANOVA is usually one of no difference between group means or no effect of treatments
- Random effects: the null hypothesis is that the variance between all possible groups equals zero
If the H0 for a fixed factor is true, all \( \alpha_i \) equal zero (no group effects) and both \( MS_{groups} \) and \( MS_{residual} \) estimate \( \alpha_{\epsilon}^2 \) and their ratio should be one. The ratio of two variances (or mean squares) is called an F-ratio.
-
If the H0 is false, then at least one \( \alpha_i \) will be different from zero. Therefore, \( MS_{groups} \) has a larger expected value than \( MS_{residual} \) and their F-ratio will be greater than one.
-
A central F distribution is a probability distribution of the F-ratio when the two sample variances come from populations with the same expected values. There are different central F distributions depending on the df of the two sample variances
We can explore this using the df and F-value to show the probability calculation. df = 3, 30 and F-value = 3.9387
- Construction of the tests of null hypotheses is identical for fixed and random factors in the single factor ANOVA model but these null hypotheses have very different interpretations - The H0 for the fixed factor refers only to the groups used in the study whereas the H0 for the random factor refers to all the possible groups that could have been used - The assumption of equal within group variances is so important. For example, if \( \alpha_{i1} \) does not equal \( \alpha_{i2} \), then \( MS_{residual} \) does not estimate a single population variance , and we cannot construct a reliable F-ratio for testing the H0 of no group effects
Unbalanced designs
- Unequal sample sizes among groups can cause some problems: 1. Different group means will be estimated with different levels of precision, which can make interpretation difficult 2. ANOVA F test is more sensitive to violations of assumptions (i.e., homogeneity of variances) if sample sizes differ 3. Estimation of group effects is more difficult 4. Power calculations for random effects models are difficult
So what do you do if you have an unbalanced design?
- Delete observations to make it balanced
- Substitute group means to make balanced
- If differences in sample size and homogeneity of variances does not seem violated, fit linear ANOVA
- Prevent unbalanced designs in the experimental design
Factor effects
- In regression, with a continuous predictor, the coefficient value in the models is an assessment of the effect size of X on Y
- When your predictor is categorical how do we measure effect size? - One measure of group effects is the variance associated with the groups over and above the residual variance (similar to \( R^2 \))
What can be some of the issues with this measure?
Random effects: variance components
- There are two variance components of interest
- true variance between replicate observations within each group, averaged across groups is estimated by \( MS_{residual} \) or \( \sigma_{\epsilon}^2 \)
- true variance between the means of all the possible groups we could have used in our study is is termed the added variance component due to groups \( \sigma_{a}^2 \)
Explore this lets make a balanced dataset
Fixed effects: variance components
- More problematic than in the random effect models - Several have criticized measures of variance explained for fixed factors. They argued that the population “variance” of a set of fixed groups makes no sense and this measure cannot be compared to the average population variance between observations within groups, which is a true variance
- Two approaches have been developed omega squared ( \( \omega^2 \); variance of the group means) and Cohen’s effect size (f; difference among means measured in units of the standard deviation between replicates within group)
- Cohen suggests that f values of 0.1, 0.25, and 0.4 represent small, medium, and large effect sizes respectively
Let’s go back to the medley
dataset to explore these