Categories &

Functions List

Function Reference: ttest2

statistics: [h, pval, ci, stats] = ttest2 (x, y)
statistics: [h, pval, ci, stats] = ttest2 (x, y, Name, Value)

Perform a t-test to compare the means of two groups of data under the null hypothesis that the groups are drawn from distributions with the same mean.

x and y can be vectors or matrices. For matrices, ttest2 performs separate t-tests along each column, and returns a vector of results. x and y must have the same number of columns. The Type I error rate of the resulting vector of pval can be controlled by entering pval as input to the function multcompare.

ttest2 treats NaNs as missing values, and ignores them.

For a nested t-test, use anova2.

The argument "alpha" can be used to specify the significance level of the test (the default value is 0.05). The string argument "tail", can be used to select the desired alternative hypotheses. If "tail" is "both" (default) the null is tested against the two-sided alternative mean (x) != m. If "tail" is "right" the one-sided alternative mean (x) > m is considered. Similarly for "left", the one-sided alternative mean (x) < m is considered.

When "vartype" is "equal" the variances are assumed to be equal (this is the default). When "vartype" is "unequal" the variances are not assumed equal.

When argument x and y are matrices the "dim" argument can be used to select the dimension over which to perform the test. (The default is the first non-singleton dimension.)

If h is 0 the null hypothesis is accepted, if it is 1 the null hypothesis is rejected. The p-value of the test is returned in pval. A 100(1-alpha)% confidence interval is returned in ci. stats is a structure containing the value of the test statistic (tstat), the degrees of freedom (df) and the sample standard deviation (sd).

See also: hotelling_ttest2, anova1, hotelling_ttest, ttest

Source Code: ttest2