-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstats_analyze.m
65 lines (54 loc) · 1.77 KB
/
stats_analyze.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
function [m, v, cit, ciw, sw, sk] = stats_analyze(data, alpha)
% STATS_ANALYZE Statistically analyze samples of focal measures, i.e.
% samples of statistical summaries taken from simulation output.
%
% [m, v, cit, ciw, sw, sk] = STATS_ANALYZE(data, alpha)
%
% Parameters:
% data - Data to analyze, n x m matrix, n observations, m focal measures.
% alpha - Significance level for confidence intervals and Shapiro-Wilk
% test.
%
% Returns:
% m - Vector of m means.
% v - Vector of m variances.
% cit - m x 2 matrix of t-confidence intervals.
% ciw - m x 2 matrix of Willink confidence intervals.
% sw - Vector of m p-values of the Shappiro-Wilk test.
% sk - Vector of m skewnesses.
%
% Copyright (c) 2016 Nuno Fachada
% Distributed under the MIT License (See accompanying file LICENSE or copy
% at http://opensource.org/licenses/MIT)
%
% How many statistical summaries?
nssumms = size(data, 2);
% Allocate space for function outputs
m = zeros(nssumms, 1);
v = zeros(nssumms, 1);
cit = zeros(nssumms, 2);
ciw = zeros(nssumms, 2);
sw = zeros(nssumms, 1);
sk = zeros(nssumms, 1);
% Cycle through statistical summaries
for i = 1:nssumms
% Get all observations for current statistical summary
cdat = data(:, i);
% Find mean, variance and skewness
m(i) = mean(cdat);
v(i) = var(cdat);
sk(i) = skewness(cdat);
% If variance is not zero...
if v(i) > 0
% ...determine confidence intervals...
cit(i, :) = ci_t(cdat, alpha);
ciw(i, :) = ci_willink(cdat, alpha);
% ...and perform the Shapiro-Wilk normality test.
[~, sw(i)] = swtest(cdat);
else
% ...otherwise
cit(i, :) = [m(i) m(i)];
ciw(i, :) = [m(i) m(i)];
sw(i) = NaN;
end;
end;