Statistics Toolbox Previous page   Next Page
ttest

Hypothesis testing for a single sample mean

Syntax

Description

h = ttest(x) performs a t-test of the hypothesis that the data in the vector x come from a distribution with mean zero, and returns the result of the test in h. h==0 indicates that the null hypothesis (mean is zero) cannot be rejected at the 5% significance level. h==1 indicates that the null hypothesis can be rejected at the 5% level. The data are assumed to come from a normal distribution with unknown variance.

h = ttest(x,m) performs a t-test of the hypothesis that the data in the vector x come from a distribution with mean m.

h = ttest(x,y) performs a paired t-test of the hypothesis that two matched (or paired) samples in the vectors x and y come from distributions with equal means. The difference x-y is assumed to come from a normal distribution with unknown variance. x and y must have the same length.

h = ttest(...,alpha) performs the test at the significance level (100*alpha)%. For example, if alpha = 0.01, and the result, h, is 1 you can reject the null hypothesis at the significance level 0.01. If h is 0, you cannot reject the null hypothesis at the alpha level of significance.

h = ttest(...,alpha,tail) performs the test against the alternative hypothesis specified by tail. There are three options for tail:

Output p is the p-value associated with the t-statistic.

where is the sample standard deviation and is the number of observations in the sample. p is the probability that the value of the t-statistic is equal to or more extreme than the observed value by chance, under the null hypothesis that the mean of x is equal to m.

ci is a 1-alpha confidence interval for the true mean.

[h,p,ci,stats] = ttest(...) returns a structure with the following fields:

Example

This example generates 100 normal random numbers with theoretical mean zero and standard deviation one. The observed mean and standard deviation are different from their theoretical values, of course, so you test the hypothesis that there is no true difference.

Normal random number generator test.

The result h = 0 means that you cannot reject the null hypothesis. The significance level is 0.4474, which means that by chance you would have observed values of T more extreme than the one in this example in 45 of 100 similar experiments. A 95% confidence interval on the mean is [-0.1165 0.2620], which includes the theoretical (and hypothesized) mean of zero.


Previous page  tstat ttest2 Next page

Learn more about the latest releases of MathWorks products:

 © 1994-2010 The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS