# vartest2

Two-sample *F*-test for equal variances

## Syntax

## Description

returns
a test decision for the null hypothesis that the data in vectors `h`

= vartest2(`x`

,`y`

)`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.

returns
a test decision for the two-sample `h`

= vartest2(`x`

,`y`

,`Name,Value`

)*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.

## Examples

### Test for Equal Variances

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 = `*2×1*
1.2383
2.5494

`stats = `*struct with fields:*
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.

### One-Sided Hypothesis Test

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')

ans = 1

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`

.

## Input Arguments

`x`

— Sample data

vector | matrix | multidimensional array

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

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`

`y`

— Sample data

vector | matrix | multidimensional array

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

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 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 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.`Alpha`

— Significance level

`0.05`

(default) | scalar value in the range (0,1)

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`

— Dimension

first 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.

**Example: **`'Dim',2`

**Data Types: **`single`

| `double`

`Tail`

— Type of alternative hypothesis

`'both'`

(default) | `'right'`

| `'left'`

Type of alternative hypothesis to evaluate using the *F*-test,
specified as the comma-separated pair consisting of `'Tail'`

and
one of the following.

`'both'` | Test the alternative hypothesis that the population variances are not equal. |

`'right'` | Test the alternative hypothesis that the population variance
of `x` is greater than that of `y` . |

`'left'` | Test the alternative hypothesis that the population variance
of `x` is less than that of `y` . |

**Example: **`'Tail','right'`

## Output Arguments

`h`

— Hypothesis test result

`1`

| `0`

Hypothesis test result, returned as `1`

or `0`

.

If

`h`

`= 1`

, this indicates the rejection of the null hypothesis at the`Alpha`

significance level.If

`h`

`= 0`

, this indicates a failure to reject the null hypothesis at the`Alpha`

significance level.

`p`

— *p*-value

scalar value in the range [0,1]

*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.

`ci`

— Confidence interval

vector

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.

`stats`

— Test statistics

structure

Test statistics for the hypothesis test, returned as a structure containing:

`fstat`

— Value of the test statistic.`df1`

— Numerator degrees of freedom of the test.`df2`

— Denominator degrees of freedom of the test.

## More About

### Two-Sample *F*-Test

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

The test statistic is

$$F=\frac{{s}_{1}{}^{2}}{{s}_{2}{}^{2}},$$

where *s*_{1} and *s*_{2} are
the sample standard deviations. 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.

### Multidimensional Array

A multidimensional array has more than two
dimensions. For example, if `x`

is a 1-by-3-by-4
array, then `x`

is 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, if `x`

is
a 1-by-2-by-3-by-4 array, then the second dimension is the first nonsingleton
dimension of `x`

.

## Extended Capabilities

### GPU Arrays

Accelerate code by running on a graphics processing unit (GPU) using Parallel Computing Toolbox™.

This function fully supports GPU arrays. For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).

**Introduced before R2006a**

## MATLAB 명령

다음 MATLAB 명령에 해당하는 링크를 클릭했습니다.

명령을 실행하려면 MATLAB 명령 창에 입력하십시오. 웹 브라우저는 MATLAB 명령을 지원하지 않습니다.

# Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

## How to Get Best Site Performance

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

### Americas

- América Latina (Español)
- Canada (English)
- United States (English)

### Europe

- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)

- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)