-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGroup1Exe3Fun1.m
More file actions
55 lines (41 loc) · 1.55 KB
/
Copy pathGroup1Exe3Fun1.m
File metadata and controls
55 lines (41 loc) · 1.55 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
function [p_parametric, p_bootstrap] = Group1Exe3Fun1(X_Year, X)
% Liouliakis Nikolaos AEM: 10058
% Panagiotis Syskakis AEM: 10045
arguments
% Make inputs a row vector
X_Year (1,:) {mustBeNumeric}
X (1,:) {mustBeNumeric}
end
% Check inputs have the same size
if( length(X) ~= length(X_Year) )
% Crash
error("In function Group1Exe3Fun1 input vectors do not have the same length");
end
% Find first discontinuity in first vector
discont = find(diff(X_Year)~=1, 1);
if(isempty(discont))
error("No discontinuity found in 'Year' data");
end
% Split data of 2nd vector
X1 = X(1:discont);
X2 = X(discont+1:end);
% Remove NaN from input
X1 = X1(~isnan(X1));
X2 = X2(~isnan(X2));
% If all of them are NaN RIP and return NaN
if( isempty(X1) || isempty(X2))
p_parametric = NaN;
p_bootstrap = NaN;
warning("One of the vectors after the split is empty (or has only Nan). (Return values are NaN)");
return
end
% Do parametric method to find p-value
[~, p_parametric, ~] = ttest2(X1, X2);
% Do permutation method (with replacement)
B = 1000;
means1 = bootstrp(B, @mean, X1,'Options',statset('UseParallel',true));
means2 = bootstrp(B, @mean, X2,'Options',statset('UseParallel',true));
stat = means2-means1;
% Returns the p-value for the boostrap values (for 0 to be inside)
[~ ,p_bootstrap , ~] = Group1Exe3Fun2( stat );
end