data = [5.1, 5.5, 5.3, 5.7, 5.2]; [h,p,ci,stats] = ttest(data, 5.0); disp(h); disp(round(p,3));
The t-test compares the sample mean to the hypothesized mean 5.0.
The p-value is about 0.012, which is less than 0.05, so h=1 (reject null).
observed = [20 30; 15 35]; [h,p,stats] = chi2gof([1 2 1 2], 'Ctrs', [1 2], 'Frequency', observed(:)); disp(h); disp(round(p,3));
The chi-square goodness-of-fit test here tests if the observed frequencies differ from expected.
The p-value is about 0.003, which is less than 0.05, so h=1 means reject the null hypothesis.
stats returned by MATLAB's ttest function?The stats output is a structure with fields such as tstat (the test statistic) and df (degrees of freedom).
It is not a vector of p-values, nor a scalar decision, nor a matrix of confidence intervals.
x1 = [5.1, 5.5, 5.3, 5.7, 5.2]; x2 = [4.9, 5.0, 5.1, 4.8, 5.0]; [h,p] = ttest2(x1, x2, 'Vartype', 'unequal'); disp(h); disp(round(p,3));
The two-sample t-test with unequal variances compares the means of x1 and x2.
The p-value is about 0.002, which is less than 0.05, so h=1 means reject the null hypothesis that means are equal.
observed = [10 20 30]; expected = [15 15 30]; [h,p] = chi2gof(observed, 'Expected', expected); disp(h);
The function chi2gof expects raw data samples, not frequency counts.
Passing frequency counts as data causes an error about input format.
