ttest2

Hypothesis test for the means of two samples with unknown and equal standard deviations.

Syntax

[h,pvalue,ci] = ttest2(x,y)

[h,pvalue,ci] = ttest2(x,y,name,value)

Inputs

x,y
Data samples to be tested.
Type: double
Dimension: vector | matrix
name
Name of an option whose value follows. Multiple name/value pairs are allowed. The supported options are alpha and dim.
alpha is the level of significance (default: 0.05).
dim is the dimension on which the test is performed (default: first non-singular dimension).
Type: string
value
Value for the preceeding option name.
Type: double | integer
Dimension: scalar

Outputs

h
0 if the null hypothesis is accepted. 1 if the null hypothesis is rejected.
pvalue
The p-value of the test.
ci
A 100*(1-alpha)% confidence interval for the difference of the population means (x - y).

Example

Simple ttest2 example.

x = [7.3 9.4 5.9 6.5 5.5 7 5.3 7.3 2.6 8.7 8.1 2.5 3.9 1.4 0.2 4 6 6.1 10.3 1.2];
y = [9.6 3.1 6 6.7 5.7 7.6 6.8 7 7.8 6.1 7.9 7 8.2 8.2 1.6 10 9.2 8.5 5.9 7.8];
[h,pvalue,ci] = ttest2(x,y)
h = 1
pvalue = 0.049394
ci = [Matrix] 1 x 2
-3.1456 -0.0043907

Comments

ttest2 is an unpaired 2 sample t test and assumes that the samples comes from normally distributed populations. The null hypothesis is that the two population means are equal.