Reputation: 2547
I tried using manova() and can not seem to get the correct programming in. I tried it this way (in a different post):
manova in R error message: length of 'dimnames' [1] not equal to array extent
the text question has to do with pedal rotation and initial speed being predictors of acceleration.
here is that data:
acc <- data.frame(Degrees = c("d5","d8","d10"), 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))
acc
acc
Degrees MPH10 MPH25 MPH40 MPH55
1 5 0.35 0.19 0.14 0.10
2 8 0.37 0.28 0.19 0.19
3 10 0.32 0.30 0.29 0.23
no idea what to do next.
Upvotes: 1
Views: 2412
Reputation: 263461
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
Upvotes: 2