T-test


Background

With a t-test one can investigate whether two collections of samples stem from different underlying populations. For instance, one can investigate whether P3 peaks in two experimental conditions are significantly different. The t-test is a parametric test, i.e. it assumes that data have come from a Gaussian probability distribution and make inferences about the parameters of the distribution. Assumptions of the t-test:

{i} Paired-samples versus independent-samples t-test

<!> Some pitfalls

Further reading

Toolbox

If two conditions are compared, your data matrix is a Nx2 matrix. In a paired-samples t-test, the N subjects are arranged along the rows, with the first column corresponding to condition 1 and the second column corresponding to condition 2. In an independent-samples t-test, each column represents one group consisting of N subjects each; there is no specific order for the subjects in the two groups. This can be visualized as follows.

ttest.png

The following code gives an example on performing a paired-samples t-test in Matlab. First, two Gaussian distributed data columns are generated in d. Then, they are compared to each other using a t-test.

N = 20;
d = [randn(N,1) randn(N,1)+0.1];      % Each column is one dataset
[h,p,ci,stats] = ttest(d(:,1), d(:,2))

where h (0 or 1) specifies whether or not the null hypothesis "The means of the two distributions are equal" is rejected, p gives the according p-value, ci gives an 1-α confidence interval for the d1-d2 mean. stats is a struct giving the t-value, the degrees-of-freedom df, and the standard deviation sd.

You can also run a one-sample t-test on each of the two distributions, using

[h,p,ci,stats] = ttest(d(:,1))
[h2,p2,ci2,stats2] = ttest(d(:,2))

In this case, the t-test tests whether the mean of each distribution is significantly different from 0.

For an independent-samples t-test, the MATLAB code is virtually identical, but to use the MATLAB function ttest2.

[h,p,ci,stats] = ttest2(d(:,1),d(:,2))

M-file

ttest_tutorial.m

Author(s)

Matthias Treder matthias.treder@tu-berlin.de

IDA Wiki: IDA/BerlinBCI/ToolBox/ToolboxStatisticsTtest (last edited 2011-12-14 18:37:52 by MatthiasTreder)