Search code examples
matlabstatisticst-test

What is the difference between the `ttest` and `ttest2` function in Matlab


I have two samples X and Y, both are N*1 vectors, I found that in Matlab(R2015), both ttest and ttest2 can accept two samples and give the P value, but their results are somewhat different.

For ttest, ttest(X,Y) gives P = 1.8e-7, for ttest2, ttest2(X,Y) gives P = 8.0e-11. It seems that both functions give relatively low P values. However, I am not familiar with the differences between these two functions, also, if I am going to report the P-value, which value should I choose?


Solution

  • This question is more about statistics than programming.

    With two samples, ttest performs a paired t-test while ttest2 does a genuine two-sample test. The paired test is equivalent to a one-sample t-test on the difference of the paired values.