-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFind_CO_by_IT.m
72 lines (71 loc) · 1.9 KB
/
Find_CO_by_IT.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
function K = Find_CO_by_IT(C,Len,X,Latent_Number,Cov_M,alpha)
%Find the causal order by Independent test
Tem_L=1:Latent_Number;
K=[];
method='Sta'; % Default method
% method='P_value'; % One may also use this method
Iter=0;
while 1
B=[];
P=[];
S=[];
LLL=length(Tem_L);
B=zeros(LLL,LLL);
P=zeros(LLL,LLL);
S=zeros(LLL,LLL);
Iter=Iter+1;
for i=1:LLL
P_X=[];
P_Z=[];
for k=1:length(Len(Tem_L(i),:))
Tem_C_X=C{Tem_L(i),k};
P_X=[P_X Tem_C_X(1:Len(Tem_L(i),k))];
if k==1
P_Z=Tem_C_X(Len(Tem_L(i),k)+1:end);
else
P_Z=[P_Z Tem_C_X(Len(Tem_L(i),k)+1:2*Len(Tem_L(i),k))];
end
end
Tem_P_X=[];
Tem_All_P=[];
for j=1:LLL
if i~=j
Tem_C_Z=C{Tem_L(j),1};
Tem_P_X=[Tem_C_Z(1,1) P_X];
%Test P_Z-->P_X
[Bolean,PP,Statistic]= GIN_Condition_Test(X,Tem_P_X,P_Z,Cov_M,alpha);
if Bolean==1
B(i,j)=1;%i-->j
end
Tem_All_P=[Tem_All_P; PP];
[~,Fisher_pval]= FisherTest(PP,alpha);
P(i,j)=Fisher_pval;
%
S(i,j)=Statistic;
All_P_value{i,j,Iter}=PP;
end
end
end
switch method
case 'P_value'
P_sum=sum(P,2);%
[P_a,P_b]=max(P_sum);
K=[ K Tem_L(P_b)];
Tem_L(P_b)=[];
case 'Sta'
S_sum=sum(S,2);
[S_a,S_b]=max(S_sum);
K=[K Tem_L(S_b)];
Tem_L(S_b)=[];
end
if LLL==2
K=[K Tem_L];
break;
end
%update the CLuster
for kkk=Tem_L
C{kkk,length(K)+1}=C{K(end),1};
Len(kkk,length(K)+1)=Len(K(end),1);
end
end
end