-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpChiBar.m
79 lines (67 loc) · 1.99 KB
/
pChiBar.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
function ChiBar=pChiBar(X,NepVct,nBS);
%function ChiBar=pChiBar(X,NepVct,nBS);
%
%PhJ 20210811
%
%Estimate chibar(u) statistic from a bivariate sample
%
% X n x 2 bivariate sample
% NepVct p x 1 vector of marginal non-exceedance probabilities at which to evaluate ChiBar(u)
% nBS 1 x 1 number of bootstrap resamples (first is always the original sample)
%
% ChiBar nBS x p values of ChiBar for nBS bootstrap resamples and p thresholds
%
%The calculation is as follows
% 1. Estimate ChiBar(u) directly from its definition
% ChiBar(u) = [2 log(Pr(U>u)) / log(Pr(U>u, V>u))] - 1
% where U and V are uniform-scale versions of X and Y
% ie U = F_X(X) and V=F_Y(Y) with F_X and F_Y estimated empirically from ranks
%
%Basics
% If ChiBar(inf)=1 => Asymptotic Dependence
% Then use Chi to describe AD further
%
% If Chi(inf)=0 => Asymptotic Independence
% Then use ChiBar(inf) to describe AI further
%
% See http://www.lancs.ac.uk/~jonathan/EKJ11.pdf for basics
% See http://www.lancs.ac.uk/~jonathan/OcnEng10.pdf Section 4 for discussion on asymptotic properties
% of asymmetric logistic and Normal
if nargin==0;
X=randn(1000,2);
NepVct=(0.7:0.01:0.99)';
nBS=50;
end;
n=size(X,1);
p=size(NepVct,1);
% Estimate Eta(u)
ChiBar=nan(nBS,p);
for iB=1:nBS;
% Create bootstrap resample
if iB==1;
tX=X;
else;
I=(1:n)';
tI=randsample(I,n,1);
tX=X(tI,:);
end;
% Estimate empirical quantiles
tR=pRnk(tX);
tU=(tR+0.5)/(n+1);
% Define threshold (this is just NEP because we're on uniform scale)
Thr=NepVct;
% Loop over thresholds
for j=1:p;
% Direct calculation of ChiBar
u=Thr(j); % threshold
tDnm=log(sum(tU(:,1)>u & tU(:,2)>u)/n); % log(Pr(U>u, V>u))
ChiBar(iB,j)=(2*log(1-u)/tDnm)-1;
end;
end;
if nargin==0;
clf;hold on;
plot(NepVct,ChiBar(1,:)','ko-')
plot(NepVct,quantile(ChiBar,0.025),'k:')
plot(NepVct,quantile(ChiBar,0.975),'k:')
end;
return;