h = vartest(x,v) returns
a test decision for the null hypothesis that the data in vector x comes
from a normal distribution with variance v, using
the chi-square
variance test. The alternative hypothesis is that x comes
from a normal distribution with a different variance. The result h is 1 if
the test rejects the null hypothesis at the 5% significance level,
and 0 otherwise.

h = vartest(x,v,Name,Value) performs
the chi-square variance 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,ci,stats]
= vartest(___) also returns the confidence
interval for the true variance, ci, and the structure stats containing
information about the test statistic.

Load the sample data. Create a vector containing the first
column of the students' exam grades matrix.

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

Test the null hypothesis that the data comes from a distribution
with a variance of 25.

[h,p,ci,stats] = vartest(x,25)

h =
1
p =
0
ci =
59.8936
99.7688
stats =
chisqstat: 361.9597
df: 119

The returned value h = 1 indicates that vartest rejects
the null hypothesis at the default 5% significance level. ci shows
the lower and upper boundaries of the 95% confidence interval for
the true variance, and suggests that the true variance is greater
than 25.

Load the sample data. Create a vector containing the first
column of the students' exam grades matrix.

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

Test the null hypothesis that the data comes from a distribution
with a variance of 25, against the alternative hypothesis that the
variance is greater than 25.

[h,p] = vartest(x,25,'Tail','right')

h =
1
p =
2.4269e-26

The returned value of h = 1 indicates that vartest rejects
the null hypothesis at the default 5% significance level, in favor
of the alternative hypothesis that the variance is greater than 25.

Sample data, specified as a vector, matrix, or multidimensional
array. For matrices, vartest performs separate
tests along each column of x, and returns a row
vector of results. For multidimensional arrays, vartest works
along the first
nonsingleton dimension of x.

Hypothesized variance, specified as a nonnegative scalar value.

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 equality to the hypothesized variance,
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 variance, returned as a two-element
vector containing the lower and upper boundaries of the 100 ×
(1 – Alpha)% confidence interval.

The chi-square variance test is used to test
if the variance of a population is equal to a hypothesized value.

The test statistic is

where N is the
sample size, s is the sample standard deviation,
and σ_{0} is the hypothesized
standard deviation. The denominator is the ratio of the sample standard
deviation to the hypothesized standard deviation. The further this
ratio deviates from 1, the more likely you are to reject the null
hypothesis. The test statistic T has a chi-square
distribution with N – 1 degrees of freedom
under the null hypothesis.

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.