Geoscience Reference
In-Depth Information
load('organicmatter_three.mat');
h is i le again contains two data sets
corg1
and
corg2
. As before, we plot both
histograms in a single graph.
histogram(corg1,'FaceColor','b'), hold on
histogram(corg2,'FaceColor','r'), hold off
We then compute the sample sizes, the means and the standard deviations.
na = length(corg1); nb = length(corg2);
ma = mean(corg1); mb = mean(corg2);
sa = std(corg1); sb = std(corg2);
Next, we calculate the
t
-value using the translation of the equation for the
t
-test statistic into MATLAB code.
tcalc = abs((ma-mb))/sqrt(((na+nb)/(na*nb)) * ...
(((na-1)*sa^2+(nb-1)*sb^2)/(na+nb-2)))
tcalc =
4.7364
We can now compare the calculated
tcalc
value of 4.7364 with the critical
tcrit
value. Again, this can be accomplished using the function
tinv
at a 5%
signii cance level. h e function
tinv
yields the inverse of the
t
distribution
function with
na-nb-2
degrees of freedom at the 5% signii cance level. h is is
again a two-sample
t
-test, i.e., the means are not equal. Computing the two-
tailed critical
tcrit
value by entering 1-0.05/2 yields the upper (positive)
tcrit
value that we compare with the absolute value of the dif erence between
the means.
tcrit = tinv(1-0.05/2,na+nb-2)
tcrit =
1.9803
Since the
tcalc
value calculated from the data is now larger than the critical
tcrit
value, we can reject the null hypothesis and conclude that the means
are not identical at a 5% signii cance level. Alternatively, we can apply the
function
ttest2(x,y,alpha)
to the two independent samples
corg1
and
corg2
at an
alpha=0.05
or a 5% signii cance level. h e command
[h,p,ci,stats] = ttest2(corg1,corg2,0.05)
yields
h =
1