MANOVA Test in R Programming

25 Aug, 2020
Multivariate analysis of variance (MANOVA) is simply an ANOVA (Analysis of variance) with several dependent variables. It is a continuation of the ANOVA. In an ANOVA, we test for statistical differences on one continuous dependent variable by an independent grouping variable. The MANOVA continues this analysis by taking multiple continuous dependent variables and bundles them collectively into a weighted linear composite variable. The MANOVA compares whether or not the newly created combination varies by the different levels, or groups, of the independent variable. One can perform this MANOVA test in R programming very easily.For example, let’s conduct an experiment where we give two treatments to two groups of rats, and we are taken the weight and height of rats. In that case, the weight and height of rats are two dependent variables, and the hypothesis is that both collectively are affected by the difference in treatment. A multivariate analysis of variance could be used to test this hypothesis.
If the global multivariate test is important then assume that the corresponding effect is important. In this case, the subsequent issue is to decide if the treatment affects only the heights, only the weight or both. In other words, we want to distinguish the particular dependent variables that contributed to the significant global effect. And to clarify this question, use one-way ANOVA to test separately each dependent variable.
MANOVA can be used in specific conditions:
The dependent variables should be normally distributed within groups.
Homogeneity of variances across the range of predictors.
Linearity between all pairs of covariates, all pairs of dependent variables, and all dependent variable-covariate pairs in every cell.
R provides a method manova() to perform the MANOVA test. The class “manova” differs from class “aov” in selecting a different summary method. The function manova() calls aov and then add class “manova” to the result object for each stratum. 
Syntax: manova(formula, data = NULL, projections = FALSE, qr = TRUE, contrasts = NULL, ...)
Parameters: formula: A formula specifying the model. data: A data frame in which the variables specified in the formula will be found. If missing, the variables are searched for in the standard way. projections: Logical flag qr: Logical flag contrasts: A list of contrasts to be used for some of the factors in the formula. ...: Arguments to be passed to lm, such as subset or na.action  
Example: To perform MANOVA test in R let’s take iris data set. 
R
# R program to illustrate# MANOVA test  # Import required librarylibrary(dplyr)  # Taking iris data setmyData = iris  # Show a random sampleset.seed(1234)dplyr::sample_n(myData, 10)
Output: 
 Sepal.Length Sepal.Width Petal.Length Petal.Width    Species
1           5.5         2.5          4.0         1.3 versicolor
2           5.6         2.5          3.9         1.1 versicolor
3           6.0         2.9          4.5         1.5 versicolor
4           6.4         3.2          5.3         2.3  virginica
5           4.3         3.0          1.1         0.1     setosa
6           7.2         3.2          6.0         1.8  virginica
7           5.9         3.0          4.2         1.5 versicolor
8           4.6         3.1          1.5         0.2     setosa
9           7.9         3.8          6.4         2.0  virginica
10          5.1         3.4          1.5         0.2     setosa


To know if there is any important difference, in sepal and petal length, between the different species then perform MANOVA test. Hence the function manova() can be used as follows.  
R
# Taking two dependent variablesepal = iris$Sepal.Lengthpetal = iris$Petal.Length  # MANOVA testresult = manova(cbind(Sepal.Length, Petal.Length) ~ Species,                                                 data = iris)summary(result)
Output: 
            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


From the output above, it can be seen that the two variables are highly significantly different among Species.
R-Statistics
R Language
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Change Color of Bars in Barchart using ggplot2 in R
How to Split Column Into Multiple Columns in R DataFrame?
Group by function in R using Dplyr
How to Change Axis Scales in R Plots?
R - if statement
Logistic Regression in R Programming
How to filter R DataFrame by values in a column?
Replace Specific Characters in String in R
How to import an Excel File into R ?
Joining of Dataframes in R Programming