% LMcs090501_4th.m
% Larsen & Marx (2006,p. 583) Introduction to Mathematical Statistics, 4th
% Edition. Case Study 9.5.1 An example of CI's for a two-sample proportion
% Examples of two sample tests
% Written by Eugene.Gallagher@umb.edu 11/14/10, revised 11/17/10
Male =[4.9 5.4 5.0 5.5 5.4 6.6 6.3 4.3]';
Female=[4.8 5.3 3.7 4.1 5.6 4.0 3.6 5.0]';
fprintf('The mean male and female gradients were %6.4f and %6.4f, respectively\n',...
mean(Male),mean(Female))
% boxplot
[M,CM]=size(Male);[F,CF]=size(Female);
DATA=[Male;Female];
G=[zeros(M,1);ones(F,1)];
boxplot(DATA,G,'labels',{'Male','Female'});figure(gcf);pause
[H,P,CI,STATS] = ttest2(Male,Female,0.05,'both','equal');
fprintf(...
'\nThe 2-tailed p for Student''s t (=%4.2f, %d df) =%6.4f\n',...
STATS.tstat,STATS.df,P);
fprintf(...
'The lower and upper CI for the observed difference=%6.3f: [%6.3f %6.3f]\n',...
mean(Male)-mean(Female),CI(1),CI(2));
% Analyze with Wilcoxon ranks sum statistic, the major non-parametric alternative
% Student's t test. First with the normal approximation:
[Wilcoxpvalue,W,U]=wilcoxranksum(Male,Female);
fprintf(...
'\nThe 2-tailed p for Wilcoxon''s rank sum with large sample normal approx=%6.4f\n',...
Wilcoxpvalue);
% Do exact test with Wilcoxon ranksum
[Wilcoxexactp,W,U]=wilcoxranksum(Male,Female,1);
fprintf(...
'The 2-tailed exact p for Wilcoxon''s rank sum =%6.4f\n',...
Wilcoxexactp);
[D,Studp,t,df,RandPermP,CIpD,CIr]=randp2sample(Male,Female,1e4,1,0.05);
fprintf(...
'The 2-tailed p using random permutations of t =%6.4f\n',...
RandPermP);