-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfidence_interval.m
59 lines (48 loc) · 1.5 KB
/
confidence_interval.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
function [mean_out, lower_out, upper_out] = confidence_interval(data_in, methd, lvl)
flag_stdonly = 0;
if ~exist('methd', 'var')
methd = 'mean';
end
if ~exist('lvl', 'var')
lvl = 1.96;
end
if flag_stdonly
% data_in = 3dim matrix (channel x time x trial)
if numel(size(data_in))==3
if strcmp('mean', methd)
mean_out = nanmean(data_in,3);
else
mean_out = nanmedian(data_in,3);
end
upper_out = mean_out + (nanstd(data_in,[],3));% ./ (sqrt(size(data_in,3))));
lower_out = mean_out - (nanstd(data_in,[],3));% ./ (sqrt(size(data_in,3))));
else
if strcmp('mean', methd)
mean_out = nanmean(data_in);
else
mean_out = nanmedian(data_in);
end
upper_out = mean_out + (nanstd(data_in));% ./ (sqrt(size(data_in,1))));
lower_out = mean_out - (nanstd(data_in));% ./ (sqrt(size(data_in,1))));
end
else
% data_in = 3dim matrix (channel x time x trial)
if numel(size(data_in))==3
if strcmp('mean', methd)
mean_out = nanmean(data_in,3);
else
mean_out = nanmedian(data_in,3);
end
upper_out = mean_out + lvl*(nanstd(data_in,[],3) ./ (sqrt(size(data_in,3))));
lower_out = mean_out - lvl*(nanstd(data_in,[],3) ./ (sqrt(size(data_in,3))));
else
if strcmp('mean', methd)
mean_out = nanmean(data_in);
else
mean_out = nanmedian(data_in);
end
upper_out = mean_out + lvl*(nanstd(data_in) ./ (sqrt(size(data_in,1))));
lower_out = mean_out - lvl*(nanstd(data_in) ./ (sqrt(size(data_in,1))));
end
end
end