ttest2

Syntax

Description

h = ttest2(x,y) returns
a test decision for the null hypothesis that the data in vectors x and y comes
from independent random samples from normal distributions with equal
means and equal but unknown variances, using the two-sample t-test.
The alternative hypothesis is that the data in x and y comes
from populations with unequal means. The result h is 1 if
the test rejects the null hypothesis at the 5% significance level,
and 0 otherwise.

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

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,'Vartype','unequal' specifies
a right-tailed test at the 1% significance level, and does not assume
that x and y have equal population
variances.

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.

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 means are
not equal.

'right'

Test the alternative hypothesis that the population mean of x is
greater than the population mean of y.

'left'

Test the alternative hypothesis that the population mean of x is
less than the population mean of y.

Example: 'Tail','right'

'Vartype' — Variance type'equal' (default) | 'unequal'

Variance type, specified as the comma-separated pair consisting
of 'Vartype' and one of the following.

'equal'

Conduct test using the assumption that x and y are
from normal distributions with unknown but equal variances.

'unequal'

Conduct test using the assumption that x and y are
from normal distributions with unknown and unequal variances. This
is called the Behrens-Fisher problem. ttest2 uses
Satterthwaite's approximation for the effective degrees of
freedom.

Vartype must be a single variance type, even
when x is a matrix or a multidimensional array.

Output Arguments

h — Hypothesis test result1 | 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-valuescalar 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 intervalvector

Confidence interval for the difference in population means of x and y,
returned as a two-element vector containing the lower and upper boundaries
of the 100 × (1 – Alpha)% confidence
interval.

stats — Test statisticsstructure

Test statistics for the two-sample t-test,
returned as a structure containing the following:

tstat — Value of the test
statistic.

df — Degrees of freedom
of the test.

sd — Pooled estimate of
the population standard deviation (for the equal variance case) or
a vector containing the unpooled estimates of the population standard
deviations (for the unequal variance case).

More About

Two-Sample t-test

The two-sample t-test is
a parametric test that compares the location parameter of two independent
data samples.

The test statistic is

t=x¯−y¯sx2n+sy2m,

where x¯ and y¯ are the sample means, sx and sy are
the sample standard deviations, and n and m are
the sample sizes.

In the case where it is assumed that the two data samples are
from populations with equal variances, the test statistic under the
null hypothesis has Student's t distribution
with n + m –
2 degrees of freedom, and the sample standard
deviations are replaced by the pooled standard deviation

s=(n−1)sx2+(m−1)sy2n+m−2.

In the case where it is not assumed that the two data samples
are from populations with equal variances, the test statistic under
the null hypothesis has an approximate Student's t distribution
with a number of degrees of freedom given by Satterthwaite's approximation.
This test is sometimes called Welch's t-test.

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.