-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathtsRankmax.m
More file actions
69 lines (56 loc) · 2.08 KB
/
tsRankmax.m
File metadata and controls
69 lines (56 loc) · 2.08 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
function [ R ] = tsRankmax( X )
%tsRankmax Returns vector of one-based ranks for each element
% [ R ] = tsRankmax( X )
% For the groups of same element, the maximum rank is returned. This can
% be viewed as number of elements smaller or equal than given number.
% input:
% X - a variable of type double containing
% samples in data space
% output:
% R - A variable of type double containing
% ranks of each element in X
%
%
% M.H.Bahmanpour, 2025
%REFERENCES
% [1] Bahmanpour, M.H., Mentaschi, L., Tilloy, A., Vousdoukas, M.,
% Federico, I., Coppini, G., and Feyen, L., 2025,
% Transformed-Stationary EVA 2.0: A Generalized Framework for
% Non-stationary Joint Extreme Analysis (submitted to Hydrology and
% Earth System Sciences; Feb 2025)
% [2] Mentaschi, L., Vousdoukas, M. I., Voukouvalas, E., Sartini, L.,
% Feyen, L., Besio, G., & Alfieri, L. (2016). The
% transformed-stationary approach: a generic and simplified methodology
% for non-stationary extreme value analysis. Hydrology and Earth System
% Sciences, 20(9), 3527–3547. https://doi.org/10.5194/hess-20-3527-2016
% [3] Genest, C., Rémillard, B., Beaudoin, D., Goodness-of-fit tests
% for copulas: A review and a power study (Open Access),(2009) Insurance:
% Mathematics and Economics, 44 (2), pp. 199-213, doi:
% 10.1016/j.insmatheco.2007.10.005
% [4] Hofert, M., Kojadinovic, I., Mächler, M. & Yan, J. Elements of
% Copula Modeling with R (Springer, New York, 2018).
% [5] Berg, D. Bakken, H. (2006) Copula Goodness-of-fit Tests: A
% Comparative Study
%%%%%%%%%%%%%%%%%%%%%%
% setting the default parameters
% Number of elements
n = size(X, 1);
% Preallocate ranks vector
R = zeros(n, 1);
% Sort the array and retrieve indices
[S, I] = sort(X);
% Rank of the previous element
r = n;
% Value of the previous element
prev = S(n);
for i=n:-1:1
x = S(i);
if x == prev
R(I(i)) = r;
else
prev = x;
r = i;
R(I(i)) = r;
end
end
end