Statistics Toolbox    
ttest

Hypothesis testing for a single sample mean

Syntax

Description

h = ttest(x,m) performs a t-test at significance level 0.05 to determine whether a sample from a normal distribution (in x) could have mean m when the standard deviation is unknown.

h = ttest(x,m,alpha) gives control of the significance level, 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,sig,ci] = ttest(x,m,alpha,tail) allows specification of one- or two-tailed tests. tail is a flag that specifies one of three alternative hypotheses:

Output sig is the p-value associated with the T-statistic

where is the sample standard deviation and is the number of observations in the sample. sig is the probability that the observed value of T could be as large or larger 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.

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. We test the hypothesis that there is no true difference.

Normal random number generator test.

The result h = 0 means that we cannot reject the null hypothesis. The significance level is 0.4474, which means that by chance we 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.


  tstat ttest2