Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

The post How to perform the MANOVA test in R? appeared first on

How to perform the MANOVA test in R?. when there are several response variables, a multivariate analysis of variance can be used to examine them all at once (MANOVA).

For example, we might run an experiment in which we give two groups of mice two treatments (A and B) and measure their weight and height.

The weight and height of mice are two dependent variables in this example, and our hypothesis is that the difference in treatment affects both.

## Assumptions

This hypothesis could be tested using a multivariate analysis of variance.

MANOVA assumptions MANOVA can be applied in the following situations:

Within groups, the dependent variables should be distributed regularly. The Shapiro-Wilk test for multivariate normality can be performed with the R function mshapiro.test() [from the mvnormtest package].

This is especially important when using MANOVA, which implies multivariate normality.

Variance homogeneity across a wide variety of predictors.

All dependent variable pairings, all covariate pairs, and all dependent variable-covariate pairs in each cell are linear.

## MANOVA interpretation

We conclude that the associated impact (treatment) is significant if the global multivariate test is significant.

The next step is to figure out whether the treatment impacts only the weight, only the height, or both. To put it another way, we want to figure out which dependent variables led to the substantial global effect.

We can evaluate each dependent variable separately using one-way ANOVA (or univariate ANOVA) to address this question.

### Compute MANOVA in R

`data <- iris`

Using the sample n() function in the dplyr package, the R code below displays a random sample of our data.

Install dplyr first if you don’t already have it.

How to perform One-Sample Wilcoxon Signed Rank Test in R?

```install.packages("dplyr")
set.seed(123)
dplyr::sample_n(data, 10)
Sepal.Length Sepal.Width Petal.Length Petal.Width    Species
1           4.3         3.0          1.1         0.1     setosa
2           5.0         3.3          1.4         0.2     setosa
3           7.7         3.8          6.7         2.2  virginica
4           4.4         3.2          1.3         0.2     setosa
5           5.9         3.0          5.1         1.8  virginica
6           6.5         3.0          5.2         2.0  virginica
7           5.5         2.5          4.0         1.3 versicolor
8           5.5         2.6          4.4         1.2 versicolor
9           5.8         2.7          5.1         1.9  virginica
10          6.1         3.0          4.6         1.4 versicolor```

Question: We’re curious if there’s a major difference in sepal and petal length across the various species.

#### Calculate the MANOVA test

The manova() function can be used as follows:

```sepl <- iris\$Sepal.Length
petl <- iris\$Petal.Length```

MANOVA test

```res.man <- manova(cbind(Sepal.Length, Petal.Length) ~ Species, data = iris)
summary(res.man)
Df Pillai approx F num Df den Df    Pr(>F)
Species     2 0.9885   71.829      4    294 < 2.2e-16 ***
Residuals 147
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1```

Look for the differences.

```summary.aov(res.man)
Response Sepal.Length :
Df Sum Sq Mean Sq F value    Pr(>F)
Species       2 63.212  31.606  119.26 < 2.2e-16 ***
Residuals   147 38.956   0.265
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Response Petal.Length :
Df Sum Sq Mean Sq F value    Pr(>F)
Species       2 437.10 218.551  1180.2 < 2.2e-16 ***

Residuals   147  27.22   0.185
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1```

## Conclusion

The two variables are extremely significantly different among Species, as shown in the result above.

The post How to perform the MANOVA test in R? appeared first on