-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPerformStats.m
executable file
·44 lines (39 loc) · 1.35 KB
/
PerformStats.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
function [h,P,stats] = PerformStats(X,Group,alpha)
% Perform Kruskal Wallis and Nemenyi test on the dataset with the provided
% alpha
% [h,p,stats] = PerformStats(X,Group,alpha)
%
% Inputs: 1) X - observations [vector]
% 2) Group - group number for each observation [vector]
% 3) alpha. Valid alpha values are:
% [0.5, 0.2, 0.1, 0.05, 0.02, 0.01, 0.005, 0.002, .001]
%
% Outputs: 1) h from Kruskal Wallis test
% h=0 implies failure to reject null hypothesis
% h=1 implies that the null hypothesis is rejected
% 2) p-value from Kruskal Wallis test for the null hypothesis
% 3) Multiple comparison table from Nemenyi test (cell array)
%
% Author: Dinesh Natesan
%
if nargin == 2
alpha = 0.05;
end
% Split vector into subvectors and remove NaN's if there are any.
[u_groups, ~, u_group_no] = unique(Group);
data = cell(length(u_groups),1);
for i = 1:size(X,1)
if (isnan(X(i,1))~= 1)
data{u_group_no(i,1),1} = [data{u_group_no(i,1),1};X(i,1)];
end
end
% Rank the obtained data.
[rankedData,tiedNums] = rankData(data);
% Analysis of variance
[h,P] = kWallis(rankedData,tiedNums,alpha);
fprintf('\nHypothesis = %d; p = %f \n',h,P);
% Post-hoc analysis - Tukey test
[stats] = nemenyi(rankedData,tiedNums,alpha);
stats.X = X;
stats.Group = Group;
end