The conventional answer would be:
macc <- melt(acc, id.var="Degrees")
lm(value ~ Degrees + variable, macc)
anova(lm(value ~ Degrees + variable, macc))
And all that remains is constructing a proper description of the results. (Notice that I used "+" instead of "*"). You get a nearly perfect answer when constructing a saturated model (one with no residuals) when using the interaction model:
anova(lm(value ~ Degrees * variable, macc))
You could have coded either or both of Degrees or MPH variables as numeric and gotten an unsaturated model.But it would still have added to the complexity of describing the result.
acc <- data.frame(Degrees = c(5,8,10), MPH10=c(0.35, 0.37, 0.32),
MPH25=c(0.19, 0.28, 0.30), MPH40=c(0.14, 0.19, 0.29), MPH55=c(0.10, 0.19, 0.23))
macc <- melt(acc, id.var="Degrees")
anova(lm(value ~ Degrees * variable, macc))
Using sub to remove the "MPH" from the character variables. I thought it would be necessary to use as.numeric(as.character())
on what I thought would be a factor variable, but the sub
operation apparently stripped the factor attribute and just using as.numeric
was sufficient.
macc$speed <- as.numeric(sub("MPH", "", macc$variable))
anova(lm(value ~ Degrees + speed, macc))
# output omitted
anova(lm(value ~ Degrees * speed, macc))
#-------------------
Analysis of Variance Table
Response: value
Df Sum Sq Mean Sq F value Pr(>F)
Degrees 1 0.016827 0.016827 16.904 0.003384 **
speed 1 0.048735 0.048735 48.959 0.000113 ***
Degrees:speed 1 0.006367 0.006367 6.396 0.035309 *
Residuals 8 0.007963 0.000995
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1