# groupmeans

Mean response estimates for multivariate analysis of variance (MANOVA)

*Since R2023b*

## Description

specifies options using one or more name-value arguments in addition to any of the input
argument combinations in the previous syntaxes. For example, you can specify the confidence
level for the confidence intervals, and whether to calculate the marginal means or a mean
for each response variable. `means`

= groupmeans(___,`Name=Value`

)

## Examples

### Calculate Marginal Means for One-Way MANOVA

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 = 1-way manova Y1,Y2,Y3,Y4 ~ 1 + Factor1 Source DF TestStatistic Value F DFNumerator DFDenominator pValue _______ ___ _____________ ______ ______ ___________ _____________ __________ Factor1 2 pillai 1.1919 53.466 8 290 9.7422e-53 Error 147 Total 149 Properties, Methods

`maov`

is a `manova`

object that contains the results of the one-way MANOVA. The small *p*-value for `species`

indicates that the flower species has a statistically significant effect on at least one of the flower measurements.

Calculate the marginal means for `maov`

.

means = groupmeans(maov)

`means=`*3×5 table*
Factor1 Mean SE Lower Upper
______________ ______ ________ ______ ______
{'setosa' } 2.5355 0.042807 2.4509 2.6201
{'versicolor'} 3.573 0.042807 3.4884 3.6576
{'virginica' } 4.285 0.042807 4.2004 4.3696

The 95% confidence intervals in the table output do not overlap, which is consistent with the small *p*-value for `species`

.

### Get Marginal Means for Two-Way MANOVA

Load the `patients`

data set.

`load patients`

The variables `Systolic`

and `Diastolic`

contain data for patient systolic and diastolic blood pressure. The variables `Smoker`

and `SelfAssessedHealthStatus`

contain data for patient smoking status and self-assessed heath status.

Use the `table`

function to create a table of factor values from the data in `Systolic`

, `Diastolic`

, `Smoker`

, and `SelfAssessedHealthStatus`

.

tbl = table(Systolic,Diastolic,Smoker,SelfAssessedHealthStatus,VariableNames=["Systolic" "Diastolic" "Smoker" "SelfAssessed"]);

Perform a two-way MANOVA to test the null hypothesis that smoking status does not have a statistically significant effect on systolic and diastolic blood pressure, and the null hypothesis that self-assessed health status does not have an effect on systolic and diastolic blood pressure.

maov = manova(tbl,["Systolic" "Diastolic"])

maov = 2-way manova Systolic,Diastolic ~ 1 + Smoker + SelfAssessed Source DF TestStatistic Value F DFNumerator DFDenominator pValue ____________ __ _____________ ________ _______ ___________ _____________ __________ Smoker 1 pillai 0.67917 99.494 2 94 6.2384e-24 SelfAssessed 3 pillai 0.053808 0.87552 6 190 0.51392 Error 95 Total 99 Properties, Methods

`maov`

is a `manova`

object that contains the results of the two-way MANOVA. The small *p*-value for the `Smoker`

term in the MANOVA model indicates that enough evidence exists to conclude that mean response vectors are statistically different across the factor values of `Smoker`

. However, the large *p*-value for the `SelfAssessed`

term indicates that not enough evidence exists to reject the null hypothesis that the mean response vectors are statistically the same across the values for `SelfAssessed`

.

Calculate the marginal means for the values of the factor `Smoker`

.

`groupmeans(maov,"Smoker")`

`ans=`*2×5 table*
Smoker Mean SE Lower Upper
______ ______ _______ ______ ______
false 99.203 0.45685 98.296 100.11
true 109.45 0.62574 108.21 110.7

The output shows that the marginal mean for non-smokers is lower than the marginal mean for smokers.

