rstatisticsmanova

How to perform MANOVA test in R?


I am trying to find any interaction between independent variables in Group and 2 samples of dependent variables Level1 and Level2 in my data dataset (size reduced).

Group Level1 Level2
a     1      0
a     2      3
a     4      3
b     2      4
b     1      3
b     3      2
c     2      4
c     3      2
c     1      3

For this, I want to run a manova test. However when I am trying to run manova(data[,2:3] ~ as.factor(Group), data=data), I get invalid type (list) for variable 'data[,2:3]' error although data[,2:3] IS a list.

(Obviously this is my first time trying to use manova and basically R for this task and I have very basic knowledge of R so maybe I am completely wrong in what I am doing in general).


Solution

  • You need to run it like this using cbind:

    Data

    df <- read.table(header=T, text='Group Level1 Level2
    a     1      0
    a     2      3
    a     4      3
    b     2      4
    b     1      3
    b     3      2
    c     2      4
    c     3      2
    c     1      3')
    

    Solution:

    > manova( cbind(Level1,Level2) ~ Group, data=df)
    Call:
       manova(cbind(Level1, Level2) ~ Group, data = df)
    
    Terms:
                       Group Residuals
    resp 1          0.222222  8.666667
    resp 2                 2        10
    Deg. of Freedom        2         6
    
    Residual standard errors: 1.20185 1.290994
    Estimated effects may be unbalanced