-
Notifications
You must be signed in to change notification settings - Fork 1
/
spem.m
30 lines (25 loc) · 870 Bytes
/
spem.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
function spem = spem(x, y)
% Logical indexing for valid values
index = ~(isnan(x) | isnan(y));
validX = x(index);
validY = y(index);
% Alpha (Spearman Rank Correlation)
rs = corr(validY, validX, 'Type', 'Spearman');
% Beta (Coefficient of Variation Ratio)
meanY = mean(y(:), 'omitnan');
meanX = mean(x(:), 'omitnan');
stdY = std(y(:), 'omitnan');
stdX = std(x(:), 'omitnan');
if meanX == 0 || stdY == 0 || stdX == 0
gamma = 0;
else
gamma = (stdX / meanX) / (stdY / meanY);
end
% Gamma (Z-Score Difference)
zDiff = ((x - meanX) / stdX) - ((y - meanY) / stdY);
alpha = 1 - sqrt(mean(zDiff(:).^2, 'omitnan'));
% SPEM
% spem = 1 - sqrt((rs - 1)^2 + (gamma - 1)^2 + (alpha - 1)^2);
% Bounded SPEM
spem = exp(-sqrt((rs - 1)^2 + (gamma - 1)^2 + (alpha - 1)^2));
end