-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPlotter_Cause4copula_stat.R
447 lines (413 loc) · 26.6 KB
/
Plotter_Cause4copula_stat.R
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
#This is a plotter function to plot the outputs from Sim_Cause4copula_stat function written in Cause4copula.R
# Input :
# res : a big list which is the output from Sim_Cause4copula_stat function
Plotter_Cause4copula_stat<-function(res){
resloc<-res$resloc
method<-res$method
fcode<-res$fcode
corcoef_list<-res$corcoef_list
S_noise_mat<-res$S_noise_mat
K_noise_mat<-res$K_noise_mat
P_noise_mat<-res$P_noise_mat
S_pop_mat<-res$S_pop_mat
K_pop_mat<-res$K_pop_mat
P_pop_mat<-res$P_pop_mat
Corl_noise_mat<-res$Corl_noise_mat
Corl_pop_mat<-res$Corl_pop_mat
Coru_noise_mat<-res$Coru_noise_mat
Coru_pop_mat<-res$Coru_pop_mat
CorlmCoru_noise_mat<-res$CorlmCoru_noise_mat
CorlmCoru_pop_mat<-res$CorlmCoru_pop_mat
Pl_noise_mat<-res$Pl_noise_mat
Pl_pop_mat<-res$Pl_pop_mat
Pu_noise_mat<-res$Pu_noise_mat
Pu_pop_mat<-res$Pu_pop_mat
PlmPu_noise_mat<-res$PlmPu_noise_mat
PlmPu_pop_mat<-res$PlmPu_pop_mat
D2u_noise_mat<-res$D2u_noise_mat
D2u_pop_mat<-res$D2u_pop_mat
D2l_noise_mat<-res$D2l_noise_mat
D2l_pop_mat<-res$D2l_pop_mat
D2umD2l_noise_mat<-res$D2umD2l_noise_mat
D2umD2l_pop_mat<-res$D2umD2l_pop_mat
pval_S<-res$pval_S
pval_K<-res$pval_K
pval_P<-res$pval_P
pval_Corl<-res$pval_Corl
pval_Coru<-res$pval_Coru
pval_CorlmCoru<-res$pval_CorlmCoru
pval_Pl<-res$pval_Pl
pval_Pu<-res$pval_Pu
pval_PlmPu<-res$pval_PlmPu
pval_D2u<-res$pval_D2u
pval_D2l<-res$pval_D2l
pval_D2umD2l<-res$pval_D2umD2l
if(method=="spearman"){
xlabel<-"Spearman's Rho"
}else if(method=="kendall"){
xlabel<-"Kendall's Tau"
}else{
warning("specify method",immediate.=T,call.=T)
}
# Plotting Spearman correlation btw noise and pop copula
pdf(paste0(resloc,BiCopName(fcode,short=F),"_Spearman_vs_",xlabel,".pdf",sep=""),height=4,width=5)
op<-par(mar=c(3.5,4.5,2,3.5), mgp=c(1.9,0.5,0))
plot(corcoef_list,S_noise_mat[,2],cex=0.5,col="dimgrey",xlab=xlabel,ylab="Spearman",xlim=c(0,1),ylim=c(0,1),cex.lab=2,cex.axis=1.5)
segments(corcoef_list,S_noise_mat[,1],corcoef_list,S_noise_mat[,3],col='dimgrey')
bar_len<-0.02
segments(corcoef_list-bar_len,S_noise_mat[,1],corcoef_list+bar_len,S_noise_mat[,1],col='dimgrey')
segments(corcoef_list-bar_len,S_noise_mat[,3],corcoef_list+bar_len,S_noise_mat[,3],col='dimgrey')
#arrows(corcoef_list,S_noise_mat[,1],corcoef_list,S_noise_mat[,3],length=0.03, angle=90, code=3, col='dimgrey')
points(corcoef_list,S_pop_mat[,2],cex=0.5,col="black")
segments(corcoef_list,S_pop_mat[,1],corcoef_list,S_pop_mat[,3],col='black')
segments(corcoef_list-bar_len,S_pop_mat[,1],corcoef_list+bar_len,S_pop_mat[,1],col='black')
segments(corcoef_list-bar_len,S_pop_mat[,3],corcoef_list+bar_len,S_pop_mat[,3],col='black')
#arrows(corcoef_list,S_pop_mat[,1],corcoef_list,S_pop_mat[,3],length=0.03, angle=90, code=3, col='black')
points(corcoef_list,pval_S,col="black",pch=2)
lines(range(0,1),c(0.05,0.05),type='l',lty='dashed',col='black')
axis(side=4,col='black',col.axis="black",cex.axis=1.5)
mtext(side = 4, line = 2, 'p values', col='black',cex=2)
par(op)
dev.off()
# Plotting Kendall correlation btw noise and pop copula
pdf(paste0(resloc,BiCopName(fcode,short=F),"_Kendall_vs_",xlabel,".pdf",sep=""),height=4,width=5)
op<-par(mar=c(3.5,4.5,2,3.5), mgp=c(1.9,0.5,0))
plot(corcoef_list,K_noise_mat[,2],cex=0.5,col="dimgrey",xlab=xlabel,ylab="Kendall",xlim=c(0,1),ylim=c(0,1),cex.lab=2,cex.axis=1.5)
segments(corcoef_list,K_noise_mat[,1],corcoef_list,K_noise_mat[,3],col='dimgrey')
segments(corcoef_list-bar_len,K_noise_mat[,1],corcoef_list+bar_len,K_noise_mat[,1],col='dimgrey')
segments(corcoef_list-bar_len,K_noise_mat[,3],corcoef_list+bar_len,K_noise_mat[,3],col='dimgrey')
#arrows(corcoef_list,K_noise_mat[,1],corcoef_list,K_noise_mat[,3],length=0.03, angle=90, code=3, col='dimgrey')
points(corcoef_list,K_pop_mat[,2],cex=0.5,col="black")
segments(corcoef_list,K_pop_mat[,1],corcoef_list,K_pop_mat[,3],col='black')
segments(corcoef_list-bar_len,K_pop_mat[,1],corcoef_list+bar_len,K_pop_mat[,1],col='black')
segments(corcoef_list-bar_len,K_pop_mat[,3],corcoef_list+bar_len,K_pop_mat[,3],col='black')
#arrows(corcoef_list,K_pop_mat[,1],corcoef_list,K_pop_mat[,3],length=0.03, angle=90, code=3, col='black')
points(corcoef_list,pval_K,col="black",pch=2)
lines(range(0,1),c(0.05,0.05),type='l',lty='dashed',col='black')
axis(side=4,col='black',col.axis="black",cex.axis=1.5)
mtext(side = 4, line = 2, 'p values', col='black',cex=2)
par(op)
dev.off()
# Plotting Pearson correlation btw noise and pop copula
pdf(paste0(resloc,BiCopName(fcode,short=F),"_Pearson_vs_",xlabel,".pdf",sep=""),height=4,width=5)
op<-par(mar=c(3.5,4.5,2,3.5), mgp=c(1.9,0.5,0))
plot(corcoef_list,P_noise_mat[,2],cex=0.5,col="dimgrey",xlab=xlabel,ylab="Pearson",xlim=c(0,1),ylim=c(0,1),cex.lab=2,cex.axis=1.5)
segments(corcoef_list,P_noise_mat[,1],corcoef_list,P_noise_mat[,3],col='dimgrey')
segments(corcoef_list-bar_len,P_noise_mat[,1],corcoef_list+bar_len,P_noise_mat[,1],col='dimgrey')
segments(corcoef_list-bar_len,P_noise_mat[,3],corcoef_list+bar_len,P_noise_mat[,3],col='dimgrey')
#arrows(corcoef_list,P_noise_mat[,1],corcoef_list,P_noise_mat[,3],length=0.03, angle=90, code=3, col='dimgrey')
points(corcoef_list,P_pop_mat[,2],cex=0.5,col="black")
segments(corcoef_list,P_pop_mat[,1],corcoef_list,P_pop_mat[,3],col='black')
segments(corcoef_list-bar_len,P_pop_mat[,1],corcoef_list+bar_len,P_pop_mat[,1],col='black')
segments(corcoef_list-bar_len,P_pop_mat[,3],corcoef_list+bar_len,P_pop_mat[,3],col='black')
#arrows(corcoef_list,P_pop_mat[,1],corcoef_list,P_pop_mat[,3],length=0.03, angle=90, code=3, col='black')
points(corcoef_list,pval_P,col="black",pch=2)
lines(range(0,1),c(0.05,0.05),type='l',lty='dashed',col='black')
axis(side=4,col='black',col.axis="black",cex.axis=1.5)
mtext(side = 4, line = 2, 'p values', col='black',cex=2)
par(op)
dev.off()
# Plotting Corl of noise and pop copula
pdf(paste0(resloc,BiCopName(fcode,short=F),"_Corl_vs_",xlabel,".pdf",sep=""),height=4,width=5)
op<-par(mar=c(3.5,4.5,2,3.5), mgp=c(1.9,0.5,0))
plot(corcoef_list,Corl_noise_mat[,2],cex=0.5,col="dimgrey",xlab=xlabel,ylab=expression("Cor"["l"]),
cex.lab=2,cex.axis=1.5,
xlim=c(0,1),ylim=c(0,0.02+max(Corl_noise_mat[,2],Corl_pop_mat[,2])))
segments(corcoef_list,Corl_noise_mat[,1],corcoef_list,Corl_noise_mat[,3],col='dimgrey')
segments(corcoef_list-bar_len,Corl_noise_mat[,1],corcoef_list+bar_len,Corl_noise_mat[,1],col='dimgrey')
segments(corcoef_list-bar_len,Corl_noise_mat[,3],corcoef_list+bar_len,Corl_noise_mat[,3],col='dimgrey')
#arrows(corcoef_list,Corl_noise_mat[,1],corcoef_list,Corl_noise_mat[,3],length=0.03, angle=90, code=3, col='dimgrey')
points(corcoef_list,Corl_pop_mat[,2],cex=0.5,col="black")
segments(corcoef_list,Corl_pop_mat[,1],corcoef_list,Corl_pop_mat[,3],col='black')
segments(corcoef_list-bar_len,Corl_pop_mat[,1],corcoef_list+bar_len,Corl_pop_mat[,1],col='black')
segments(corcoef_list-bar_len,Corl_pop_mat[,3],corcoef_list+bar_len,Corl_pop_mat[,3],col='black')
#arrows(corcoef_list,Corl_pop_mat[,1],corcoef_list,Corl_pop_mat[,3],length=0.03, angle=90, code=3, col='black')
par(new = TRUE)
plot(corcoef_list,pval_Corl,col="black",type="p",axes = FALSE, bty = "n", xlab = "", ylab = "",xlim=c(0,1),ylim=c(0,1),pch=2)
lines(range(0,1),c(0.05,0.05),type='l',lty='dashed',col='black')
axis(side=4,col='black',col.axis="black",cex.axis=1.5)
mtext(side = 4, line = 2, 'p values', col='black',cex=2)
par(op)
dev.off()
# Plotting Coru of noise and pop copula
pdf(paste0(resloc,BiCopName(fcode,short=F),"_Coru_vs_",xlabel,".pdf",sep=""),height=4,width=5)
op<-par(mar=c(3.5,4.5,2,3.5), mgp=c(1.9,0.5,0))
plot(corcoef_list,Coru_noise_mat[,2],cex=0.5,col="dimgrey",xlab=xlabel,ylab=expression("Cor"["u"]),
cex.lab=2,cex.axis=1.5,
xlim=c(0,1),ylim=c(0,0.02+max(Coru_noise_mat[,2],Coru_pop_mat[,2])))
segments(corcoef_list,Coru_noise_mat[,1],corcoef_list,Coru_noise_mat[,3],col='dimgrey')
segments(corcoef_list-bar_len,Coru_noise_mat[,1],corcoef_list+bar_len,Coru_noise_mat[,1],col='dimgrey')
segments(corcoef_list-bar_len,Coru_noise_mat[,3],corcoef_list+bar_len,Coru_noise_mat[,3],col='dimgrey')
#arrows(corcoef_list,Coru_noise_mat[,1],corcoef_list,Coru_noise_mat[,3],length=0.03, angle=90, code=3, col='dimgrey')
points(corcoef_list,Coru_pop_mat[,2],cex=0.5,col="black")
segments(corcoef_list,Coru_pop_mat[,1],corcoef_list,Coru_pop_mat[,3],col='black')
segments(corcoef_list-bar_len,Coru_pop_mat[,1],corcoef_list+bar_len,Coru_pop_mat[,1],col='black')
segments(corcoef_list-bar_len,Coru_pop_mat[,3],corcoef_list+bar_len,Coru_pop_mat[,3],col='black')
#arrows(corcoef_list,Coru_pop_mat[,1],corcoef_list,Coru_pop_mat[,3],length=0.03, angle=90, code=3, col='black')
par(new = TRUE)
plot(corcoef_list,pval_Coru,col="black",type="p",axes = FALSE, bty = "n", xlab = "", ylab = "",xlim=c(0,1),ylim=c(0,1),pch=2)
lines(range(0,1),c(0.05,0.05),type='l',lty='dashed',col='black')
axis(side=4,col='black',col.axis="black",cex.axis=1.5)
mtext(side = 4, line = 2, 'p values', col='black',cex=2)
par(op)
dev.off()
# Plotting Corl - Coru of noise and pop copula
pdf(paste0(resloc,BiCopName(fcode,short=F),"_Corl-Coru_vs_",xlabel,".pdf",sep=""),height=4,width=5)
op<-par(mar=c(3.5,4.5,2,3.5), mgp=c(1.9,0.5,0))
plot(corcoef_list,CorlmCoru_noise_mat[,2],cex=0.5,col="dimgrey",xlab=xlabel,ylab=expression("Cor"["l"]-"Cor"["u"]),
cex.lab=2,cex.axis=1.5,
xlim=c(0,1),ylim=c(-0.15,0.15))
segments(corcoef_list,CorlmCoru_noise_mat[,1],corcoef_list,CorlmCoru_noise_mat[,3],col='dimgrey')
segments(corcoef_list-bar_len,CorlmCoru_noise_mat[,1],corcoef_list+bar_len,CorlmCoru_noise_mat[,1],col='dimgrey')
segments(corcoef_list-bar_len,CorlmCoru_noise_mat[,3],corcoef_list+bar_len,CorlmCoru_noise_mat[,3],col='dimgrey')
#arrows(corcoef_list,CorlmCoru_noise_mat[,1],corcoef_list,CorlmCoru_noise_mat[,3],length=0.03, angle=90, code=3, col='dimgrey')
points(corcoef_list,CorlmCoru_pop_mat[,2],cex=0.5,col="black")
segments(corcoef_list,CorlmCoru_pop_mat[,1],corcoef_list,CorlmCoru_pop_mat[,3],col='black')
segments(corcoef_list-bar_len,CorlmCoru_pop_mat[,1],corcoef_list+bar_len,CorlmCoru_pop_mat[,1],col='black')
segments(corcoef_list-bar_len,CorlmCoru_pop_mat[,3],corcoef_list+bar_len,CorlmCoru_pop_mat[,3],col='black')
#arrows(corcoef_list,CorlmCoru_pop_mat[,1],corcoef_list,CorlmCoru_pop_mat[,3],length=0.03, angle=90, code=3, col='black')
lines(range(0,1),c(0,0),type='l',lty='dotted',col='black')
par(new = TRUE)
plot(corcoef_list,pval_CorlmCoru,col="black",type="p",axes = FALSE, bty = "n", xlab = "", ylab = "",
xlim=c(0,1),ylim=c(0,1),pch=2)
lines(range(0,1),c(0.05,0.05),type='l',lty='dashed',col='black')
axis(side=4,col='black',col.axis="black",cex.axis=1.5)
mtext(side = 4, line = 2, 'p values', col='black',cex=2)
par(op)
dev.off()
# Plotting correlation between Corl - Coru of noise and pop copula
pdf(paste0(resloc,BiCopName(fcode,short=F),"_scatter_CorlmCoru_",xlabel,".pdf",sep=""),height=4,width=5)
op<-par(mar=c(4.5,6,2,2), mgp=c(3,0.5,0))
ylim1<-range(CorlmCoru_pop_mat[,1],CorlmCoru_pop_mat[,3])
xlim1<-range(CorlmCoru_noise_mat[,1],CorlmCoru_noise_mat[,3])
b_len<-diff(xlim1)/50
plot(CorlmCoru_noise_mat[,2],CorlmCoru_pop_mat[,2],cex=2,col="black",
xlab=expression("Cor"["l,input"]-"Cor"["u,input"]),
ylab=expression("Cor"["l,output"]-"Cor"["u,output"]),
cex.lab=2,cex.axis=1.5,
xlim=xlim1,ylim=ylim1)
segments(CorlmCoru_noise_mat[,2],CorlmCoru_pop_mat[,1],CorlmCoru_noise_mat[,2],CorlmCoru_pop_mat[,3],col='black')
segments(CorlmCoru_noise_mat[,2]-b_len,CorlmCoru_pop_mat[,1],CorlmCoru_noise_mat[,2]+b_len,CorlmCoru_pop_mat[,1],col='black')
segments(CorlmCoru_noise_mat[,2]-b_len,CorlmCoru_pop_mat[,3],CorlmCoru_noise_mat[,2]+b_len,CorlmCoru_pop_mat[,3],col='black')
segments(CorlmCoru_noise_mat[,1],CorlmCoru_pop_mat[,2],CorlmCoru_noise_mat[,3],CorlmCoru_pop_mat[,2],col='dimgrey')
segments(CorlmCoru_noise_mat[,1],CorlmCoru_pop_mat[,2]-b_len,CorlmCoru_noise_mat[,1],CorlmCoru_pop_mat[,2]+b_len,col='dimgrey')
segments(CorlmCoru_noise_mat[,3],CorlmCoru_pop_mat[,2]-b_len,CorlmCoru_noise_mat[,3],CorlmCoru_pop_mat[,2]+b_len,col='dimgrey')
dat<-data.frame(x1=CorlmCoru_noise_mat[,2],y1=CorlmCoru_pop_mat[,2])
mylm<-lm(y1~x1,data=dat)
abline(mylm,col="black")
lines(x=xlim1,y=ylim1,col="black",lty="dashed")
c<-cor.test(dat$x1,dat$y1,method = "pearson",alternative = "t")
mtext(paste0("Pearson = ",round(unname(c$estimate),3),", p = ",round(c$p.value,3),sep=""),cex=1.5,line=0.1)
par(op)
dev.off()
# Plotting Pl of noise and pop copula
pdf(paste0(resloc,BiCopName(fcode,short=F),"_Pl_vs_",xlabel,".pdf",sep=""),height=4,width=5)
op<-par(mar=c(3.5,4.5,2,3.5), mgp=c(1.9,0.5,0))
plot(corcoef_list,Pl_noise_mat[,2],cex=0.5,col="dimgrey",xlab=xlabel,ylab=expression("P"["l"]),
cex.lab=2,cex.axis=1.5,
xlim=c(0,1),ylim=c(0,0.01+max(Pl_noise_mat[,2],Pl_pop_mat[,2])))
segments(corcoef_list,Pl_noise_mat[,1],corcoef_list,Pl_noise_mat[,3],col='dimgrey')
segments(corcoef_list-bar_len,Pl_noise_mat[,1],corcoef_list+bar_len,Pl_noise_mat[,1],col='dimgrey')
segments(corcoef_list-bar_len,Pl_noise_mat[,3],corcoef_list+bar_len,Pl_noise_mat[,3],col='dimgrey')
#arrows(corcoef_list,Pl_noise_mat[,1],corcoef_list,Pl_noise_mat[,3],length=0.03, angle=90, code=3, col='dimgrey')
points(corcoef_list,Pl_pop_mat[,2],cex=0.5,col="black")
segments(corcoef_list,Pl_pop_mat[,1],corcoef_list,Pl_pop_mat[,3],col='black')
segments(corcoef_list-bar_len,Pl_pop_mat[,1],corcoef_list+bar_len,Pl_pop_mat[,1],col='black')
segments(corcoef_list-bar_len,Pl_pop_mat[,3],corcoef_list+bar_len,Pl_pop_mat[,3],col='black')
#arrows(corcoef_list,Pl_pop_mat[,1],corcoef_list,Pl_pop_mat[,3],length=0.03, angle=90, code=3, col='black')
par(new = TRUE)
plot(corcoef_list,pval_Pl,col="black",type="p",axes = FALSE, bty = "n", xlab = "", ylab = "",xlim=c(0,1),ylim=c(0,1),pch=2)
lines(range(0,1),c(0.05,0.05),type='l',lty='dashed',col='black')
axis(side=4,col='black',col.axis="black",cex.axis=1.5)
mtext(side = 4, line = 2, 'p values', col='black',cex=2)
par(op)
#op<-par(fig = c(0, 1, 0, 1), oma = c(0, 0, 0, 0), mar = c(0, 1, 0, 0), new = TRUE)
#plot(0, 0, type = "n", bty = "n", xaxt = "n", yaxt = "n")
#legend("top", c("noise copula","population copula", "p-value(paired t-test)"), col = c("dimgrey", "black", "black"),
# cex = 0.8, pch = c(16, 16, 1), xpd = TRUE, horiz = TRUE, inset = c(0,0),
# bty = "n")
#par(op)
dev.off()
# Plotting Pu of noise and pop copula
pdf(paste0(resloc,BiCopName(fcode,short=F),"_Pu_vs_",xlabel,".pdf",sep=""),height=4,width=5)
op<-par(mar=c(3.5,4.5,2,3.5), mgp=c(1.9,0.5,0))
plot(corcoef_list,Pu_noise_mat[,2],cex=0.5,col="dimgrey",xlab=xlabel,ylab=expression("P"["u"]),
cex.lab=2,cex.axis=1.5,
xlim=c(0,1),ylim=c(0,0.01+max(Pu_noise_mat[,2],Pu_pop_mat[,2])))
segments(corcoef_list,Pu_noise_mat[,1],corcoef_list,Pu_noise_mat[,3],col='dimgrey')
segments(corcoef_list-bar_len,Pu_noise_mat[,1],corcoef_list+bar_len,Pu_noise_mat[,1],col='dimgrey')
segments(corcoef_list-bar_len,Pu_noise_mat[,3],corcoef_list+bar_len,Pu_noise_mat[,3],col='dimgrey')
#arrows(corcoef_list,Pu_noise_mat[,1],corcoef_list,Pu_noise_mat[,3],length=0.03, angle=90, code=3, col='dimgrey')
points(corcoef_list,Pu_pop_mat[,2],cex=0.5,col="black")
segments(corcoef_list,Pu_pop_mat[,1],corcoef_list,Pu_pop_mat[,3],col='black')
segments(corcoef_list-bar_len,Pu_pop_mat[,1],corcoef_list+bar_len,Pu_pop_mat[,1],col='black')
segments(corcoef_list-bar_len,Pu_pop_mat[,3],corcoef_list+bar_len,Pu_pop_mat[,3],col='black')
#arrows(corcoef_list,Pu_pop_mat[,1],corcoef_list,Pu_pop_mat[,3],length=0.03, angle=90, code=3, col='black')
par(new = TRUE)
plot(corcoef_list,pval_Pu,col="black",type="p",axes = FALSE,
bty = "n", xlab = "", ylab = "",ylim=c(0,1),xlim=c(0,1),pch=2)
lines(range(0,1),c(0.05,0.05),type='l',lty='dashed',col='black')
axis(side=4,col='black',col.axis="black",cex.axis=1.5)
mtext(side = 4, line = 2, 'p values', col='black',cex=2)
par(op)
dev.off()
# Plotting Pl - Pu of noise and pop copula
pdf(paste0(resloc,BiCopName(fcode,short=F),"_Pl-Pu_vs_",xlabel,".pdf",sep=""),height=4,width=5)
op<-par(mar=c(3.5,4.5,2,3.5), mgp=c(1.9,0.5,0))
plot(corcoef_list,PlmPu_noise_mat[,2],cex=0.5,col="dimgrey",xlab=xlabel,ylab=expression("P"["l"]-"P"["u"]),
cex.lab=2,cex.axis=1.5,
xlim=c(0,1),ylim=c(-0.04,0.04))
segments(corcoef_list,PlmPu_noise_mat[,1],corcoef_list,PlmPu_noise_mat[,3],col='dimgrey')
segments(corcoef_list-bar_len,PlmPu_noise_mat[,1],corcoef_list+bar_len,PlmPu_noise_mat[,1],col='dimgrey')
segments(corcoef_list-bar_len,PlmPu_noise_mat[,3],corcoef_list+bar_len,PlmPu_noise_mat[,3],col='dimgrey')
#arrows(corcoef_list,PlmPu_noise_mat[,1],corcoef_list,PlmPu_noise_mat[,3],length=0.03, angle=90, code=3, col='dimgrey')
points(corcoef_list,PlmPu_pop_mat[,2],cex=0.5,col="black")
segments(corcoef_list,PlmPu_pop_mat[,1],corcoef_list,PlmPu_pop_mat[,3],col='black')
segments(corcoef_list-bar_len,PlmPu_pop_mat[,1],corcoef_list+bar_len,PlmPu_pop_mat[,1],col='black')
segments(corcoef_list-bar_len,PlmPu_pop_mat[,3],corcoef_list+bar_len,PlmPu_pop_mat[,3],col='black')
#arrows(corcoef_list,PlmPu_pop_mat[,1],corcoef_list,PlmPu_pop_mat[,3],length=0.03, angle=90, code=3, col='black')
lines(range(0,1),c(0,0),type='l',lty='dotted',col='black')
par(new = TRUE)
plot(corcoef_list,pval_PlmPu,col="black",type="p",axes = FALSE, bty = "n", xlab = "", ylab = "",
xlim=c(0,1),ylim=c(0,1),pch=2)
lines(range(0,1),c(0.05,0.05),type='l',lty='dashed',col='black')
axis(side=4,col='black',col.axis="black",cex.axis=1.5)
mtext(side = 4, line = 2, 'p values', col='black',cex=2)
par(op)
dev.off()
# Plotting correlation between Pl - Pu of noise and pop copula
pdf(paste0(resloc,BiCopName(fcode,short=F),"_scatter_PlmPu_",xlabel,".pdf",sep=""),height=4,width=5)
op<-par(mar=c(4.5,6,2,2), mgp=c(3,0.5,0))
ylim1<-range(PlmPu_pop_mat[,1],PlmPu_pop_mat[,3])
xlim1<-range(PlmPu_noise_mat[,1],PlmPu_noise_mat[,3])
b_len<-diff(xlim1)/50
plot(PlmPu_noise_mat[,2],PlmPu_pop_mat[,2],cex=2,col="black",
xlab=expression("P"["l,input"]-"P"["u,input"]),
ylab=expression("P"["l,output"]-"P"["u,output"]),
cex.lab=2,cex.axis=1.5,
xlim=xlim1,ylim=ylim1)
segments(PlmPu_noise_mat[,2],PlmPu_pop_mat[,1],PlmPu_noise_mat[,2],PlmPu_pop_mat[,3],col='black')
segments(PlmPu_noise_mat[,2]-b_len,PlmPu_pop_mat[,1],PlmPu_noise_mat[,2]+b_len,PlmPu_pop_mat[,1],col='black')
segments(PlmPu_noise_mat[,2]-b_len,PlmPu_pop_mat[,3],PlmPu_noise_mat[,2]+b_len,PlmPu_pop_mat[,3],col='black')
segments(PlmPu_noise_mat[,1],PlmPu_pop_mat[,2],PlmPu_noise_mat[,3],PlmPu_pop_mat[,2],col='dimgrey')
segments(PlmPu_noise_mat[,1],PlmPu_pop_mat[,2]-b_len,PlmPu_noise_mat[,1],PlmPu_pop_mat[,2]+b_len,col='dimgrey')
segments(PlmPu_noise_mat[,3],PlmPu_pop_mat[,2]-b_len,PlmPu_noise_mat[,3],PlmPu_pop_mat[,2]+b_len,col='dimgrey')
dat<-data.frame(x1=PlmPu_noise_mat[,2],y1=PlmPu_pop_mat[,2])
mylm<-lm(y1~x1,data=dat)
abline(mylm,col="black")
lines(x=xlim1,y=ylim1,col="black",lty="dashed")
c<-cor.test(dat$x1,dat$y1,method = "pearson",alternative = "t")
mtext(paste0("Pearson = ",round(unname(c$estimate),3),", p = ",round(c$p.value,3),sep=""),cex=1.5,line=0.1)
par(op)
dev.off()
# Plotting D2u of noise and pop copula
pdf(paste0(resloc,BiCopName(fcode,short=F),"_D2u_vs_",xlabel,".pdf",sep=""),height=4,width=5)
op<-par(mar=c(3.5,4.5,2,3.5), mgp=c(1.9,0.5,0))
plot(corcoef_list,D2u_noise_mat[,2],cex=0.5,col="dimgrey",xlab=xlabel,ylab=expression("D"[u]^2),
cex.lab=2,cex.axis=1.5,
xlim=c(0,1),ylim=c(0,0.0005+max(D2u_noise_mat[,2],D2u_pop_mat[,2])))
segments(corcoef_list,D2u_noise_mat[,1],corcoef_list,D2u_noise_mat[,3],col='dimgrey')
segments(corcoef_list-bar_len,D2u_noise_mat[,1],corcoef_list+bar_len,D2u_noise_mat[,1],col='dimgrey')
segments(corcoef_list-bar_len,D2u_noise_mat[,3],corcoef_list+bar_len,D2u_noise_mat[,3],col='dimgrey')
#arrows(corcoef_list,D2u_noise_mat[,1],corcoef_list,D2u_noise_mat[,3],length=0.03, angle=90, code=3, col='dimgrey')
points(corcoef_list,D2u_pop_mat[,2],cex=0.5,col="black")
segments(corcoef_list,D2u_pop_mat[,1],corcoef_list,D2u_pop_mat[,3],col='black')
segments(corcoef_list-bar_len,D2u_pop_mat[,1],corcoef_list+bar_len,D2u_pop_mat[,1],col='black')
segments(corcoef_list-bar_len,D2u_pop_mat[,3],corcoef_list+bar_len,D2u_pop_mat[,3],col='black')
#arrows(corcoef_list,D2u_pop_mat[,1],corcoef_list,D2u_pop_mat[,3],length=0.03, angle=90, code=3, col='black')
par(new = TRUE)
plot(corcoef_list,pval_D2u,col="black",type="p",axes = FALSE, bty = "n", xlab = "", ylab = "",
xlim=c(0,1),ylim=c(0,1),pch=2)
lines(range(0,1),c(0.05,0.05),type='l',lty='dashed',col='black')
axis(side=4,col='black',col.axis="black",cex.axis=1.5)
mtext(side = 4, line = 2, 'p values', col='black',cex=2)
par(op)
dev.off()
# Plotting D2l of noise and pop copula
pdf(paste0(resloc,BiCopName(fcode,short=F),"_D2l_vs_",xlabel,".pdf",sep=""),height=4,width=5)
op<-par(mar=c(3.5,4.5,2,3.5), mgp=c(1.9,0.5,0))
plot(corcoef_list,D2l_noise_mat[,2],cex=0.5,col="dimgrey",xlab=xlabel,ylab=expression("D"[l]^2),
cex.lab=2,cex.axis=1.5,
xlim=c(0,1),ylim=c(0,0.0005+max(D2l_noise_mat[,2],D2l_pop_mat[,2])))
segments(corcoef_list,D2l_noise_mat[,1],corcoef_list,D2l_noise_mat[,3],col='dimgrey')
segments(corcoef_list-bar_len,D2l_noise_mat[,1],corcoef_list+bar_len,D2l_noise_mat[,1],col='dimgrey')
segments(corcoef_list-bar_len,D2l_noise_mat[,3],corcoef_list+bar_len,D2l_noise_mat[,3],col='dimgrey')
#arrows(corcoef_list,D2l_noise_mat[,1],corcoef_list,D2l_noise_mat[,3],length=0.03, angle=90, code=3, col='dimgrey')
points(corcoef_list,D2l_pop_mat[,2],cex=0.5,col="black")
segments(corcoef_list,D2l_pop_mat[,1],corcoef_list,D2l_pop_mat[,3],col='black')
segments(corcoef_list-bar_len,D2l_pop_mat[,1],corcoef_list+bar_len,D2l_pop_mat[,1],col='black')
segments(corcoef_list-bar_len,D2l_pop_mat[,3],corcoef_list+bar_len,D2l_pop_mat[,3],col='black')
#arrows(corcoef_list,D2l_pop_mat[,1],corcoef_list,D2l_pop_mat[,3],length=0.03, angle=90, code=3, col='black')
par(new = TRUE)
plot(corcoef_list,pval_D2l,col="black",type="p",axes = FALSE, bty = "n", xlab = "", ylab = "",
xlim=c(0,1),ylim=c(0,1),pch=2)
lines(range(0,1),c(0.05,0.05),type='l',lty='dashed',col='black')
axis(side=4,col='black',col.axis="black",cex.axis=1.5)
mtext(side = 4, line = 2, 'p values', col='black',cex=2)
par(op)
dev.off()
# Plotting D2u - D2l of noise and pop copula
pdf(paste0(resloc,BiCopName(fcode,short=F),"_D2u-D2l_vs_",xlabel,".pdf",sep=""),height=4,width=5)
op<-par(mar=c(3.5,4.5,2,3.5), mgp=c(1.9,0.5,0))
plot(corcoef_list,D2umD2l_noise_mat[,2],cex=0.5,col="dimgrey",xlab=xlabel,ylab=expression("D"["u"]^2-"D"["l"]^2),
cex.lab=2,cex.axis=1.5,
xlim=c(0,1),ylim=c(-0.004,0.004))
#ylim=c(0,0.002+max(D2umD2l_noise_mat[,2],D2umD2l_pop_mat[,2])))
segments(corcoef_list,D2umD2l_noise_mat[,1],corcoef_list,D2umD2l_noise_mat[,3],col='dimgrey')
segments(corcoef_list-bar_len,D2umD2l_noise_mat[,1],corcoef_list+bar_len,D2umD2l_noise_mat[,1],col='dimgrey')
segments(corcoef_list-bar_len,D2umD2l_noise_mat[,3],corcoef_list+bar_len,D2umD2l_noise_mat[,3],col='dimgrey')
#arrows(corcoef_list,D2umD2l_noise_mat[,1],corcoef_list,D2umD2l_noise_mat[,3],length=0.03, angle=90, code=3, col='dimgrey')
points(corcoef_list,D2umD2l_pop_mat[,2],cex=0.5,col="black")
segments(corcoef_list,D2umD2l_pop_mat[,1],corcoef_list,D2umD2l_pop_mat[,3],col='black')
segments(corcoef_list-bar_len,D2umD2l_pop_mat[,1],corcoef_list+bar_len,D2umD2l_pop_mat[,1],col='black')
segments(corcoef_list-bar_len,D2umD2l_pop_mat[,3],corcoef_list+bar_len,D2umD2l_pop_mat[,3],col='black')
#arrows(corcoef_list,D2umD2l_pop_mat[,1],corcoef_list,D2umD2l_pop_mat[,3],length=0.03, angle=90, code=3, col='black')
lines(range(0,1),c(0,0),type='l',lty='dotted',col='black')
par(new = TRUE)
plot(corcoef_list,pval_D2umD2l,col="black",type="p",axes = FALSE, bty = "n", xlab = "", ylab = "",
xlim=c(0,1),ylim=c(0,1),pch=2)
lines(range(0,1),c(0.05,0.05),type='l',lty='dashed',col='black')
axis(side=4,col='black',col.axis="black",cex.axis=1.5)
mtext(side = 4, line = 2, 'p values', col='black',cex=2)
par(op)
dev.off()
# Plotting correlation between D2u - D2l of noise and pop copula
pdf(paste0(resloc,BiCopName(fcode,short=F),"_scatter_D2umD2l_",xlabel,".pdf",sep=""),height=4,width=5)
op<-par(mar=c(4.5,6,2,2), mgp=c(3,0.5,0))
ylim1<-range(D2umD2l_pop_mat[,1],D2umD2l_pop_mat[,3])
xlim1<-range(D2umD2l_noise_mat[,1],D2umD2l_noise_mat[,3])
plot(D2umD2l_noise_mat[,2],D2umD2l_pop_mat[,2],cex=2,col="black",
xlab=expression("D"["u,input"]^2-"D"["l,input"]^2),
ylab=expression("D"["u,output"]^2-"D"["l,output"]^2),
cex.lab=2,cex.axis=1.5,
xlim=xlim1,ylim=ylim1)
b_len<-diff(xlim1)/50
segments(D2umD2l_noise_mat[,2],D2umD2l_pop_mat[,1],D2umD2l_noise_mat[,2],D2umD2l_pop_mat[,3],col='black')
segments(D2umD2l_noise_mat[,2]-b_len,D2umD2l_pop_mat[,1],D2umD2l_noise_mat[,2]+b_len,D2umD2l_pop_mat[,1],col='black')
segments(D2umD2l_noise_mat[,2]-b_len,D2umD2l_pop_mat[,3],D2umD2l_noise_mat[,2]+b_len,D2umD2l_pop_mat[,3],col='black')
segments(D2umD2l_noise_mat[,1],D2umD2l_pop_mat[,2],D2umD2l_noise_mat[,3],D2umD2l_pop_mat[,2],col='dimgrey')
segments(D2umD2l_noise_mat[,1],D2umD2l_pop_mat[,2]-b_len,D2umD2l_noise_mat[,1],D2umD2l_pop_mat[,2]+b_len,col='dimgrey')
segments(D2umD2l_noise_mat[,3],D2umD2l_pop_mat[,2]-b_len,D2umD2l_noise_mat[,3],D2umD2l_pop_mat[,2]+b_len,col='dimgrey')
dat<-data.frame(x1=D2umD2l_noise_mat[,2],y1=D2umD2l_pop_mat[,2])
mylm<-lm(y1~x1,data=dat)
abline(mylm,col="black")
lines(x=xlim1,y=ylim1,col="black",lty="dashed")
c<-cor.test(dat$x1,dat$y1,method = "pearson",alternative = "t")
mtext(paste0("Pearson = ",round(unname(c$estimate),3),", p = ",round(c$p.value,3),sep=""),cex=1.5,line=0.1)
par(op)
dev.off()
#op2<-par(fig = c(0, 1, 0, 1), oma = c(0, 0, 0, 0), mar = c(0, 0, 0, 0), new = TRUE)
#plot(0, 0, type = "n", bty = "n", xaxt = "n", yaxt = "n")
#legend("top", c("noise","population", "p-value(paired t-test)"), col = c("dimgrey", "black", "black"),
# cex = 0.8, pch = c(16, 16, 1), xpd = TRUE, horiz = T, inset = c(0,0),
# bty = "n")
#par(op2)
pdf(paste0(resloc,"common_legend_cause4copula_stat.pdf",sep=""),height=1,width=15)
op<-par(fig = c(0, 1, 0, 1), oma = c(0, 0, 0, 0), mar = c(0, 0, 0, 0))
plot(0, 0, type = "n", bty = "n", xaxt = "n", yaxt = "n")
legend("center", c("input noise copula","model output copula", "p-value(paired t-test)"), col = c("grey70", "black", "black"),
pt.lwd=4.5, cex = 2.5, pch = c(1, 1, 2), xpd = TRUE, horiz = T, inset = c(0,0), text.col = c("grey70", "black", "black"),
bty = "n")
par(op)
dev.off()
}