t test and f test

6 次查看(过去 30 天)
Shahid
Shahid 2012-9-7
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.

回答(1 个)

Samayochita
Samayochita 2025-4-21
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:

类别

Help CenterFile Exchange 中查找有关 Results, Reporting, and Test File Management 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by