[1] "ozone" "garden"
2025-01-30
Plot the ozone data in the order it was measured
Calculate the residual of each point from the mean of y
Lets look at the data separated into its levels (garden)
The means are different but are they significantly different?
Calculate the residuals from the individual means
Calculate SSY \[ SSY = \Sigma(y-\bar{y})^2 \]
Calculate SSE \[ SSE = \Sigma_{j=1}^k\Sigma(y-\bar{y_j})^2 \]
So SSA = 44 - 24 = 20 (SSY = SSE + SSA)
Source | Sum of squares | Degrees of freedom | Mean squares | F |
---|---|---|---|---|
Garden | 20 | 1 | 20 | 15 |
Error | 24 | 18 | s^2 = 1.3333 | |
Total | 44 | 19 |
The p prefix, as in pf(), is how you calculate a p-value from a probability distribution
So the probability of obtaining data as extreme as ours (or more extreme) if the two means were really the same is about 0.1%
oneway <- read.csv("~/Dropbox/Teaching/old_teaching/zipped/oneway.csv") #Just getting the data in
model_ozone<-lm(oneway$ozone~oneway$garden) #Creates the linear model
ozone_anova<-aov(model_ozone) #Creates the anova from the linear model
summary(ozone_anova) #Outputs an ANOVA table
Df Sum Sq Mean Sq F value Pr(>F)
oneway$garden 1 20 20.000 15 0.00111 **
Residuals 18 24 1.333
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
The gardens differ in their ozone level (One-way ANOVA: \(F_{1,18}\) = 15.0, p = 0.0011). This is the correct way to report it
Diet type affects the weight of chickens (One-way ANOVA: \(F_{3,574}\) =10.81, p = \(6.433 \times 10^{-7}\))
Great, which diet is best? Eh ANOVA doesn’t tell you, it just says diet has an effect
Tukey multiple comparisons of means
95% family-wise confidence level
Fit: aov(formula = model_weight)
$Diet
diff lwr upr p adj
2-1 19.971212 -0.2998092 40.24223 0.0552271
3-1 40.304545 20.0335241 60.57557 0.0000025
4-1 32.617257 12.2353820 52.99913 0.0002501
3-2 20.333333 -2.7268370 43.39350 0.1058474
4-2 12.646045 -10.5116315 35.80372 0.4954239
4-3 -7.687288 -30.8449649 15.47039 0.8277810
Think of them like legit t-tests.
ANOVA