-
Notifications
You must be signed in to change notification settings - Fork 6
/
pseudoObservations.m
47 lines (39 loc) · 1.07 KB
/
pseudoObservations.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
function [ U ] = pseudoObservations( X )
%PSEUDOOBSERVATIONS Uniforms input sample to pseudo-observations.
% Based on empirical CDF function described in [1]. We use n+1 for
% division to keep empirical CDF lower than 1.
%
% References:
% [1] Berg, D. Bakken, H. (2006) Copula Goodness-of-fit Tests: A
% Comparative Study
[n, d] = size(X);
U = zeros(n, d);
for i=1:d
U(:,i) = rankmax(X(:,i)) / (n + 1);
end
end
function [ R ] = rankmax( X )
%RANKMAX Returns vector of one-based ranks for each element
% 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.
% 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