-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstat_statTestCollection.m
More file actions
95 lines (68 loc) · 3.77 KB
/
stat_statTestCollection.m
File metadata and controls
95 lines (68 loc) · 3.77 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
% Calculates mean, SD, etc. here
function statOut = stat_statTestCollection(vecConc, x1, x2, colHeader, statOut, statFuncPath, shapWilk_pThr, bartlett_pThr, handles)
% modify the code if you start feeding matrices here instead of vectors
currDir = cd;
% get the size of the input
% vecConc
% colHeader
% statOut
vecConc_nonNan = vecConc(~isnan(vecConc));
n = length(vecConc_nonNan); % length of non-NaN value vector
sizeIn = size(vecConc);
x1 = x1(~isnan(x1));
x2 = x2(~isnan(x2));
%% BASIC ONES
% just add lines here and store it to the structure if you want to
% calculate something more
statOut.mean = nanmean(vecConc);
statOut.median = nanmedian(vecConc);
statOut.SD = nanstd(vecConc);
% We use mainly 3rd party implementations of the statistical tests
cd(statFuncPath)
vecConc_nonNan = vecConc(~isnan(vecConc));
%% STATISTICAL TESTS
%% ANOVA
% If Data are normal (Gaussian) and deviations are homogeneous then you can do an ANOVA
% --> significant if p < 0.05
if statOut.shapWilk_W(1) < 1 && statOut.btestOut_P <= bartlett_pThr
% The ANOVA test makes the following assumptions about the data in X:
% All sample populations are normally distributed.
% All sample populations have equal variance.
% All observations are mutually independent.
% the Matlab Statistics Toolbox
alpha = handles.anova_pThreshold;
X = vecConc;
[statOut.anovaP, statOut.anovaTable, statOut.anovaStats] = anova1(X, [], 'off');
% Notches in the boxplot provide a test of group medians
% (see boxplot) different from the F test for means in
% the ANOVA table '
else
statOut.anovaP = NaN;
statOut.anovaTable = NaN;
statOut.anovaStats = NaN;
end
%% t-Test
alpha = handles.student_pThreshold;
[statOut.tTest_h, statOut.tTest_p, statOut.tTest_ci, statOut.tTest_stats] = ttest2(x1,x2,alpha);
% statOut.tTest_h = [];
% statOut.tTest_p = [];
%% Kruskal-Wallis test
X = vecConc;
[statOut.kruskWallisP, statOut.kruskWallisTable, statOut.kruskWallisStats] = kruskalwallis(X, [], 'off');
%% Wilcoxon-Mann-Whithney Test, unpaired sample
% --> significant if p < 0.05
% We use Giuseppe Cardillo's code for this, same as RANKSUM
% in MATLAB, % http://www.mathworks.com/matlabcentral/fileexchange/25830
dispFullResultsFlag = 0;
statOut.mww_Stats = mwwtest(x1,x2,dispFullResultsFlag);
% In mwwtest the method is determined automatically, so we
% use the same method for the ransum -function as well
if strcmp(statOut.mww_Stats.method, 'Normal approximation') == 1
handles.wilcox_method = 'approximate';
else
handles.wilcox_method = 'exact';
end
% RANKSUM (Matlab Statistics Toolbox)
[statOut.rankSum_P, statOut.rankSum_H, statOut.rankSumStats] = ranksum(x1,x2,'alpha',handles.wilcox_pThreshold,'method',handles.wilcox_method);
% check why NaNs are coming out
cd(currDir)