### Calculate Mean for Each Response Variable

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`

and `Displacement`

variables contain data for car acceleration and displacement.

Use the `table`

function to create a table of factor values from the data in `Model_Year`

, `Cylinders`

, `Acceleration`

, and `Displacement`

.

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

Perform a two-way MANOVA using the table variables `Year`

and `Cylinders`

as factors, and the `Acceleration`

and `Displacement`

variables as response variables.

`maov = manova(tbl,"Acceleration,Displacement ~ Cylinders + Year")`

maov = 2-way manova Acceleration,Displacement ~ 1 + Year + Cylinders Source DF TestStatistic Value F DFNumerator DFDenominator pValue _________ __ _____________ ________ ______ ___________ _____________ __________ Year 2 pillai 0.084893 2.1056 4 190 0.081708 Cylinders 2 pillai 0.94174 42.27 4 190 2.5049e-25 Error 95 Total 99 Properties, Methods

`maov`

is a `manova`

object that contains the results of the two-way MANOVA. The table output shows that the *p*-value for the MANOVA model term `Year`

is too large to conclude that `Year`

has a statistically significant effect on `Acceleration`

and `Displacement`

.

Calculate the means, standard errors, and 95% confidence intervals for each response variable, grouped by the factor values in `Year`

.

`means = groupmeans(maov,"Year",MarginalMean=false)`

`means=`*6×6 table*
Year ResponseName Mean SE Lower Upper
____ ______________ ______ _______ ______ ______
70 "Acceleration" 14.102 0.45499 13.199 15.005
70 "Displacement" 233.02 6.4983 220.12 245.92
76 "Acceleration" 15.623 0.41203 14.805 16.441
76 "Displacement" 218.43 5.8848 206.75 230.12
82 "Acceleration" 15.083 0.53717 14.016 16.149
82 "Displacement" 234.09 7.6721 218.86 249.32

The table output shows that the 95% confidence intervals have significant overlap for each response variable, supporting the conclusion that `Year`

does not have a statistically significant effect on `Acceleration`

and `Displacement`

.

## Input Arguments

`maov`

— MANOVA results

`manova`

object

MANOVA results, specified as a `manova`

object.
The properties of `maov`

contain the factor values and response data
used by `groupmeans`

to calculate the means, standard errors, and
confidence intervals.

`factors`

— Factors used to group response data

string scalar | character vector | string vector | cell array of character vectors

Factors used to group the response data, specified as a string scalar, a character or string
vector, or a cell array of character vectors. The `groupmeans`

function groups the response data by the combinations of values for the factors in
`factors`

. The `factors`

argument must be one
or more of the names in `maov.FactorNames`

.

**Example: **`["Factor1","Factor2"]`

**Data Types: **`string`

| `cell`

### Name-Value Arguments

Specify optional pairs of arguments as
`Name1=Value1,...,NameN=ValueN`

, where `Name`

is
the argument name and `Value`

is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.

**Example: **`groupmeans(maov,["Cylinders","Year"],MarginalMean=false,Alpha=0.01)`

calculates a mean with a 99% confidence interval for each response variable.

`Alpha`

— Significance level

`0.05`

(default) | scalar value in the range (0,1)

Significance level for the estimates, specified as a scalar value in the range
(0,1). The confidence level of the confidence intervals is $$100(1-\alpha )\%$$. The default value for `alpha`

is
`0.05`

, which returns 95% confidence intervals for the
estimates.

**Example: **`Alpha=0.01`

**Data Types: **`single`

| `double`

`MarginalMean`

— Indicator to calculate marginal means

`true`

or `1`

(default) | `false`

or `0`

Indicator to calculate the marginal means, specified as a numeric or logical
`1`

(`true`

) or `0`

(`false`

). Each marginal mean is the average of the values in the
corresponding mean response vector. When `MarginalMean`

is false,
`groupmeans`

calculates a separate mean for each response
variable.

**Example: **`MarginalMean=false`

**Data Types: **`logical`

## Output Arguments

`means`

— Means, standard errors, and confidence intervals

table

Means, standard errors, and confidence intervals, returned as a table. The table
`means`

has one row per unique combination of factor values when
`MarginalMean`

is `true`

. Otherwise,
`means`

has *r* rows per unique combination of
factor values, where *r* is the number of response variables.

If `maov`

is a one-way `manova`

object,
`means`

contains a column corresponding to the single factor. If
`maov`

is a two- or N-way `manova`

object,
`means`

contains a column for each factor specified in
`factors`

. The table also contains the following columns.

`Mean`

— Estimate of the marginal or response variable mean corresponding to the factor value. Use the`MarginalMean`

name-value argument to specify the type of mean to calculate.`SE`

— Standard error of the mean estimate.`Lower`

— 95% lower confidence bound of the mean estimate.`Upper`

— 95% upper confidence bound of the mean estimate.

## Version History

**Introduced in R2023b**

## See Also

## Comando MATLAB

Hai fatto clic su un collegamento che corrisponde a questo comando MATLAB:

Esegui il comando inserendolo nella finestra di comando MATLAB. I browser web non supportano i comandi MATLAB.

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

## How to Get Best Site Performance

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

### Americas

- América Latina (Español)
- Canada (English)
- United States (English)

### Europe

- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)

- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)