t test and f test

6 views (last 30 days)
Shahid
Shahid on 7 Sep 2012
Answered: Samayochita on 21 Apr 2025
Hi, I am new to matlab. I have two vectors [2 3 5 4 2 1 4 6 ] and [2.7 3.1 4.2 1.7 1.1 3.7 5.2]. The individual values in the vector are independent of each other. So one of this is my calculated values set and other observed values test. Now I have to calculate p values for both t test and F test to do the error analysis. Can someone tell me which matlab functions should I use? Thanks.

Answers (1)

Samayochita
Samayochita on 21 Apr 2025
Hi Shahid,
I understand that you are trying to calculate p-values for a t-test and an F-test between two independent data sets. A t-test and F-test can be performed in MATLAB using thettest (or “ttest2”) and “vartest2 functions respectively.
1. t-test (comparing means): Test if the means of two groups are significantly different.
In MATLAB ttest2is used for unpaired samples whilettest” is used for paired samples
Since the above data seems to be paired (calculated vs. observed for the same cases) thettest” function could be used:
[h, p_ttest] = ttest(A(1:length(B)), B);
fprintf('Paired t-test p-value: %f\n', p_ttest);
  • h is 1 if the test rejects the null hypothesis at the 5% significance level.
  • p_ttest is the p-value.
If your samples are not paired, use:
[h, p_ttest2] = ttest2(A(1:length(B)), B);
fprintf('Unpaired t-test p-value: %f\n', p_ttest2);
2. F-test (comparing variances): Test if the variances of two groups are significantly different.
[h, p_ftest] = vartest2(A(1:length(B)), B);
fprintf('F-test p-value: %f\n', p_ftest);
  • h is 0 if variances are statistically similar, 1 if they are significantly different
  • p_ftest is the p-value.
For more information, please refer to the MATLAB documentation links given below:

Categories

Find more on Results, Reporting, and Test File Management in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!