# stats

Multivariate analysis of variance (MANOVA) table

Since R2023b

## Syntax

``s = stats(maov)``
``s = stats(maov,TestStatistic=testStat)``
``[s,H,E] = stats(___)``

## Description

example

````s = stats(maov)` returns a MANOVA table for the `manova` object `maov`. The MANOVA table contains statistics for the model terms, error, and total. ```
````s = stats(maov,TestStatistic=testStat)` specifies the test statistics to display in the MANOVA table.```

example

````[s,H,E] = stats(___)` also returns a table `H` of the hypothesis matrices for the MANOVA model terms, and the error matrix `E` used to perform the MANOVA, using any of the input argument combinations in the previous syntaxes.```

## Examples

collapse all

Load the `fisheriris` data set.

`load fisheriris`

The column vector `species` contains iris flowers of three different species: setosa, versicolor, and virginica. The matrix `meas` contains four types of measurements for the flower: the length and width of sepals and petals in centimeters.

Perform a one-way MANOVA with `species` as the factor and the measurements in `meas` as the response variables.

`maov = manova(species,meas);`

`maov` is a `manova` object that contains the results of the one-way MANOVA. Display the corresponding MANOVA table.

`s = stats(maov)`
```s=3×8 table Source DF TestStatistic Value F DFNumerator DFDenominator pValue _______ ___ _____________ ______ ______ ___________ _____________ __________ Factor1 2 pillai 1.1919 53.466 8 290 9.7422e-53 Error 147 Total 149 ```

The small p-value for `species` indicates that the flower species has a statistically significant effect on at least one of the flower measurements.

Load the `carsmall` data set.

`load carsmall`

The variable `Model_Year` contains data for the year a car was manufactured, and the variable `Cylinders` contains data for the number of engine cylinders in the car. The `Acceleration`, `Displacement`, and `Weight` variables contain data for car acceleration, displacement, and weight.

Use the `table` function to create a table from the data in `Model_Year`, `Cylinders`, `Acceleration`, `Displacement`, and `Weight`.

`tbl = table(Model_Year,Cylinders,Acceleration,Displacement,Weight,VariableNames=["Year" "Cylinders" "Acceleration" "Displacement" "Weight"]);`

Perform a two-way MANOVA using the table variables `Year` and `Cylinders` as factors, and the `Acceleration`, `Displacement`, and `Weight` variables as response variables.

`maov = manova(tbl,"Acceleration,Displacement,Weight ~ Cylinders + Year")`
```maov = 2-way manova Acceleration,Displacement,Weight ~ 1 + Year + Cylinders Source DF TestStatistic Value F DFNumerator DFDenominator pValue _________ __ _____________ _______ ______ ___________ _____________ _________ Year 2 pillai 0.11134 1.8471 6 188 0.092099 Cylinders 2 pillai 0.96154 29.012 6 188 1.891e-24 Error 95 Total 99 Properties, Methods ```

`maov` is a two-way `manova` object that contains the results of the two-way MANOVA. The small p-value for `Cylinders` indicates that enough evidence exists to conclude that `Cylinders` has a statistically significant effect on the mean response vector.

Return the hypothesis and error matrices for the MANOVA model terms.

`[~,H,E] = stats(maov)`
```H=3×2 table Year Cylinders ___________________________________ __________________________________ 33.703 -327.34 3443.7 278.01 -13017 -90619 -327.34 4835.3 -30382 -13017 7.1228e+05 4.9601e+06 3443.7 -30382 3.5753e+05 -90619 4.9601e+06 3.4541e+07 ```
```E = 3×3 107 × 0.0001 -0.0002 0.0021 -0.0002 0.0109 0.0451 0.0021 0.0451 1.3656 ```

The variables in the table `H` correspond to the MANOVA model terms of the same name. Each variable contains the hypothesis matrix for its corresponding MANOVA model term. The error matrix `E` contains the irreducible error for the MANOVA model. You can use `H` and `E` to perform hypothesis tests that are not supported by MATLAB® or Statistics and Machine Learning Toolbox™.

## Input Arguments

collapse all

MANOVA results, specified as a `manova` object. The properties of `maov` contain the response data and factor values used by `stats` to calculate the statistics in the MANOVA table.

MANOVA test statistics, specified as `maov.TestStatistic`, `"all"`, or one or more of the following values.

ValueTest NameEquation
`"pillai"` (default)Pillai's trace
`$V=trace\left({Q}_{h}{\left({Q}_{h}+{Q}_{e}\right)}^{-1}\right)=\sum {\theta }_{i},$`

where θi values are the solutions of the characteristic equation Qhθ(Qh + Qe) = 0. Qh and Qe are, respectively, the hypotheses and the residual sum of squares product matrices.

`"hotelling"`Hotelling-Lawley trace
`$U=trace\left({Q}_{h}{Q}_{e}^{-1}\right)=\sum {\lambda }_{i},$`

where λi are the solutions of the characteristic equation |QhλQe| = 0.

`"wilks"`Wilk's lambda
`$\Lambda =\frac{|{Q}_{e}|}{|{Q}_{h}+{Q}_{e}|}=\prod \frac{1}{1+{\lambda }_{i}}.$`
`"roy"`Roy's maximum root statistic
`$\Theta =\mathrm{max}\left(eig\left({Q}_{h}{Q}_{e}^{-1}\right)\right).$`

If you specify `testStat` as `"all"`, `stats` calculates all the test statistics in the table above.

Example: `TestStatistic="hotelling"`

Data Types: `char` | `string` | `cell`

## Output Arguments

collapse all

MANOVA table, returned as a table. In addition to rows for the error and total, `s` contains t rows per model term, where t is the number of test statistics in `maov.TestStatistic`. The table `s` also has the following columns:

• `Source` — MANOVA model term

• `DF` — Degrees of freedom for the term in `Source`

• `TestStatistic` — Name of the test statistic used to calculate the F-statistic in the column `F` and the p-value in the column `pValue`

• `Value` — Value of the test statistic named in `TestStatistic`

• `F` — Value of the F-statistic corresponding to the test statistic named in `TestStatistic`

• `DFNumerator` — Degrees of freedom for the numerator of the F-statistic

• `DFDenominator` — Degrees of freedom for the denominator of the F-statistic

• `pValue`p-value for the F-statistic

Data Types: `table`

Hypothesis matrices used to compute the F-statistics for the MANOVA model terms, returned as a table of matrices. Each column of `H` corresponds to a MANOVA model term in `maov.Formula`. For more information about `H`, see Qh in Multivariate Analysis of Variance for Repeated Measures.

Data Types: `table`

MANOVA model error matrix used to compute the F-statistics for the MANOVA model terms, returned as a numeric matrix. For more information about `E`, see Qe in Multivariate Analysis of Variance for Repeated Measures.

Data Types: `single` | `double`

## Version History

Introduced in R2023b