1

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.

Community
  • 1
  • 1
tora0515
  • 2,479
  • 12
  • 33
  • 40
  • I do not think you are giving the entire setup for this obvious homework problem. It looks to me that both Degrees and the MPH columns are predictors. – IRTFM Dec 18 '11 at 02:23
  • Further hints: If you don't have replication, then don't use Manova. And you should probably be looking at what the reshape2 package can offer in the way of making a wide format dataset into a long format one. (You should edit your question rather than posting further ones.) – IRTFM Dec 18 '11 at 02:32
  • yeah, using an old intro to stats text for data to learn R. I have no idea about the programming in R, just trying to learn it. Yup, both are predictors and I want to run a two-factor anova on it. the text has a table set up just like the data.frame above, just don't know what to do in R, text uses minitab and excel... Thanks for the reshape2 package advice, I'll give it a look. – tora0515 Dec 18 '11 at 03:37
  • 1
    Try this after loading reshape2: `macc <- melt(acc, id.var="Degrees", value="accel")` ` – IRTFM Dec 18 '11 at 04:25
  • Thanks, I was still messing around with it. just managed to move the rows into columns and columns into rows..... I ran: anova(lm(value ~ degrees * variable, macc) – tora0515 Dec 18 '11 at 05:09
  • value="accel" not sure what this is. the documentation says: value.name.... name of variable used to store values. So, I typed in macc$accel and it returned NULL. what does 'value' do in this case then. – tora0515 Dec 18 '11 at 05:23
  • Your anova() call was the correct way to do it. My effort to use melt to rename the value column failed. – IRTFM Dec 18 '11 at 13:33

1 Answers1

2

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 
IRTFM
  • 258,963
  • 21
  • 364
  • 487
  • yeah, found my mistake. no replication use '+' with replication use '*'. So your original melt still worked. but thank you for the thorough answer. – tora0515 Dec 28 '11 at 06:38