h = vartest2(x,y) returns
a test decision for the null hypothesis that the data in vectors x and y comes
from normal distributions with the same variance, using the two-sample F-test.
The alternative hypothesis is that they come from normal distributions
with different variances. The result h is 1 if
the test rejects the null hypothesis at the 5% significance level,
and 0 otherwise.

h = vartest2(x,y,Name,Value) returns
a test decision for the two-sample F-test with
additional options specified by one or more name-value pair arguments.
For example, you can change the significance level or conduct a one-sided
test.

[h,p] =
vartest2(___) also returns the p-value
of the test, p, using any of the input arguments
in the previous syntaxes.

[h,p,ci,stats]
= vartest2(___) also returns the confidence
interval for the true variance ratio, ci, and
the structure stats containing information about
the test statistic.

Load the sample data. Create vectors containing the first
and second columns of the data matrix to represent students'
grades on two exams.

load examgrades;
x = grades(:,1);
y = grades(:,2);

Test the null hypothesis that the data in x and y comes
from distributions with the same variance.

[h,p,ci,stats] = vartest2(x,y)

h =
1
p =
0.0019
ci =
1.2383
2.5494
stats =
fstat: 1.7768
df1: 119
df2: 119

The returned result h = 1 indicates that vartest2 rejects
the null hypothesis at the default 5% significance level. ci contains
the lower and upper boundaries of the 95% confidence interval for
the true variance ratio. stats contains the value
of the test statistic for the F-test and the numerator
and denominator degrees of freedom.

Load the sample data. Create vectors containing the first
and second columns of the data matrix to represent students'
grades on two exams.

load examgrades;
x = grades(:,1);
y = grades(:,2);

Test the null hypothesis that the data in x and y comes
from distributions with the same variance, against the alternative
that the population variance of x is greater than
that of y.

vartest2(x,y,'Tail','right')

h =
1
p =
9.4364e-04

The returned result h = 1 indicates that vartest2 rejects
the null hypothesis at the default 5% significance level, in favor
of the alternative hypothesis that the population variance of x is
greater than that of y.

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

If x and y are
matrices, they must have the same number of columns, but do not need
to have the same number of rows. vartest2 performs
separate tests along each column and returns a vector of the results.

If x and y are
multidimensional arrays, they must have the same number of dimensions,
and the same size along all but the first nonsingleton dimension.

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

If x and y are
matrices, they must have the same number of columns, but do not need
to have the same number of rows. vartest2 performs
separate tests along each column and returns a vector of the results.

If x and y are
multidimensional arrays, they must have the same number of dimensions,
and the same size along all but the first nonsingleton dimension.

Data Types: single | double

Name-Value Pair Arguments

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 to test along, specified as the
comma-separated pair consisting of 'Dim' and a
positive integer value. For example, specifying 'Dim',1 tests
the data in each column for variance equality, while 'Dim',2 tests
the data in each row.

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.

Confidence interval for the true ratio of the population variances,
returned as a two-element vector containing the lower and upper boundaries
of the 100 × (1 – Alpha)% confidence
interval.

The two-sample F-test is
used to test if the variances of two populations are equal.

The test statistic is

where s_{1} and s_{2} are
the sample variances. The test statistic is a ratio of the two sample
variances. The further this ratio deviates from 1, the more likely
you are to reject the null hypothesis. Under the null hypothesis,
the test statistic F has a F-distribution
with numerator degrees of freedom equal to N_{1} –
1 and denominator degrees of freedom equal to N_{2} –
1, where N_{1} and N_{2} are
the sample sizes of the two data sets.

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.