Main Content

vartest

Chi-square variance test

Description

example

h= vartest(x,v)returns a test decision for the null hypothesis that the data in vectorxcomes from a normal distribution with variancev, using thechi-square variance test. The alternative hypothesis is thatxcomes from a normal distribution with a different variance. The resulth1if the test rejects the null hypothesis at the 5% significance level, and0otherwise.

example

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.

example

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

example

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

Examples

collapse all

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

loadexamgradesx = 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 =2×159.8936 99.7688
stats =struct with fields:chisqstat: 361.9597 df: 119

The returned valueh = 1indicates thatvartestrejects the null hypothesis at the default 5% significance level.cishows 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.

loadexamgradesx = 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 ofh = 1indicates thatvartestrejects the null hypothesis at the default 5% significance level, in favor of the alternative hypothesis that the variance is greater than 25.

Input Arguments

collapse all

样本数据,指定为vector, matrix, or multidimensional array. For matrices,vartestperforms separate tests along each column ofx, and returns a row vector of results. Formultidimensional arrays,vartestworks along thefirst nonsingleton dimensionofx.

Data Types:single|double

Hypothesized variance, specified as a nonnegative scalar value.

Data Types:single|double

Name-Value Arguments

Specify optional comma-separated pairs ofName,Valuearguments.Name是the argument name andValue是the corresponding value.Namemust appear inside quotes. You can specify several name and value pair arguments in any order asName1,Value1,...,NameN,ValueN.

Example:'Tail','right','Alpha',0.01specifies 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

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',1tests the data in each column for equality to the hypothesized variance, while'Dim',2tests the data in each row.

Example:'Dim',2

Data Types:single|double

Type of alternative hypothesis to evaluate, specified as the comma-separated pair consisting of'Tail'and one of the following.

'both' Test the alternative hypothesis that the population variance is notv.
'right' Test the alternative hypothesis that the population variance is greater thanv.
'left' Test the alternative hypothesis that the population variance is less thanv.

Example:'Tail','right'

Output Arguments

collapse all

Hypothesis test result, returned as1or0.

  • Ifh= 1, this indicates the rejection of the null hypothesis at theAlphasignificance level.

  • Ifh= 0, this indicates a failure to reject the null hypothesis at theAlphasignificance level.

p-value of the test, returned as a scalar value in the range [0,1].p是the probability of observing a test statistic as extreme as, or more extreme than, the observed value under the null hypothesis. Small values ofp怀疑啊n 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.

Test statistics for the chi-square variance test, returned as a structure containing:

  • chisqstat— Value of the test statistic.

  • df— Degrees of freedom of the test.

More About

collapse all

Chi-Square Variance Test

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

The test statistic is

T = ( n 1 ) ( s σ 0 ) 2 ,

wheren是the sample size,s是the sample standard deviation, andσ0是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 statisticThas a chi-square distribution withn– 1degrees of freedom under the null hypothesis.

Multidimensional Array

A multidimensional array has more than two dimensions. For example, ifx是a 1-by-3-by-4 array, thenx是a three-dimensional array.

First Nonsingleton Dimension

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

Tips

  • Usesampsizepwrto calculate:

    • The sample size that corresponds to specified power and parameter values;

    • The power achieved for a particular sample size, given the true parameter value;

    • The parameter value detectable with the specified sample size and power.

Extended Capabilities

Introduced before R2006a