Statistics: ttest

### Function Reference: `ttest`

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

Test for mean of a normal sample with unknown variance.

Perform a t-test of the null hypothesis `mean (x) == m` for a sample x from a normal distribution with unknown mean and unknown standard deviation. Under the null, the test statistic t has a Student’s t distribution. The default value of m is 0.

If the second argument y is a vector, a paired-t test of the hypothesis `mean (x) = mean (y)` is performed. If x and y are vectors, they must have the same size and dimensions.

x (and y) can also be matrices. For matrices, `ttest` 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`.

`ttest` treats NaNs as missing values, and ignores them.

Name-Value pair arguments can be used to set various options. `"alpha"` can be used to specify the significance level of the test (the default value is 0.05). `"tail"`, can be used to select the desired alternative hypotheses. If the value is `"both"` (default) the null is tested against the two-sided alternative `mean (x) != m`. If it is `"right"` the one-sided alternative `mean (x) > m` is considered. Similarly for `"left"`, the one-sided alternative `mean (x) < m` is considered. When argument x is a matrix, `"dim"` can be used to select the dimension over which to perform the test. (The default is the first non-singleton dimension).

If h is 1 the null hypothesis is rejected, meaning that the tested sample does not come from a Student’s t distribution. If h is 0, then the null hypothesis cannot be rejected and it can be assumed that x follows a Student’s t distribution. 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’s standard deviation (sd).

See also: hotelling_ttest, ttest2, hotelling_ttest2

Source Code: ttest