# barttest

Bartlett's test for multivariate analysis of variance (MANOVA)

Since R2023b

## Syntax

``d = barttest(maov)``
``d = barttest(maov,factor)``
``d = barttest(___,Alpha=alpha)``
``[d,tbl] = barttest(___)``

## Description

````d = barttest(maov)` returns the result of a Bartlett's test to determine the minimum number of dimensions needed by a linear space to contain the mean response vectors of the `manova` object `maov`. In other words, `barttest` calculates the number of linearly independent mean response vectors. This syntax is supported only when `maov` is a one-way `manova` object. ```

example

````d = barttest(maov,factor)` specifies the factor `barttest` uses to group the response data. Use this syntax when `maov` is a two- or N-way `manova` object.```
````d = barttest(___,Alpha=alpha)` specifies the confidence level `barttest` uses to return the minimum dimension, using any of the input argument combinations in previous syntaxes. The confidence level is (1 – `alpha`)*100.```

example

````[d,tbl] = barttest(___)` additionally returns a table containing the Bartlett's test statistics.```

## Examples

collapse all

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` and `Cylinders`.

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

Create a matrix of response variables from `Acceleration` and `Displacement`.

`y = [Acceleration Displacement];`

Perform a two-way MANOVA using the factor values in `tbl` and the response variables in `y`.

`maov = manova(tbl,y)`
```maov = 2-way manova Y1,Y2 ~ 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 two-way `manova` object that contains the results of the two-way MANOVA. The output displays the formula for the MANOVA model and a MANOVA table. In the formula, the car acceleration and displacement are represented by the variables `Y1` and `Y2`, respectively. The MANOVA table contains a small p-value corresponding to the `Cylinders` term in the MANOVA model. The small p-value indicates that, at the 95% confidence level, enough evidence exists to conclude that `Cylinders` has a statistically significant effect on the mean response vector. `Year` has a p-value larger than 0.05, which indicates that not enough evidence exists to conclude that `Year` has a statistically significant effect on the mean response vector at the 95% confidence level.

Use the `barttest` function to determine the dimension of the space spanned by the mean response vectors corresponding to the factor `Year`.

`barttest(maov,"Year")`
```ans = 0 ```

The output shows that the mean response vectors corresponding to `Year` span a point, indicating that they are not statistically different from each other. This result is consistent with the large p-value for `Year`.

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 one-way `manova` object that contains the results of the one-way MANOVA.

Perform a Bartlett's test to determine the minimum number of dimensions needed by a linear space to contain the mean response vectors. `maov` has three mean response vectors corresponding to the three iris species.

`[d,tbl] = barttest(maov)`
```d = 2 ```
```tbl=2×5 table Dimension WilksLambda ChiSquared DF pValue _________ ___________ __________ __ ___________ 0 0.023439 546.12 8 8.8708e-113 1 0.77797 36.53 3 5.7861e-08 ```

Each row of the table output corresponds to a dimension checked by the Bartlett's test. The small p-values in the table indicate that not enough evidence exists to conclude that the mean response vectors are elements of a zero- or one-dimensional space. Three points are guaranteed to be elements of a two-dimensional space, so the Bartlett's test returns `2` as the number of dimensions.

## Input Arguments

collapse all

MANOVA results, specified as a `manova` object. The properties of `maov` contain the response data and factor values used by `barttest` to perform the Bartlett's test.

Factor used to group the response data, specified as a string scalar or character array. `factor` must be a name in `maov.FactorNames`.

Example: `"Factor2"`

Data Types: `char` | `string`

Significance level `barttest` uses to return `d`, specified as a scalar value in the range (0,1). The confidence level for `d` is (1 – `alpha`)*100.

Example: `Alpha=0.01`

Data Types: `single` | `double`

## Output Arguments

collapse all

Dimension of the lowest dimensional linear space containing the response vectors of `maov`, returned as a nonnegative integer. `d` is the number of linearly independent mean response vectors for `maov`.

Bartlett's test statistics, returned as a table. Each row of `tbl` corresponds to a dimension checked by `barttest` using the Wilks' lambda test statistic. `tbl` has the same number of rows as the minimum of the number of response variables and the number of values in `factor` minus 1. `tbl` has the following columns:

• `Dimension` — Dimension checked by the Bartlett's test

• `WilksLambda` — Value of the Wilks' lambda test statistic

• `ChiSquared` — Value of the chi-square test statistic corresponding to the Wilks' lambda test statistic

• `DF` — Degrees of freedom of the chi-square test statistic

• `pValue`p-value for the chi-square test statistic

Data Types: `table`

## Alternative Functionality

The `manova1` function returns the output of the `barttest` object function, and a subset of the `manova` object properties. `manova1` is limited to one-way MANOVA.

## Version History

Introduced in R2023b