How to prepare data in R for manova
题
The data in a text looks like this:
Initial Speed
Pedal Rotation 10 mph 25 mph 40 mph 55 mph
5 degrees 0.35 0.19 0.14 0.10
8 degrees 0.37 0.28 0.19 0.19
10 degrees 0.42 0.30 0.29 0.23
The numbers in the table represent acceleration.
I would like to know how to get this information ready to run a manova test in R.
I have created variables from the columns and rows:
mph10 <- c(0.35, 0.37, 0.42)
mph25 <- c(0.19, 0.28, 0.30)
mph40 <- c(0.14, 0.19, 0.29)
mph55 <- c(0.10, 0.19, 0.23)
and
d5 <- c(0.35, 0.19, 0.14, 0.10)
d8 <- c(0.37, 0.28, 0.19, 0.23)
d10 <- c(0.42, 0.30, 0.29, 0.23)
I have found some tutorials on Youtube that show how to do manova, they all use .csv files and jump right into using manova without explaining how the data is arranged in the files or how to make your own.
So, I have no idea what to do next....
解决方案
You should convert your data to a data frame prior to analysis, your code above only creates unlinked columns. Suggested code (probably more efficient way to do it, this works):
degrees <- 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))
Test of data:
degrees
Degrees MPH10 MPH25 MPH40 MPH55
1 d5 0.35 0.19 0.14 0.10
2 d8 0.37 0.28 0.19 0.19
3 d10 0.32 0.30 0.29 0.23
You should now be able to analyse degrees in manova.
When you did your c(...)
for your MPH variables, you set these up as observations, not variables. If you want to input columns rather than rows, the rbind()
command is used.
So the command mph10 <- c(0.35, 0.37, 0.42)
will give the following output to mph10
:
[1] 0.35 0.37 0.42
whereas mph10 <- rbind(0.35, 0.37, 0.42)
gives
[,1]
[1,] 0.35
[2,] 0.37
[3,] 0.42
HTH.
其他提示
Generally you want the data setup with the multivariate responses each in their own column and your predictor variables each in their own column. It seems to me (not sure what you measured) that your text file is already setup fine... but I'd take out the word "degrees" repeated in the first column.
I checked youtube (manova in r), and if you use the skull example (second thing that came up in what I found) and realize that everything in the cbind
portion of the manova
command is just separate columns of the data.frame being grouped together as the multivariate response variables, you should be fine.