Code covered by the BSD License  

Highlights from
tmcomptest

4.0

4.0 | 1 rating Rate this file 5 Downloads (last 30 days) File Size: 3.72 KB File ID: #15499

tmcomptest

by Antonio Trujillo-Ortiz

 

04 Jul 2007 (Updated 01 Aug 2007)

Tukey's HSD multiple comparisons test among proportions.

| Watch this File

File Information
Description

A statistical analysis used for count data is to compare the proportions of a binary outcome of interest for two or more groups.

This m-file it is an implemented alternative to the Marascuillo's test and identifies significant pairwise contrasts that this last one does not. If the previously Chi-square test results in a p-value smaller to an alpha-value, the results are deemed significant, the null hypothesis that all proportions are equal is rejected, and it is concluded that there is a significant difference between at least two of the proportions.

We can look at the pairwise comparisons obtained out of the Tukey's honest significant difference test employed. You will observe the comparisons identified as significant. We can compare up to 20 proportions.

Syntax: tmcomptest(X,alpha)
      
Input:
X - data matrix size rx2. Rows=number of groups. Column 1=number of successes or interested events. Column 2=number of trials.
alpha - significance level (default = 0.05)

Output:
- Complete Tukey's HSD multiple comparisons test among proportions table

Required Products Statistics Toolbox
MATLAB release MATLAB 7 (R14)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (1)
20 Jul 2007 Ali ÖZGÜL

Dear Antonio Trujillo-Ortiz;

I was supervised several cyclomatic complexity, m-lint error-codes and program algorithms for sub-program's running on profiler & tic-toc applications.

Good works, Best Regards.
----------

function tmcomptest(X,alpha)

clc
%Sub-function input's veriables control
switch nargin
    case {2} %nargin=2 [X,alpha]
    if isempty(X)== false && isempty(alpha)==false
        %Alpha's boundary condition controls
        if (alpha <= 0 || alpha >= 1)
            fprintf('Warning: Significance level error; must be 0 < alpha < 1 \n');
        return;
        end
    end
    case{1} %nargin=1 [X ,[] ]
        alpha=0.05;
    otherwise
        error('Input argument.s definiton error ,tmcomptest(X) or tmcomptest(X,alpha)');
end

s = X(:,1); %number of successes
t = X(:,2); %number of trials

is = (fix(s)==s);
it = (fix(t)==t);
if (sum(is) ~= length(s)) || (sum(it) ~= length(t)),
    error('Data is not in integer format. Please, check it.');
% return;
end

k = length(X);
%f = t-s;
if any((t-s) < 0)
   error('Number of events must be less than the number of trials. Check it.');
else if (k >=2) && (k<=20)
    fprintf('Selected conforming groups \n');
else
    error('Selected non-conforming groups; 2 < groups < 20');
    end
end

%% Arcsin transformation for each proportion
p = [];
for i = 1:k
    x = 0.5*(asin(...
                  sqrt(s(i)/(t(i)+1)) )+ ...
             asin(...
                  sqrt((s(i)+1)/(t(i)+1))) )*180/pi;
    p = [p x];
end

e = s; %**

CO = [];
dpx= [];
se = [];
for i = k:-1:2
    for s = i-1:-1:1
        if s ~= i
% Co = [i s];
            CO = [CO ; [i s] ];
% difp = abs(p(i)-p(s));
            dpx = [dpx; abs(p(i)-p(s)) ];
% sep = sqrt((410.35/(t(i)+0.5))+(410.35/(t(s)+0.5)));
            se = [se ; sqrt((410.35/(t(i)+0.5))+(410.35/(t(s)+0.5)))];
        end
    end
end

q = dpx./se;
      
%% Tukey's critical values calculate
%Tukey's critical values up to 20 groups for infinity degrees of freedom for
%alpha-value=0.01, 0.05 and 0.10
switch(alpha)

    case{0.01}
    c = [3.643 4.120 4.403 4.603 4.757 ...
         4.882 4.987 5.078 5.157 5.227 ...
         5.290 5.348 5.400 5.448 5.493 ...
         5.535 5.574 5.611 5.645];
    case{0.05};
    c = [2.772 3.314 3.633 3.858 4.030 ...
         4.170 4.286 4.387 4.474 4.552 ...
         4.622 4.685 4.743 4.796 4.845 ...
         4.891 4.934 4.974 5.012];
    case{0.10}
    c = [2.326 2.902 3.240 3.478 3.661 ...
         3.808 3.931 4.037 4.129 4.211 ...
         4.285 4.351 4.412 4.468 4.519 ...
         4.568 4.612 4.654 4.694];
end

qc = c(k-1);

%% NS and S selected
Ds = [];
for i = 1:size(CO,1);
    if (q(i) >= qc);
        ds = ' S';
    else % (q(i) < qc);
        ds = 'NS';
    end;
    Ds = [Ds ; ds];
end;

%Scaler applications
qc = ones(size(q))*qc;

ss = 1:k;
ps = e./t;%**
disp(' ');
disp('Group proportions of the interested events are:');
disp('-------------------------------------------');
disp('Group Proportions');
disp('-------------------------------------------');
fprintf(' %d %17.4f\n',[ss',ps].');
disp('-------------------------------------------');
disp(' ');
fprintf('Tukey''s multiple comparisions test among proportions, k = %.i\n', k);
disp('-------------------------------------------------------------------------');
disp(' Comparision Difference* SE q qc Decision');
disp('-------------------------------------------------------------------------');
for ml=1:k*((k-1)/2)
    fprintf(' %d %d %11.4f %6.3f %4.3f %4.3f %s\n', ...
        CO(ml,1),CO(ml,2),dpx(ml),se(ml),q(ml),qc(ml,:),Ds(ml,:));
end;
disp('-------------------------------------------------------------------------');
fprintf('With a given significance level of:% 3.2f\n', alpha);
disp('The multiple comparisions can be significant (S) or not significant (NS).');
disp('* After asin transformation of proportions.');

return,

Please login to add a comment or rating.
Updates
06 Jul 2007

It was added an appropriate format to cite this file.

06 Jul 2007

Text was improved.

09 Jul 2007

Text was improved.

01 Aug 2007

Text was improved.

Tag Activity for this File
Tag Applied By Date/Time
statistics Antonio Trujillo-Ortiz 22 Oct 2008 09:18:19
probability Antonio Trujillo-Ortiz 22 Oct 2008 09:18:19
proportions Antonio Trujillo-Ortiz 22 Oct 2008 09:18:19
multiple comparisions Antonio Trujillo-Ortiz 22 Oct 2008 09:18:19
pairwise Antonio Trujillo-Ortiz 22 Oct 2008 09:18:19
tukeys test Antonio Trujillo-Ortiz 22 Oct 2008 09:18:19
hsd Antonio Trujillo-Ortiz 22 Oct 2008 09:18:19
posthoc Antonio Trujillo-Ortiz 22 Oct 2008 09:18:19

Contact us at files@mathworks.com