h = ansaribradley(x,y) returns
a test decision for the null hypothesis that the data in vectors x and y comes
from the same distribution, using the Ansari-Bradley test. The alternative
hypothesis is that the data in x and y comes
from distributions with the same median and shape but different dispersions
(e.g., variances). The result h is 1 if
the test rejects the null hypothesis at the 5% significance level,
or 0 otherwise.

h = ansaribradley(x,y,Name,Value) returns
a test decision for the Ansari-Bradley test with additional options
specified by one or more name-value pair arguments. For example, you
can change the significance level, conduct a one-sided test, or use
a normal approximation to calculate the value of the test statistic.

Load the sample data. Create data vectors of miles per
gallon (MPG) measurements for the model years 1982
and 1976.

load carsmall;
x = MPG(Model_Year==82);
y = MPG(Model_Year==76);

Test the null hypothesis that the miles per gallon measured
in cars from 1982 and 1976 have equal variances, against the alternative
hypothesis that the variance of cars from 1982 is greater than that
of cars from 1976.

[h,p,stats] = ansaribradley(x,y,'Tail','right')

h =
0
p =
0.5787
stats =
W: 526.9000
Wstar: 0.1986

The returned value of h = 0 indicates that ansaribradley does
not reject the null hypothesis that the variance in miles per gallon
is the same for the two model years, when the alternative is that
the variance of cars from 1982 is greater than that of cars from 1976.

Sample data, specified as a vector, matrix, or multidimensional
array.

If x and y are
specified as vectors, they do not need to be the same length.

If x and y are
specified as matrices, they must have the same number of columns. ansaribradley performs
separate tests along each column and returns a vector of results.

Sample data, specified as a vector, matrix, or multidimensional
array.

If x and y are
specified as vectors, they do not need to be the same length.

If x and y are
specified as matrices, they must have the same number of columns. ansaribradley performs
separate tests along each column and returns a vector of results.

Specify optional comma-separated pairs of Name,Value arguments.
Name is the argument
name and Value is the corresponding
value. Name must appear
inside single quotes (' ').
You can specify several name and value pair
arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: 'Tail','right','Alpha',0.01 specifies
a right-tailed hypothesis test at the 1% significance level.

Significance level of the hypothesis test, specified as the
comma-separated pair consisting of 'Alpha' and
a scalar value in the range (0,1).

Example: 'Alpha',0.01

Data Types: single | double

'Dim' — Dimensionfirst nonsingleton dimension (default) | positive integer value

Dimension of the input matrix along which to test the means,
specified as the comma-separated pair consisting of 'Dim' and
a positive integer value. For example, specifying 'Dim',1 tests
the column means, while 'Dim',2 tests the row means.

Computation method for the test statistic, specified as the
comma-separated pair consisting of 'Method' and
one of the following.

'exact'

Compute p using an exact calculation of
the distribution of the test statistic W. This
is the default if n, the total number of rows in x and y,
is 25 or less. Note that n is computed before any NaN values
(representing missing data) are removed.

'approximate'

Compute p using a normal approximation
for the statistic W*. This is the default if n,
the total number of rows in x and y,
is greater than 25.

p-value of the test, returned as a scalar
value in the range [0,1]. p is the probability
of observing a test statistic as extreme as, or more extreme than,
the observed value under the null hypothesis. Small values of p cast
doubt on the validity of the null hypothesis.

The Ansari-Bradley test is a nonparametric
alternative to the two-sample F-test of equal variances.
It does not require the assumption that x and y come
from normal distributions. The dispersion of a distribution is generally
measured by its variance or standard deviation, but the Ansari-Bradley
test can be used with samples from distributions that do not have
finite variances.

This test requires that the samples have equal medians. Under
that assumption, and if the distributions of the samples are continuous
and identical, the test is independent of the distributions. If the
samples do not have the same medians, the results can be misleading.
In that case, Ansari and Bradley recommend subtracting the median,
but then the distribution of the resulting test under the null hypothesis
is no longer independent of the common distribution of x and y.
If you want to perform the tests with medians subtracted, you should
subtract the medians from x and y before
calling ansaribradley.

The first nonsingleton dimension is the first
dimension of an array whose size is not equal to 1. For example, if x is
a 1-by-2-by-3-by-4 array, then the second dimension is the first nonsingleton
dimension of x.