-
Notifications
You must be signed in to change notification settings - Fork 1
/
main_GenerateMSFigures.r
1264 lines (991 loc) · 67.7 KB
/
main_GenerateMSFigures.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
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
## Organize Manuscript Figures ###
#### Kostas Lagogiannis 2019
## \brief Make a scipt clarifying the script files used to produce each figure Used in the MS
##Fig 1 Epxperimental TimeLine: manually designed Inkscape
### Fig 2A ####
## The kinematics was produced by selecting one of the figure produced
## from Hunt event analysis loop in : runHuntEpisodeAnalysis.r
##
### Fig 2B ####
##
#source("Stats/stat_HuntRateInPreyRange.R")
#source("Stats/stat_HuntDuration.R")
### Fig 3 ####
#source("Stats/stat_HuntEfficiency.r")
#source("Datalabelling/main_MeasureLengthBlind.r")
### Fig 4 ####
#source("DataLabelling/plotLabelledDataResults.R")
#source("Stats/stat_CaptureSpeedVsDistanceToPrey.R")
### Fig 5 ####
#source("Stats/stat_LinRegression_TurnVsBearing.R")
## Fig 6 clustering Speed, TurnRatio and Distance to Prey using 3D 2xGaussian mixture method####
#source("Stats/stat_ClusterCaptureSpeedVsUndershootAndDistance.r")
### Fig 7 Show Covariance using Gaussian 3D (not clustering on capture speed) model - ####
# The Covariance plots are in the original model file:
#source("Stats/stat_3DLarvaGroupBehaviour.r")
library(tools)
library(RColorBrewer);
library("MASS");
library(extrafont) ##For F
library(mvtnorm)
library(boot) ## BootStrapping
library(ggplot2) ##install.packages("ggplot2")
library(ggExtra)## install.packages("ggExtra") ##devtools::install_github("daattali/ggExtra").
library(cowplot)
library(ggpubr) ##install.packages("ggpubr")
source("config_lib.R")
#setEnvFileLocations("OFFICE") #OFFICE,#LAPTOP HOME
source("DataLabelling/labelHuntEvents_lib.r")
source("Stats/stat_InformationTheoryAndCorrelations_bootstrap_lib.r")
####################
#source("TrackerDataFilesImport.r")
### Hunting Episode Analysis ####
###Used for drawing contour in ggplot -
## Draw the model fit above the cluster points
getFastClusterGrid <- function(drawMCMC)
{
### Add the cluster contours ###
xran <- seq(0,0.8,0.05) ##Distance Grid
yran <- seq(0,70,1) ##Speed Grid
##Example Code for PLotting Inferred Multivariate Cluster
nsteps <- NROW(drawMCMC$mID[,,1][1,])
mat_cov_fast <- rowMeans(drawMCMC$cov[2,,,(nsteps-1000):nsteps,1],dim=2) ##Average over samples
mat_mu <- rowMeans(drawMCMC$mu[,,(nsteps-1000):nsteps,1],dim=2)
#valGrid <- matrix( expand.grid(distance=xran,speed=yran),nrow=NROW(xran),ncol=NROW(yran) )
valGrid <- expand.grid(distance=xran,speed=yran)
#matrix(valGrid$distance,ncol=NROW(xran))
cluster_z <- mvtnorm::dmvnorm(valGrid,mean=mat_mu[2,],sigma=mat_cov_fast )
cluster_fast <- cbind(valGrid,cluster_z, factor(rep(16,NROW(valGrid) ),levels=c(1,16),labels=c("slow","fast") ) )
names(cluster_fast) <- c("DistanceToPrey", "CaptureSpeed", "Density","Cluster")
return(cluster_fast)
}
###Used for drawing contour in ggplot
getSlowClusterGrid <- function(drawMCMC)
{
### Add the cluster contours ###
xran <- seq(0,0.8,0.05) ##Distance Grid
yran <- seq(0,70,1) ##Speed Grid
##Example Code for PLotting Inferred Multivariate Cluster
nsteps <- NROW(drawMCMC$mID[,,1][1,])
mat_cov_slow <- rowMeans(drawMCMC$cov[1,,,(nsteps-1000):nsteps,1],dim=2) ##Average over samples
mat_mu <- rowMeans(drawMCMC$mu[,,(nsteps-1000):nsteps,1],dim=2)
#valGrid <- matrix( expand.grid(distance=xran,speed=yran),nrow=NROW(xran),ncol=NROW(yran) )
valGrid <- expand.grid(distance=xran,speed=yran)
#matrix(valGrid$distance,ncol=NROW(xran))
cluster_z <- mvtnorm::dmvnorm(valGrid,mean=mat_mu[1,],sigma=mat_cov_slow )
cluster_slow <- cbind(valGrid,cluster_z, factor(rep(1,NROW(valGrid) ),levels=c(1,16),labels=c("slow","fast") ) )
names(cluster_slow) <- c("DistanceToPrey", "CaptureSpeed", "Density","Cluster")
return(cluster_slow)
}
## Used for PCA
standardizeHuntData <- function(datCapStat)
{
within( datCapStat,{
###Assume split in High Low Values is around mean
Efficiency_norm <- (Efficiency-mean(Efficiency))/sd(Efficiency)
HuntPower_norm <- (HuntPower-mean(HuntPower)) /sd(HuntPower)
CaptureSpeed_norm <-(CaptureSpeed-mean(CaptureSpeed))/sd(CaptureSpeed)
DistSpeed_norm <- (DistanceToPrey*CaptureSpeed -mean(DistanceToPrey*CaptureSpeed))/sd(DistanceToPrey*CaptureSpeed)
DistanceToPrey_norm <- (DistanceToPrey-mean(DistanceToPrey))/sd(DistanceToPrey)
Undershoot_norm <- (Undershoot-1)/sd(Undershoot)
##Use Centre As The Mean Of The Most Efficient Hunters
TimeToHitPrey_norm <- (FramesToHitPrey/G_APPROXFPS - mean(datCapStat[datCapStat$Efficiency >0.5,]$FramesToHitPrey/G_APPROXFPS) ) /sd(FramesToHitPrey/G_APPROXFPS)
DistUnder_norm <- (DistanceToPrey_norm*Undershoot_norm - mean(DistanceToPrey_norm*Undershoot_norm)) /sd(DistanceToPrey_norm*Undershoot_norm)
})
}
datTrackedEventsRegister <- readRDS( paste(strDataExportDir,"/setn_huntEventsTrackAnalysis_Register_ToValidate.rds",sep="") ) ## THis is the Processed Register File On
#lMotionBoutDat <- readRDS(paste(strDataExportDir,"/huntEpisodeAnalysis_MotionBoutData_SetC.rds",sep="") ) #Processed Registry on which we add )
#lEyeMotionDat <- readRDS(file=paste(strDataExportDir,"/huntEpisodeAnalysis_EyeMotionData_SetC",".rds",sep="")) #
lFirstBoutPoints <- readRDS(file=paste(strDataExportDir,"/huntEpisodeAnalysis_FirstBoutData_wCapFrame_Validated.rds",sep="")) ##Original :huntEpisodeAnalysis_FirstBoutData_Validated
#### Plot Raw Capture Data Indicating Low/High Speed Clustering for each
### Load Pre Calc RJAgs Model Results
## stat_CaptSpeedVsDistance_RJags.RData ##stat_CaptSpeedCluster_RJags.RData
load(file =paste(strDataExportDir,"stat_CaptSpeedVsDistance_RJags.RData",sep=""))
##Calc Model Covariance
ntail <- 1500
fastClusterCovarSamples<-list()
fastClusterCovarSamples$LF <-tail(draw_LF$rho[2,,],ntail)
fastClusterCovarSamples$NF <-tail(draw_NF$rho[2,,],ntail)
fastClusterCovarSamples$DF <-tail(draw_DF$rho[2,,],ntail)
fastClusterCovarSamples$LFvsDF <- tail(fastClusterCovarSamples$LF , ntail)- tail(fastClusterCovarSamples$DF,ntail)
fastClusterCovarSamples$LFvsNF <- tail(fastClusterCovarSamples$LF , ntail)- tail(fastClusterCovarSamples$NF,ntail)
#### LOAD Capture First-Last Bout hunting that include the cluster classification - (made in stat_CaptureSpeedVsDistanceToPrey)
datCapture_NL <- readRDS(file=paste(strDataExportDir,"/huntEpisodeAnalysis_FirstBoutData_wCapFrame_NL_2Dclustered.rds",sep=""))
datCapture_LL <- readRDS(file=paste(strDataExportDir,"/huntEpisodeAnalysis_FirstBoutData_wCapFrame_LL_2Dclustered.rds",sep=""))
datCapture_DL <- readRDS(file=paste(strDataExportDir,"/huntEpisodeAnalysis_FirstBoutData_wCapFrame_DL_2Dclustered.rds",sep=""))
datHuntLabelledEventsSB <- getLabelledHuntEventsSet()
datFishSuccessRate <- getHuntSuccessPerFish(datHuntLabelledEventsSB)
### PREAMP DONE####
##################
### FIG 3 SUPP FIG HPI Corr-Larva Size
## Bootstrap correlation Analysis - Hunt Power Against Development/Nutrition Measured from Larval Std. Length
## Save To summary Stat Output - Used By generate figure
datSuccessVsSize <- readRDS(file= paste(strDataExportDir,"/FishLengthVsHuntSuccess.rds",sep=""))
#\Loaded Structure datSuccessVsSize - Simplify Group Calls
datSuccessVsSize.NF <- datSuccessVsSize[datSuccessVsSize$groupID.y =="NL",]
datSuccessVsSize.LF <- datSuccessVsSize[datSuccessVsSize$groupID.y =="LL",]
datSuccessVsSize.DF <- datSuccessVsSize[datSuccessVsSize$groupID.y =="DL",]
#
datexp_SuccessVsSize<-datSuccessVsSize[,c(1,2,5,10,11,13,14)]
names(datexp_SuccessVsSize)[1] <- "expID"
names(datexp_SuccessVsSize)[2] <- "Length_mm"
datexp_SuccessVsSize[,2] <- datexp_SuccessVsSize[,2]*DIM_MMPERPX
write.csv(datexp_SuccessVsSize,file= paste(strDataExportDir,"/fig3S1_LengthVsHuntSuccess.csv",sep=""))
#\Loaded Structure datSuccessVsSize - Simplify Group Calls
dSuccessVsSize.NF <- datexp_SuccessVsSize[datexp_SuccessVsSize$groupID.y =="NL",]
dSuccessVsSize.LF <- datexp_SuccessVsSize[datexp_SuccessVsSize$groupID.y =="LL",]
dSuccessVsSize.DF <- datexp_SuccessVsSize[datexp_SuccessVsSize$groupID.y =="DL",]
XRange <- c(3.9,5)
YRange <- c(0,5)
pBw <- 0.05
stat_SizeVsHuntPower_NF <- bootStrap_stat(dSuccessVsSize.NF$Length_mm,dSuccessVsSize.NF$HuntPower,1000,XRange,YRange,"spearman")
stat_SizeVsHuntPower_LF <- bootStrap_stat(dSuccessVsSize.LF$Length_mm,dSuccessVsSize.LF$HuntPower,1000,XRange,YRange,"spearman")
stat_SizeVsHuntPower_DF <- bootStrap_stat(dSuccessVsSize.DF$Length_mm,dSuccessVsSize.DF$HuntPower,1000,XRange,YRange,"spearman")
pdf(paste0(strPlotExportPath,"/stat/fig3S1_stat_LarvalLengthsToHPI_Correlation.pdf"),width=7,height=7,title="Correlation Larval size to Hunt Success (HPI) ",onefile = TRUE) #col=(as.integer(filtereddatAllFrames$expID))
par(mar = c(3.9,4.7,1,1))
plot(density(stat_SizeVsHuntPower_NF$corr,kernel="gaussian",bw=pBw),
col=colourLegL[1],xlim=c(-0.5,0.5),lwd=3,lty=1,ylim=c(0,7),main=NA, xlab=NA,ylab=NA,cex=cex,cex.axis=cex) #expression(paste("slope ",gamma) ) )
lines(density(stat_SizeVsHuntPower_LF$corr,kernel="gaussian",bw=pBw),col=colourLegL[2],lwd=3,lty=2)
lines(density(stat_SizeVsHuntPower_DF$corr,kernel="gaussian",bw=pBw),col=colourLegL[3],lwd=3,lty=3)
mtext(side = 1,cex=cex,cex.main=cex, line = lineXAxis, expression(paste("Correlation of hunt success (HPI) to larval length ") ))
mtext(side = 2,cex=cex,cex.main=cex, line = lineAxis, expression("Density function"))
legend("topright", legend=c( paste0("NF # ", NROW(dSuccessVsSize.NF$expID) ),
paste0("LF # " , NROW(dSuccessVsSize.LF$expID) ),
paste0("DF # " , NROW(dSuccessVsSize.DF$expID) )
), ##paste(c("DL n=","LL n=","NL n="),c(NROW(lFirstBoutPoints[["DL"]][,1]),NROW(lFirstBoutPoints[["LL"]][,1]) ,NROW(lFirstBoutPoints[["NL"]][,1] ) ) )
col=colourLegL,lty=c(1,2,3),lwd=3,cex=cex)
dev.off()
### Add Stat Test ###
message("LF Corr of Larval Size to Hunting Ability Is +ve")
t.test(stat_SizeVsHuntPower_LF$corr,alternative=c("greater"),paired=FALSE ) # "two.sided"
t.test(stat_SizeVsHuntPower_NF$corr,alternative=c("greater"),paired=FALSE ) # "two.sided"
t.test(stat_SizeVsHuntPower_DF$corr,alternative=c("greater"),paired=FALSE ) # "two.sided"
t.test(stat_SizeVsHuntPower_LF$corr,stat_Cap_fast_DF$corr,alternative=c("greater"),paired=FALSE ) # "two.sided"
#### Fig 4 Supplemental - Covariance ####
nSamples <- 10000
stat_Cap_NF <- bootStrap_stat(datCapture_NL$DistanceToPrey,datCapture_NL$CaptureSpeed,nSamples,XRange,YRange)
stat_Cap_LF <- bootStrap_stat(datCapture_LL$DistanceToPrey,datCapture_LL$CaptureSpeed,nSamples,XRange,YRange)
stat_Cap_DF <- bootStrap_stat(datCapture_DL$DistanceToPrey,datCapture_DL$CaptureSpeed,nSamples,XRange,YRange)
stat_Cap_fast_NF <- bootStrap_stat(datCapture_NL[datCapture_NL$Cluster == "fast",]$DistanceToPrey,datCapture_NL[datCapture_NL$Cluster == "fast",]$CaptureSpeed,nSamples,XRange,YRange)
stat_Cap_fast_LF <- bootStrap_stat(datCapture_LL[datCapture_LL$Cluster == "fast",]$DistanceToPrey,datCapture_LL[datCapture_LL$Cluster == "fast",]$CaptureSpeed,nSamples,XRange,YRange)
stat_Cap_fast_DF <- bootStrap_stat(datCapture_DL[datCapture_DL$Cluster == "fast",]$DistanceToPrey,datCapture_DL[datCapture_DL$Cluster == "fast",]$CaptureSpeed,nSamples,XRange,YRange)
## Fast CLuster Covariance
ntail <- 700
# Plot Fast_Cluster Speed Vs Distance Correlation - bootstraped Stat ##
dLLb_rho_fast <-density(fastClusterCovarSamples$LF,kernel="gaussian",bw=0.05)
dNLb_rho_fast <-density(fastClusterCovarSamples$NF,kernel="gaussian",bw=0.05)
dDLb_rho_fast <-density(fastClusterCovarSamples$DF,kernel="gaussian",bw=0.05)
strPlotName = paste(strPlotExportPath,"/stat/fig4S1_FastClust_SpeedVsDistanceCovar.pdf",sep="")
pdf(strPlotName,width=14,height=7,
title="Esimating Covariance of capture Speed-Distance in fast capture swims / A.Model Cluster B.Bootstrap Correlation ",onefile = TRUE) #col=(as.integer(filtereddatAllFrames$expID))
outer = FALSE
line = 1 ## SubFig Label Params
lineAxis = 2.4
lineXAxis = 3.0
cex = 1.4
adj = 3.5
padj <- -16.0
las <- 1
##Margin: (Bottom,Left,Top,Right )
par(mar = c(3.9,4.7,1,1))
pBw <- 0.01
## Compare Bootstrap And Model COvariance - Fast Cluster
layout(matrix(c(1,2),1,2, byrow = TRUE))
plot(dNLb_rho_fast,col=colourLegL[1],xlim=c(-0.6,0.6),lwd=3,lty=1,ylim=c(0,10),
main=NA, #"Density Inference of Turn-To-Prey Slope ",
xlab=NA,ylab=NA,cex=cex,cex.axis=cex) #expression(paste("slope ",gamma) ) )
lines(dLLb_rho_fast,col=colourLegL[2],lwd=3,lty=2)
lines(dDLb_rho_fast,col=colourLegL[3],lwd=3,lty=3)
mtext(side = 1,cex=cex, line = lineXAxis, expression("Model-estimated speed-distance correlation in fast cluster" ))
mtext(side = 2,cex=cex, line = lineAxis, expression("Density function " ))
#mtext(side = 3,cex=cex, line = lineTitle-3, expression("Capture distance and speed " ))
mtext("A",at="topleft",outer=outer,side=2,col="black",font=2,las=las,line=line,padj=padj,adj=adj,cex.main=cex,cex=cex)
legend("topleft", legend=c( expression (),
bquote(NF~ '' ),
bquote(LF ~ '' ),
bquote(DF ~ '' ) ), ##paste(c("DL n=","LL n=","NL n="),c(NROW(lFirstBoutPoints[["DL"]][,1]),NROW(lFirstBoutPoints[["LL"]][,1]) ,NROW(lFirstBoutPoints[["NL"]][,1] ) ) )
col=colourLegL,lty=c(1,2,3),lwd=3,cex=cex)
##Boot Strap
plot(density(stat_Cap_fast_NF$corr,kernel="gaussian",bw=pBw),
col=colourLegL[1],lwd=3,lty=1,xlim=c(-0.6,0.6),ylim=c(0,10),main=NA, xlab=NA,ylab=NA,cex=cex,cex.axis=cex) #expression(paste("slope ",gamma) ) )
lines(density(stat_Cap_fast_LF$corr,kernel="gaussian",bw=pBw),col=colourLegL[2],lwd=3,lty=2)
lines(density(stat_Cap_fast_DF$corr,kernel="gaussian",bw=pBw),col=colourLegL[3],lwd=3,lty=3)
mtext(side = 1,cex=cex,cex.main=cex, line = lineXAxis, expression(paste("Bootstrapped correlation of speed-distance in fast cluster") ))
mtext(side = 2,cex=cex,cex.main=cex, line = lineAxis, expression("Density function"))
mtext("B",at="topleft",outer=outer,side=2,col="black",font=2,las=las,line=line,padj=padj,adj=adj,cex.main=cex,cex=cex)
dev.off()
##Do Stat Associated With Plot
message("Cluster Model Covariance - Probabilities")
message("Prob Fast-cluster Cov NF > 0 : ", NROW(fastClusterCovarSamples$NF[fastClusterCovarSamples$NF>0])/length(fastClusterCovarSamples$NF) )
message("Prob Fast-cluster Cov LF > 0 : ", NROW(fastClusterCovarSamples$LF[fastClusterCovarSamples$LF>0])/length(fastClusterCovarSamples$LF) )
message("Prob Fast-cluster Cov DF > 0 : ", NROW(fastClusterCovarSamples$DF[fastClusterCovarSamples$DF>0])/length(fastClusterCovarSamples$DF) )
message("Prob Fast-cluster Cov LF > DF : ", length(fastClusterCovarSamples$LFvsDF[fastClusterCovarSamples$LFvsDF>0]) / length(fastClusterCovarSamples$LFvsDF) )
message("Prob Fast-cluster Cov LF > NF : ", length(fastClusterCovarSamples$LFvsNF[fastClusterCovarSamples$LFvsNF>0]) / length(fastClusterCovarSamples$LFvsNF) )
message("BootStrapped Covariance")
message("Estimate Prob of NF > 0 : ", NROW(stat_Cap_fast_NF[stat_Cap_fast_NF$corr>0,])/NROW(stat_Cap_fast_NF) )
message("Estimate Prob of LF > 0 : ", NROW(stat_Cap_fast_LF[stat_Cap_fast_LF$corr>0,])/NROW(stat_Cap_fast_LF) )
message("Estimate Prob of DF > 0 : ", NROW(stat_Cap_fast_DF[stat_Cap_fast_DF$corr>0,])/NROW(stat_Cap_fast_DF) )
## LF Has Higher Correlation than Control
corrDiff_LFvsDF <- stat_Cap_fast_LF$corr - stat_Cap_fast_DF$corr
corrDiff_LFvsNF <- stat_Cap_fast_LF$corr - stat_Cap_fast_NF$corr
message("Estimate Prob of LF > DF : ",NROW(corrDiff_LFvsDF[corrDiff_LFvsDF > 0])/NROW(corrDiff_LFvsDF) )
message("Estimate Prob of LF > NF : ", NROW(corrDiff_LFvsNF[corrDiff_LFvsNF > 0])/NROW(corrDiff_LFvsNF) )
test_FastClustCorr_NF <- t.test(stat_Cap_fast_NF$corr,stat_Cap_fast_NF$corr_suffled,alternative=c("greater"))
test_FastClustCorr_LF <- t.test(stat_Cap_fast_LF$corr,stat_Cap_fast_LF$corr_suffled,alternative=c("greater"))
test_FastClustCorr_DF <- t.test(stat_Cap_fast_DF$corr,stat_Cap_fast_DF$corr_suffled,alternative=c("greater"))
test_FastClustCorr_LFvsDF <- t.test(stat_Cap_fast_LF$corr,stat_Cap_fast_DF$corr,alternative=c("greater"))
test_FastClustCorr_LFvsNF <- t.test(stat_Cap_fast_LF$corr,stat_Cap_fast_NF$corr,alternative=c("greater"))
message("T-test bootstrapped Speed-Dist Corr Fast Clust : NF corr is > 0 p=",test_FastClustCorr_NF$p.value )
message("T-test bootstrapped Speed-Dist Corr Fast Clust : LF corr is > 0 p=",test_FastClustCorr_LF$p.value ) ##*** Significant
message("T-test bootstrapped Speed-Dist Corr Fast Clust : DF corr is > 0 p=",test_FastClustCorr_DF$p.value )
message("T-test bootstrapped Speed-Dist Corr Fast Clust : LF corr is > NF p=",test_FastClustCorr_LFvsNF$p.value )
message("T-test bootstrapped Speed-Dist Corr Fast Clust : LF corr is > DF p=",test_FastClustCorr_LFvsDF$p.value )
##LF Shows Higher Correlation Than DF
t.test(stat_Cap_fast_LF$corr,stat_Cap_fast_DF$corr,alternative=c("greater"),paired=FALSE ) # "two.sided"
##LF Shows Higher Correlation Than NF
t.test(stat_Cap_fast_LF$corr,stat_Cap_fast_NF$corr,alternative=c("greater"),paired=FALSE ) # "two.sided"
##END OF COVAR Fast Capture Swim
#### Covar All Captures Bootstrap ###
# Plot Speed Vs Distance Correlation - bootstraped Stat ##
##Also Found in InfoTheoryBootstra[ ]
strPlotName = paste(strPlotExportPath,"/stat/fig4_statbootstrap_correlation_SpeedVsDistance.pdf",sep="")
pdf(strPlotName,width=7,height=7,title="Correlations In Speed/Distance capture variables",onefile = TRUE) #col=(as.integer(filtereddatAllFrames$expID))
par(mar = c(3.9,4.7,1,1))
plot(density(stat_Cap_NF$corr,kernel="gaussian",bw=pBw),
col=colourLegL[1],xlim=c(0,1),lwd=3,lty=1,ylim=c(0,10),main=NA, xlab=NA,ylab=NA,cex=cex,cex.axis=cex) #expression(paste("slope ",gamma) ) )
lines(density(stat_Cap_LF$corr,kernel="gaussian",bw=pBw),col=colourLegL[2],lwd=3,lty=2)
lines(density(stat_Cap_DF$corr,kernel="gaussian",bw=pBw),col=colourLegL[3],lwd=3,lty=3)
mtext(side = 1,cex=cex,cex.main=cex, line = lineXAxis, expression(paste("Correlation of capture speed to prey distance ") ))
mtext(side = 2,cex=cex,cex.main=cex, line = lineAxis, expression("Density function"))
dev.off()
## Use BootStrap Library
boot(cbind(DistanceToPrey=datCapture_NL$DistanceToPrey,CaptureSpeed=datCapture_NL$CaptureSpeed),R=1000,sim="ordinary",statistic=cor)
##Correlation Tests
##Note that Pearsons Assumes these are independent
corrDistSpeed_NF <- cor.test(datCapture_NL$DistanceToPrey,datCapture_NL$CaptureSpeed,alternative="greater",method = "pearson")
corrDistSpeed_LF <- cor.test(datCapture_LL$DistanceToPrey,datCapture_LL$CaptureSpeed,alternative="greater",method = "pearson")
corrDistSpeed_DF <- cor.test(datCapture_DL$DistanceToPrey,datCapture_DL$CaptureSpeed,alternative="greater",method = "pearson")
message("Pearson Corr Test: NF corr is > 0 p=",corrDistSpeed_NF$p.value )
message("Pearson Corr Test: LF corr is > 0 p=",corrDistSpeed_LF$p.value ) ##*** Significant
message("Pearson Corr Test: DF corr is > 0 p=",corrDistSpeed_DF$p.value )
## Do stat Associated With Plot
message("BootStrapped Covariance")
message("Estimate Prob of NF > 0 : ", NROW(stat_Cap_NF[stat_Cap_NF$corr>0,])/NROW(stat_Cap_NF) )
message("Estimate Prob of LF > 0 : ", NROW(stat_Cap_LF[stat_Cap_LF$corr>0,])/NROW(stat_Cap_LF) )
message("Estimate Prob of DF > 0 : ", NROW(stat_Cap_DF[stat_Cap_DF$corr>0,])/NROW(stat_Cap_DF) )
t_boot_speedVsDist_NF <- t.test( stat_Cap_NF$corr, stat_Cap_NF$corr_suffled, alternative=c("greater") )
t_boot_speedVsDist_LF <- t.test( stat_Cap_LF$corr, stat_Cap_LF$corr_suffled, alternative=c("greater") )
t_boot_speedVsDist_DF <- t.test( stat_Cap_DF$corr, stat_Cap_DF$corr_suffled, alternative=c("greater") )
message("T-test bootstrapped Corr Test: NF corr is > 0 p=",t_boot_speedVsDist_NF$p.value )
message("T-test bootstrapped Corr Test: LF corr is > 0 p=",t_boot_speedVsDist_LF$p.value ) ##*** Significant
message("T-test bootstrapped Corr Test: DF corr is > 0 p=",t_boot_speedVsDist_DF$p.value )
t.test( stat_Cap_LF$corr, alternative=c("greater") )
#### FIG 4 I - Time-To Hit Prey Vs Distance Boot Strapped Covariance
corrDiff_LFvsDF <- stat_Cap_LF$corr - stat_Cap_DF$corr
corrDiff_LFvsNF <- stat_Cap_LF$corr - stat_Cap_NF$corr
message("Estimate Prob of LF > DF : ",NROW(corrDiff_LFvsDF[corrDiff_LFvsDF > 0])/NROW(corrDiff_LFvsDF) )
message("Estimate Prob of LF > NF : ", NROW(corrDiff_LFvsNF[corrDiff_LFvsNF > 0])/NROW(corrDiff_LFvsNF) )
##Test Control Bootstraps
plot(density(stat_Cap_NF$corr_suffled),col="red")
lines(density(stat_Cap_NF$corr))
lines(density(stat_Cap_DF$corr))
lines(density(stat_Cap_LF$corr))
lines(density(stat_Cap_LF$corr_suffled),col="green")
lines(density(stat_Cap_DF$corr_suffled),col="blue")
stat_CapDistVsTime_NF <- bootStrap_stat(stat_Cap_fast_NF$DistanceToPrey,stat_Cap_fast_NF$FramesToHitPrey/G_APPROXFPS,10000,XRange,YRange,"spearman")
stat_CapDistVsTime_LF <- bootStrap_stat(stat_Cap_fast_LF$DistanceToPrey,stat_Cap_fast_LF$FramesToHitPrey/G_APPROXFPS,10000,XRange,YRange,"spearman")
stat_CapDistVsTime_DF <- bootStrap_stat(stat_Cap_fast_DF$DistanceToPrey,stat_Cap_fast_DF$FramesToHitPrey/G_APPROXFPS,10000,XRange,YRange,"spearman")
# Plot Speed Vs Distance Correlation - bootstraped Stat ##
strPlotName = paste(strPlotExportPath,"/stat/fig4I_statbootstrap_corrSpearman_DistanceVsTimeToPrey_fastCluster.pdf",sep="")
pdf(strPlotName,width=7,height=7,title="Correlations In between Distance And Number of Frames to Get to Prey For Fast Capture swims ",onefile = TRUE) #col=(as.integer(filtereddatAllFrames$expID))
par(mar = c(3.9,4.7,1,1))
plot(density(stat_CapDistVsTime_NF$corr,kernel="gaussian",bw=pBw),
col=colourLegL[1],xlim=c(-0.5,0.5),lwd=3,lty=1,ylim=c(0,10),main=NA, xlab=NA,ylab=NA,cex=cex,cex.axis=cex) #expression(paste("slope ",gamma) ) )
lines(density(stat_CapDistVsTime_LF$corr,kernel="gaussian",bw=pBw),col=colourLegL[2],lwd=3,lty=2)
lines(density(stat_CapDistVsTime_DF$corr,kernel="gaussian",bw=pBw),col=colourLegL[3],lwd=3,lty=3)
# legend("topright", legend=c( expression (),
# bquote(NF~ '' ),
# bquote(LF ~ '' ),
# bquote(DF ~ '' ) ), ##paste(c("DL n=","LL n=","NL n="),c(NROW(lFirstBoutPoints[["DL"]][,1]),NROW(lFirstBoutPoints[["LL"]][,1]) ,NROW(lFirstBoutPoints[["NL"]][,1] ) ) )
# col=colourLegL,lty=c(1,2,3),lwd=3,cex=cex)
mtext(side = 1,cex=cex,cex.main=cex, line = lineXAxis, expression(paste("Correlation of time to hit prey and distance") ))
mtext(side = 2,cex=cex,cex.main=cex, line = lineAxis, expression("Density function"))
dev.off()
message("Mean Spearman Correlation Values")
message("E[NF corr] = ",mean(stat_CapDistVsTime_NF$corr))
message("E[LF corr] = ",mean(stat_CapDistVsTime_LF$corr))
message("E[DF corr] = ",mean(stat_CapDistVsTime_DF$corr))
## Use BootStrap Library
boot(cbind(DistanceToPrey=datCapture_NL$DistanceToPrey,CaptureSpeed=datCapture_NL$CaptureSpeed),R=1000,sim="ordinary",statistic=cor)
##Correlation Tests
##Note that Pearsons Assumes these are independent
corrDistTime_NF <- cor.test(datCapture_NL$DistanceToPrey,datCapture_NL$FramesToHitPrey/G_APPROXFPS,alternative="greater",method = "spearman")
corrDistTime_LF <- cor.test(datCapture_LL$DistanceToPrey,datCapture_LL$FramesToHitPrey/G_APPROXFPS,alternative="greater",method = "spearman")
corrDistTime_DF <- cor.test(datCapture_DL$DistanceToPrey,datCapture_DL$FramesToHitPrey/G_APPROXFPS,alternative="greater",method = "spearman")
message("Spearman Corr Test: NF corr is > 0 p=",corrDistTime_NF$p.value )
message("Spearman Corr Test: LF corr is > 0 p=",corrDistTime_LF$p.value ) ##*** Significant
message("Spearman Corr Test: DF corr is > 0 p=",corrDistTime_DF$p.value )
message("Calculate Probabilities and Significance (Prob Of Rejecting Alternative Hypothesis)")
message("NF correlation mean is NOT zero ***p=", t.test(stat_CapDistVsTime_NF$corr,alternative = "two.sided")["p.value"] )
message("LF correlation mean is NOT zero ***p=", t.test(stat_CapDistVsTime_LF$corr,alternative = "two.sided")["p.value"] )
message("DF correlation mean is not zero ***p=", t.test(stat_CapDistVsTime_DF$corr,alternative = "two.sided")["p.value"] )
message("NF is less than DF ***p=", t.test(stat_CapDistVsTime_DF$corr,stat_CapDistVsTime_NF$corr,alternative = "greater")["p.value"] )
message("Estimate Probabilities")
stat_CapDistVsTime_LFvsNF <- stat_CapDistVsTime_LF$corr-stat_CapDistVsTime_NF$corr
stat_CapDistVsTime_LFvsDF <- stat_CapDistVsTime_LF$corr-stat_CapDistVsTime_DF$corr
stat_CapDistVsTime_NFvsDF <- stat_CapDistVsTime_NF$corr-stat_CapDistVsTime_DF$corr
message("P[NF > 0] =", NROW(stat_CapDistVsTime_NF$corr[stat_CapDistVsTime_NF$corr > 0 ])/NROW(stat_CapDistVsTime_NF$corr))
message("P[LF > 0] =", NROW(stat_CapDistVsTime_LF$corr[stat_CapDistVsTime_LF$corr > 0 ])/NROW(stat_CapDistVsTime_LF$corr))
message("P[DF > 0] =", NROW(stat_CapDistVsTime_DF$corr[stat_CapDistVsTime_DF$corr > 0 ])/NROW(stat_CapDistVsTime_DF$corr))
message("P[LF < NF] =", NROW(stat_CapDistVsTime_LFvsNF[stat_CapDistVsTime_LFvsNF < 0 ])/NROW(stat_CapDistVsTime_LFvsNF))
message("P[LF < DF] =", NROW(stat_CapDistVsTime_LFvsDF[stat_CapDistVsTime_LFvsDF < 0 ])/NROW(stat_CapDistVsTime_LFvsDF))
message("P[NF < DF] =", NROW(stat_CapDistVsTime_NFvsDF[stat_CapDistVsTime_NFvsDF < 0 ])/NROW(stat_CapDistVsTime_NFvsDF))
message("LF < DF **p=", t.test(stat_CapDistVsTime_LF$corr,stat_CapDistVsTime_DF$corr,alternative = "less")["p.value"])
message("LF < NF **p=", t.test(stat_CapDistVsTime_LF$corr,stat_CapDistVsTime_NF$corr,alternative = "less")["p.value"])
###
##############Clustered Capture Speed Vs Turn Ratio ####
#### GGPLOT VERSION ###
pdf(file= paste(strPlotExportPath,"/stat/fig5_stat_clusterCaptureSpeedVsDistToPrey_NF.pdf",sep=""),width=7,height=7)
#layout(matrix(c(1,2,3),1,3, byrow = FALSE))
# ##Margin: (Bottom,Left,Top,Right )
#par(mar = c(3.9,4.7,12,1))
p_NF = ggplot( datCapture_NL, aes(DistanceToPrey, CaptureSpeed,color =Cluster,fill=Cluster)) +
ggtitle(NULL) +
theme(axis.title = element_text(family="Helvetica",face="bold", size=16),
axis.text = element_text(family="Helvetica",face="bold", size=16),
plot.margin = unit(c(1,1,1,1), "mm")) + fill_palette("jco") +
theme( ##Add the Legend
legend.position = c(.95, .95),
legend.justification = c("right", "top"),
legend.box.just = "right",
legend.margin = margin(6, 6, 6, 6)
)
p_NF = p_NF + geom_point( size = 3, alpha = 0.6,aes(color =datCapture_NL$Cluster) ) + xlim(0, 0.8) + ylim(0, 80) +
scale_color_manual( values = c("#00AFBB", "#E7B800", "#FC4E07") )
contour_fast <- getFastClusterGrid(draw_NF) ## Draw the mvtnorm model fit contour
contour_slow <- getSlowClusterGrid(draw_NF)
p_NF = p_NF +
geom_contour(contour_fast, mapping = aes(x = DistanceToPrey, y = CaptureSpeed, z = Density) ,linetype=2 ) +
geom_contour(contour_slow, mapping = aes(x = DistanceToPrey, y = CaptureSpeed, z = Density) ,linetype=2 ) +
scale_x_continuous(name="Distance to prey (mm)", limits=c(0, 0.8)) +
scale_y_continuous(name="Capture Speed (mm/sec)", limits=c(0, 80))
#theme_linedraw()
ggMarginal(p_NF, x="DistanceToPrey",y="CaptureSpeed", type = "density",groupColour = TRUE,groupFill=TRUE,show.legend=TRUE)
##Make Custom Marginal Plot
#xplot <- ggdensity(datCapture_NL,"DistanceToPrey", mapping=aes(x="DistanceToPrey",color=datCapture_NL$Cluster), fill = "Cluster") +
#clean_theme() + theme(plot.margin = unit(c(1,1,1,1), "mm"), legend.position = "none") +
#fill_palette("jco") ##scale_color_manual( values = c("#00AFBB", "#00AFBB" ) )+
#yplot <- ggdensity(datCapture_NL, "CaptureSpeed",mapping=aes(x="CaptureSpeed",color=datCapture_NL$Cluster), fill = "Cluster")+
# rotate() + clean_theme() + theme(plot.margin = unit(c(1,1,1,1), "mm"), legend.position = "none")+
# fill_palette("jco") #
##Cordinates Run 0-1 From lower left 0,0
# ggdraw() +
# draw_plot(xplot, x = 0.055, y = 0.8, width = 0.74, height = 0.2) +
# draw_plot(p_NF, x = 0, y = 0, width = 0.8, height = 0.8) +
#draw_plot(yplot, x = 0.8 , y = 0.055, width = 0.2, height = 0.74)
dev.off()
pdf(file= paste(strPlotExportPath,"/stat/fig5_stat_clusterCaptureSpeedVsDistToPrey_LF.pdf",sep=""),width=7,height=7)
p_LF <- ggplot( datCapture_LL, aes(DistanceToPrey, CaptureSpeed,color =Cluster,fill=Cluster)) + ggtitle(NULL) +
theme(axis.title = element_text(family="Helvetica",face="bold", size=16),
axis.text = element_text(family="Helvetica",face="bold", size=16),
plot.margin = unit(c(1,1,1,1), "mm"), legend.position = "none") +
fill_palette("jco")
p_LF <- p_LF + geom_point( size = 3, alpha = 0.6,aes(color =datCapture_LL$Cluster) ) + xlim(0, 0.8) + ylim(0, 80) +
scale_color_manual( values = c("#00AFBB", "#E7B800", "#FC4E07") )
contour_fast <- getFastClusterGrid(draw_LF)
contour_slow <- getSlowClusterGrid(draw_LF)
p_LF = p_LF + geom_contour(contour_fast, mapping = aes(x = DistanceToPrey, y = CaptureSpeed, z = Density) ,linetype=2 ) +
geom_contour(contour_slow, mapping = aes(x = DistanceToPrey, y = CaptureSpeed, z = Density) ,linetype=2 ) +
scale_x_continuous(name="Distance to prey (mm)", limits=c(0, 0.8)) +
scale_y_continuous(name="Capture Speed (mm/sec)", limits=c(0, 80))
ggMarginal(p_LF ,
x="DistanceToPrey",y="CaptureSpeed", type = "density",groupColour = TRUE,groupFill=TRUE,show.legend=TRUE)
dev.off()
pdf(file= paste(strPlotExportPath,"/stat/fig5_stat_clusterCaptureSpeedVsDistToPrey_DF.pdf",sep=""),width=7,height=7)
p_DF = ggplot( datCapture_DL, aes(DistanceToPrey, CaptureSpeed,color =Cluster,fill=Cluster)) + ggtitle(NULL) +
theme(axis.title = element_text(family="Helvetica",face="bold", size=16),
axis.text = element_text(family="Helvetica",face="bold", size=16),
plot.margin = unit(c(1,1,1,1), "mm"), legend.position = "none") +
fill_palette("jco")
p_DF = p_DF + geom_point( size = 3, alpha = 0.6,aes(color =datCapture_DL$Cluster) ) + xlim(0, 0.8) + ylim(0, 80) +
scale_color_manual( values = c("#00AFBB", "#E7B800", "#FC4E07") ) # scale_color_manual( values = c(colourHPoint[4],colourHPoint[1]) )
contour_fast <- getFastClusterGrid(draw_DF)
contour_slow <- getSlowClusterGrid(draw_DF)
p_DF = p_DF + geom_contour(contour_fast, mapping = aes(x = DistanceToPrey, y = CaptureSpeed, z = Density) ,linetype=2 ) +
geom_contour(contour_slow, mapping = aes(x = DistanceToPrey, y = CaptureSpeed, z = Density) ,linetype=2 ) +
scale_x_continuous(name="Distance to prey (mm)", limits=c(0, 0.8)) +
scale_y_continuous(name="Capture Speed (mm/sec)", limits=c(0, 80))
ggMarginal(p_DF ,x="DistanceToPrey",y="CaptureSpeed", type = "density",groupColour = TRUE,groupFill=TRUE,show.legend=TRUE)
dev.off()
### Probability of Membership in High speed Cluster /
pdf(file= paste(strPlotExportPath,"/stat/fig5_stat_ProbOfFactCapture_ggplot.pdf",sep=""),width=7,height=7)
dat2_NF <- rbind( data.frame(D=tail(draw_NF$pS[,,1],500),Group=rep("NF",500) ),
data.frame(D=tail(draw_LF$pS[,,1],500),Group=rep("LF",500) ),
data.frame(D=tail(draw_DF$pS[,,1],500),Group=rep("DF",500) ))
par(mar=c(5,5,5,5))
ggplot(dat2_NF, aes(x=D),group=Group ) +
#geom_density( lwd=1.5,aes(linetype=label,colour=label) ) +
geom_line(stat="density",lwd=1.5,show.legend=T,aes(linetype=Group,colour=Group) ) +
theme(legend.position = c(0.1, 0.8),legend.title=element_blank(),legend.key.width = unit(3, "line") ) + ## No Legend
scale_x_continuous(name= expression(paste("Probability of high speed capture ["~p["s"]~"]" )), limits=c(0, 1),expand=c(0,0) ) +
scale_y_continuous(name="Density function", limits=c(0, 15),expand=c(0,0))
# guides( size = guide_legend(order = 3) )
#scale_color_manual(labels=dat2_NF$label,values=colourHLine) ##Change legend text
#
#plot_probM = plot_probM + geom_density(dat2_NF[dat2_NF$label=="NF",], mapping=aes(x=pS_LF,colour=colourHLine[2]))
#plot_probM + geom_density(dat_pS, mapping=aes(x=pS_DF,colour=colourHLine[3])) +
# scale_color_manual(labels = c("T999", "T888","T88asd8"),values=colourHLine) ##Change legend text
#####
dev.off()
pdf(file= paste(strPlotExportPath,"/stat/fig5_stat_clusterMembership.pdf",sep=""),width=7,height=7)
par(mar = c(3.9,4.7,1,1))
#### ## Probability Density of Strike capture ####
plot(density(tail(draw_NF$pS[,,1],1000),pBw=0.05),col=colourLegL[1],xlim=c(0,1),ylim=c(0.4,10),lwd=3,lty=1,main=NA,xlab=NA,ylab=NA,
cex=cex,cex.axis=cex )
lines(density(tail(draw_LF$pS[,,1],1000)),col=colourLegL[2],lwd=3,lty=2)
lines(density(tail(draw_DF$pS[,,1],1000)),col=colourLegL[3],lwd=3,lty=3)
#lines(density(draw_ALL$pS),col=colourLegL[4],lwd=3,lty=4)
mtext(side = 1,cex=cex, line = lineXAxis, expression(paste(bold("Probability of high speed capture ["~p["s"]~"]" ) ) ) ,cex.main=cex )
mtext(side = 2,cex=cex, line = lineAxis, expression(bold("Density function" ) ) )
legend("topleft",
legend=c( expression (),
bquote(NF[""] ~ '#' ~ .(NROW(datCapture_NL$DistanceToPrey)) ),
bquote(LF[""] ~ '#' ~ .(NROW(datCapture_LL$DistanceToPrey)) ),
bquote(DF[""] ~ '#' ~ .(NROW(datCapture_DL$DistanceToPrey)) )
#bquote(ALL ~ '#' ~ .(ldata_ALL$N) )
), ##paste(c("DL n=","LL n=","NL n="),c(NROW(lFirstBoutPoints[["DL"]][,1]),NROW(lFirstBoutPoints[["LL"]][,1]) ,NROW(lFirstBoutPoints[["NL"]][,1] ) ) )
col=colourLegL,lty=c(1,2,3,4),lwd=3,cex=cex)
dev.off()
pdf(file= paste(strPlotExportPath,"/stat/fig5_stat_meanDistanceOfFastCapture.pdf",sep=""),width=7,height=7)
par(mar = c(3.9,4.7,1,1))
#### ## Probability Density of Strike capture ####
plot(density(tail(draw_NF$mu[2,1,,1],1000)),col=colourLegL[1],xlim=c(0,0.6),ylim=c(0.0,35),lwd=3,lty=1,main=NA,xlab=NA,ylab=NA,
cex=cex,cex.axis=cex )
lines(density(tail(draw_LF$mu[2,1,,1],1000)),col=colourLegL[2],lwd=3,lty=2)
lines(density(tail(draw_DF$mu[2,1,,1],1000)),col=colourLegL[3],lwd=3,lty=3)
#lines(density(draw_ALL$pS),col=colourLegL[4],lwd=3,lty=4)
mtext(side = 1,cex=cex, line = lineXAxis, expression(paste(bold("Estimated mean distance of high speed capture (mm)") ) ) ,cex.main=cex )
mtext(side = 2,cex=cex, line = lineAxis, expression(bold("Density function") ))
# legend("topleft",
# legend=c( expression (),
# bquote(NF[""] ~ '#' ~ .(NROW(datCapture_NL$DistanceToPrey)) ),
# bquote(LF[""] ~ '#' ~ .(NROW(datCapture_LL$DistanceToPrey)) ),
# bquote(DF[""] ~ '#' ~ .(NROW(datCapture_DL$DistanceToPrey)) )
# #bquote(ALL ~ '#' ~ .(ldata_ALL$N) )
# ), ##paste(c("DL n=","LL n=","NL n="),c(NROW(lFirstBoutPoints[["DL"]][,1]),NROW(lFirstBoutPoints[["LL"]][,1]) ,NROW(lFirstBoutPoints[["NL"]][,1] ) ) )
# col=colourLegL,lty=c(1,2,3,4),lwd=3,cex=cex)
dev.off()
##########UNDERSHOOT Vs Distance
#fig6.CaptureSpeed/fig6-stat_modelCaptureSpeedVsUndershootAndDistance_Valid.pdf
pdf(file= paste(strPlotExportPath,"/stat/fig6_stat_UndershootAndDistance_NF.pdf",sep=""),width=7,height=7)
#layout(matrix(c(1,2,3),1,3, byrow = FALSE))
# ##Margin: (Bottom,Left,Top,Right )
#par(mar = c(3.9,4.7,12,1))
p_NF = ggplot( datCapture_NL, aes(Undershoot, DistanceToPrey ,color =Cluster,fill=Cluster)) +
ggtitle(NULL) +
theme(axis.title = element_text(family="Helvetica",face="bold", size=16),plot.margin = unit(c(1,1,1,1), "mm"), legend.position = "none") +
fill_palette("jco")
p_NF = p_NF + geom_point( size = 3, alpha = 0.6,aes(color =datCapture_NL$Cluster) ) + xlim(0, 0.8) + ylim(0, 80) +
scale_color_manual( values = c("#00AFBB", "#E7B800", "#FC4E07") ) +
scale_y_continuous(name="Distance to prey (mm)", limits=c(0, 0.8)) +
scale_x_continuous(name="Turn ratio", limits=c(0, 2))
ggMarginal(p_NF, x="Undershoot",y="DistanceToPrey", type = "density",groupColour = TRUE,groupFill=TRUE,show.legend=TRUE)
dev.off()
pdf(file= paste(strPlotExportPath,"/stat/fig6_stat_UndershootAndDistance_LF.pdf",sep=""),width=7,height=7)
#layout(matrix(c(1,2,3),1,3, byrow = FALSE))
# ##Margin: (Bottom,Left,Top,Right )
#par(mar = c(3.9,4.7,12,1))
p_NF = ggplot( datCapture_LL, aes(Undershoot, DistanceToPrey ,color =Cluster,fill=Cluster)) +
ggtitle(NULL) +
theme(axis.title = element_text(family="Helvetica",face="bold", size=16),plot.margin = unit(c(1,1,1,1), "mm"), legend.position = "none") +
fill_palette("jco")
p_NF = p_NF + geom_point( size = 3, alpha = 0.6,aes(color =datCapture_LL$Cluster) ) + xlim(0, 0.8) + ylim(0, 80) +
scale_color_manual( values = c("#00AFBB", "#E7B800", "#FC4E07") ) +
scale_y_continuous(name="Distance to prey (mm)", limits=c(0, 0.8)) +
scale_x_continuous(name="Turn ratio", limits=c(0, 2))
ggMarginal(p_NF, x="Undershoot",y="DistanceToPrey", type = "density",groupColour = TRUE,groupFill=TRUE,show.legend=TRUE)
dev.off()
pdf(file= paste(strPlotExportPath,"/stat/fig6_stat_UndershootAndDistance_DF.pdf",sep=""),width=7,height=7)
#layout(matrix(c(1,2,3),1,3, byrow = FALSE))
# ##Margin: (Bottom,Left,Top,Right )
#par(mar = c(3.9,4.7,12,1))
p_NF = ggplot( datCapture_DL, aes(Undershoot, DistanceToPrey ,color =Cluster,fill=Cluster)) +
ggtitle(NULL) +
theme(axis.title = element_text(family="Helvetica",face="bold", size=16),plot.margin = unit(c(1,1,1,1), "mm"), legend.position = "none") +
fill_palette("jco")
p_NF = p_NF + geom_point( size = 3, alpha = 0.6,aes(color =datCapture_DL$Cluster) ) + xlim(0, 0.8) + ylim(0, 80) +
scale_color_manual( values = c("#00AFBB", "#E7B800", "#FC4E07") ) +
scale_y_continuous(name="Distance to prey (mm)", limits=c(0, 0.8)) +
scale_x_continuous(name="Turn ratio", limits=c(0, 2))
ggMarginal(p_NF, x="Undershoot",y="DistanceToPrey", type = "density",groupColour = TRUE,groupFill=TRUE,show.legend=TRUE)
dev.off()
########UNdershoot - Speed ###
pdf(file= paste(strPlotExportPath,"/stat/fig6_stat_UndershootAndSpeed_NF.pdf",sep=""),width=7,height=7)
#layout(matrix(c(1,2,3),1,3, byrow = FALSE))
# ##Margin: (Bottom,Left,Top,Right )
#par(mar = c(3.9,4.7,12,1))
p_NF = ggplot( datCapture_NL, aes(Undershoot, CaptureSpeed ,color =Cluster,fill=Cluster)) +
ggtitle(NULL) +
theme(axis.title = element_text(family="Helvetica",face="bold", size=16),plot.margin = unit(c(1,1,1,1), "mm"), legend.position = "none") +
fill_palette("jco") +
theme( ##Add the Legend
legend.position = c(.95, .95),
legend.justification = c("right", "top"),
legend.box.just = "right",
legend.margin = margin(6, 6, 6, 6)
)
p_NF = p_NF + geom_point( size = 3, alpha = 0.6,aes(color =datCapture_NL$Cluster) ) + xlim(0, 0.8) + ylim(0, 80) +
scale_color_manual( values = c("#00AFBB", "#E7B800", "#FC4E07") ) +
scale_y_continuous(name="Capture Speed (mm/sec)", limits=c(0, 60)) +
scale_x_continuous(name="Turn ratio", limits=c(0, 2))
p_NF = p_NF + geom_vline(xintercept = 1, linetype="dotted", color = "grey", size=1.0)
ggMarginal(p_NF, x="Undershoot",y="CaptureSpeed", type = "density",groupColour = TRUE,groupFill=TRUE,show.legend=TRUE)
dev.off()
pdf(file= paste(strPlotExportPath,"/stat/fig6_stat_UndershootAndSpeed_DF.pdf",sep=""),width=7,height=7)
#layout(matrix(c(1,2,3),1,3, byrow = FALSE))
# ##Margin: (Bottom,Left,Top,Right )
#par(mar = c(3.9,4.7,12,1))
p_DF = ggplot( datCapture_DL, aes(Undershoot, CaptureSpeed ,color =Cluster,fill=Cluster)) +
ggtitle(NULL) +
theme(axis.title = element_text(family="Helvetica",face="bold", size=16),plot.margin = unit(c(1,1,1,1), "mm"), legend.position = "none") +
fill_palette("jco")
p_DF = p_DF + geom_point( size = 3, alpha = 0.6,aes(color =datCapture_DL$Cluster) ) + xlim(0, 0.8) + ylim(0, 80) +
scale_color_manual( values = c("#00AFBB", "#E7B800", "#FC4E07") ) +
scale_y_continuous(name="Capture Speed (mm/sec)", limits=c(0, 60)) +
scale_x_continuous(name="Turn ratio", limits=c(0, 2))
p_DF = p_DF + geom_vline(xintercept = 1, linetype="dotted", color = "grey", size=1.0)
ggMarginal(p_DF, x="Undershoot",y="CaptureSpeed", type = "density",groupColour = TRUE,groupFill=TRUE,show.legend=TRUE)
dev.off()
pdf(file= paste(strPlotExportPath,"/stat/fig6_stat_UndershootAndSpeed_LF.pdf",sep=""),width=7,height=7)
#layout(matrix(c(1,2,3),1,3, byrow = FALSE))
# ##Margin: (Bottom,Left,Top,Right )
#par(mar = c(3.9,4.7,12,1))
p_LF = ggplot( datCapture_LL, aes(Undershoot, CaptureSpeed ,color =Cluster,fill=Cluster)) +
ggtitle(NULL) +
theme(axis.title = element_text(family="Helvetica",face="bold", size=16),plot.margin = unit(c(1,1,1,1), "mm"), legend.position = "none") +
fill_palette("jco")
p_LF = p_LF + geom_point( size = 3, alpha = 0.6,aes(color =datCapture_LL$Cluster) ) + xlim(0, 0.8) + ylim(0, 80) +
scale_color_manual( values = c("#00AFBB", "#E7B800", "#FC4E07") ) +
scale_y_continuous(name="Capture Speed (mm/sec)", limits=c(0, 60)) +
scale_x_continuous(name="Turn ratio", limits=c(0, 2))
p_LF = p_LF + geom_vline(xintercept = 1, linetype="dotted", color = "grey", size=1.0)
ggMarginal(p_LF, x="Undershoot",y="CaptureSpeed", type = "density",groupColour = TRUE,groupFill=TRUE,show.legend=TRUE)
dev.off()
### Bootstrap Undershoot Vs Capture Speed ###
## Repeated here taken from stat_informationTheoryAndCorrelations_bootstrap
XRange <- c(0,2) #
YRange <- c(0,60) ##We limit The information Obtained To Reasonable Ranges Of Phi (Vergence Angle)
smethod <- "spearman"
stat_CapTurnVsSpeed_NF <- bootStrap_stat(datCapture_NL$Undershoot,datCapture_NL$CaptureSpeed,10000,XRange,YRange,smethod)
stat_CapTurnVsSpeed_LF <- bootStrap_stat(datCapture_LL$Undershoot,datCapture_LL$CaptureSpeed,10000,XRange,YRange,smethod)
stat_CapTurnVsSpeed_DF <- bootStrap_stat(datCapture_DL$Undershoot,datCapture_DL$CaptureSpeed,10000,XRange,YRange,smethod)
# PLot Density Turn Vs Speed
#strPlotName = paste(strPlotExportPath,"/stat/fig6_statbootstrap_Spearman_correlation_TurnVsSpeed.pdf",sep="")
strPlotName = paste(strPlotExportPath,"/stat/fig6_statbootstrap_correlation_TurnVsSpeed.pdf",sep="")
pdf(strPlotName,width=7,height=7,title="Correlations In hunt variables - turn-ratio vs capture Speed",onefile = TRUE) #col=(as.integer(filtereddatAllFrames$expID))
par(mar = c(3.9,4.7,1,1))
pBw <- 0.02
plot(density(stat_CapTurnVsSpeed_NF$corr,kernel="gaussian",bw=pBw),
col=colourLegL[1],xlim=c(-0.5,0.5),lwd=3,lty=1,ylim=c(0,10),main=NA, xlab=NA,ylab=NA,cex=cex,cex.axis=cex) #expression(paste("slope ",gamma) ) )
lines(density(stat_CapTurnVsSpeed_LF$corr,kernel="gaussian",bw=pBw),col=colourLegL[2],lwd=3,lty=2)
lines(density(stat_CapTurnVsSpeed_DF$corr,kernel="gaussian",bw=pBw),col=colourLegL[3],lwd=3,lty=3)
mtext(side = 1,cex=cex,cex.main=cex, line = lineXAxis, expression(paste("Correlation of turn-ratio to capture speed ") ))
mtext(side = 2,cex=cex,cex.main=cex, line = lineAxis, expression("Density function"))
dev.off()
message("Calc Probability that Correlation in LF larvae is higher than DF/NF")
cor_Diff_LFvsNF <- (stat_CapTurnVsSpeed_LF$corr - stat_CapTurnVsSpeed_NF$corr)
cor_Diff_LFvsDF <- (stat_CapTurnVsSpeed_LF$corr - stat_CapTurnVsSpeed_DF$corr)
P_cor_UndershootVsSpeed_LF <- length(stat_CapTurnVsSpeed_LF$corr[stat_CapTurnVsSpeed_LF$corr < 0 ])/length(stat_CapTurnVsSpeed_LF$corr)
P_cor_UndershootVsSpeed_NF <- length(stat_CapTurnVsSpeed_NF$corr[stat_CapTurnVsSpeed_NF$corr < 0 ])/length(stat_CapTurnVsSpeed_NF$corr)
P_cor_UndershootVsSpeed_DF <- length(stat_CapTurnVsSpeed_DF$corr[stat_CapTurnVsSpeed_DF$corr < 0 ])/length(stat_CapTurnVsSpeed_DF$corr)
P_cor_UndershootVsSpeed_LFNF <- length(cor_Diff_LFvsNF[cor_Diff_LFvsNF < 0 ])/length(cor_Diff_LFvsNF)
P_cor_UndershootVsSpeed_LFDF <- length(cor_Diff_LFvsDF[cor_Diff_LFvsDF < 0 ])/length(cor_Diff_LFvsDF)
message("LF Has higher correlation than NF with p=",P_cor_UndershootVsSpeed_LFNF, " and from DF with p=",P_cor_UndershootVsSpeed_LFDF)
message("LF shows undershoot and capt. speed correlation with p=",P_cor_UndershootVsSpeed_LF)
message("LF with p=",P_cor_UndershootVsSpeed_LF)
message("NF with p=",P_cor_UndershootVsSpeed_NF)
message("DF with p=",P_cor_UndershootVsSpeed_DF)
plot(dens_dist_NF_all,xlim=c(0.0,0.5),col=colourLegL[1],lwd=4,lty=1,ylim=c(0,5),
main=NA,cex=cex,xlab=NA,ylab=NA)
lines(dens_dist_NF_fast,col=colourLegL[1],lwd=2,lty=2)
lines(dens_dist_NF_slow,col=colourLegE[1],lwd=2,lty=2)
plot(dens_dist_LF_all,xlim=c(0.0,0.5),col=colourLegL[2],lwd=4,lty=1)
lines(dens_dist_LF_fast,col=colourLegL[2],lwd=2,lty=2)
lines(dens_dist_LF_slow,col=colourLegE[2],lwd=2,lty=2)
plot(dens_dist_DF_all,xlim=c(0.0,0.5),col=colourLegL[3],lwd=4,lty=1)
lines(dens_dist_DF_fast,col=colourLegL[3],lwd=2,lty=2)
lines(dens_dist_DF_slow,col=colourLegE[3],lwd=2,lty=2)
legend("topleft",
legend=c( expression (),
bquote(NF[""] ~ '#' ~ .(NROW(datCapture_NL)) ),
bquote(LF[""] ~ '#' ~ .(NROW(datCapture_LL)) ),
bquote(DF[""] ~ '#' ~ .(NROW(datCapture_DL)) )
#,bquote(ALL ~ '#' ~ .(ldata_ALL$N) )
), ##paste(c("DL n=","LL n=","NL n="),c(NROW(lFirstBoutPoints[["DL"]][,1]),NROW(lFirstBoutPoints[["LL"]][,1]) ,NROW(lFirstBoutPoints[["NL"]][,1] ) ) )
col=colourLegL,lty=c(1,2,3,4),lwd=3,cex=cex)
mtext(side = 2,cex=cex, line = lineAxis, expression("Density ") )
mtext(side = 1,cex=cex, line = lineXAxis, expression(paste("Probability of high speed capture ["~p["s"]~"]" ) ) )
#mtext("B",at="topleft",outer=outer,side=2,col="black",font=2,las=las,line=line,padj=padj,adj=adj,cex.main=cex)
mtext("D",at="topleft",outer=outer,side=2,col="black",font=2 ,las=1,line=line,padj=padj,adj=3,cex.main=cex,cex=cex)
###### Capture Speed ###
lineAxis = 2.4
lineXAxis = 2.7
layout(matrix(c(1,2,3),3,1, byrow = FALSE))
##Margin: (Bottom,Left,Top,Right )
par(mar = c(3.9,4.3,2,1))
##Make SPeed Density Of Each Cluster
dens_speed_NF_all <- density(datCapture_NL$CaptureSpeed)
dens_speed_NF_fast <- density(datCapture_NL$CaptureSpeed[lClustScore_NF$pchL == 16])
dens_speed_NF_slow <- density(datCapture_NL$CaptureSpeed[lClustScore_NF$pchL == 1])
##Make SPeed Density Of Each Cluster
dens_speed_LF_all <- density(datCapture_LL$CaptureSpeed)
dens_speed_LF_fast <- density(datCapture_LL$CaptureSpeed[lClustScore_LF$pchL == 16])
dens_speed_LF_slow <- density(datCapture_LL$CaptureSpeed[lClustScore_LF$pchL == 1])
##Make SPeed Density Of Each Cluster
dens_speed_DF_all <- density(datCapture_DL$CaptureSpeed)
dens_speed_DF_fast <- density(datCapture_DL$CaptureSpeed[lClustScore_DF$pchL == 16])
dens_speed_DF_slow <- density(datCapture_DL$CaptureSpeed[lClustScore_DF$pchL == 1])
## Plot Density Speed ##
plot(dens_speed_NF_all,xlim=c(0.0,60),col=colourLegL[1],lwd=4,lty=1,ylim=c(0,0.1),
main=NA,cex=cex,xlab=NA,ylab=NA)
lines(dens_speed_NF_fast,col=colourLegL[1],lwd=2,lty=2)
lines(dens_speed_NF_slow,col=colourLegE[1],lwd=2,lty=2)
plot(dens_speed_LF_all,xlim=c(0.0,60),col=colourLegL[2],lwd=4,lty=1,ylim=c(0,0.1))
lines(dens_speed_LF_fast,col=colourLegL[2],lwd=2,lty=2)
lines(dens_speed_LF_slow,col=colourLegE[2],lwd=2,lty=2)
plot(dens_speed_DF_all,xlim=c(0.0,60),col=colourLegL[3],lwd=4,lty=1,ylim=c(0,0.1))
lines(dens_speed_DF_fast,col=colourLegL[3],lwd=2,lty=2)
lines(dens_speed_DF_slow,col=colourLegE[3],lwd=2,lty=2)
####### END OF Speed ###
#'######### TURN RATIO ##########
##Make SPeed Density Of Each Cluster
dens_turn_NF_all <- density(datCapture_NL$Undershoot)
dens_turn_NF_fast <- density(datCapture_NL$Undershoot[lClustScore_NF$pchL == 16])
dens_turn_NF_slow <- density(datCapture_NL$Undershoot[lClustScore_NF$pchL == 1])
##Make SPeed Density Of Each Cluster
dens_turn_LF_all <- density(datCapture_LL$Undershoot)
dens_turn_LF_fast <- density(datCapture_LL$Undershoot[lClustScore_LF$pchL == 16])
dens_turn_LF_slow <- density(datCapture_LL$Undershoot[lClustScore_LF$pchL == 1])
##Make SPeed Density Of Each Cluster
fracSlow_DF <- table(lClustScore_DF$pchL )[1]/NROW(lClustScore_DF$pchL)
dens_turn_DF_all <- density(datCapture_DL$Undershoot)
dens_turn_DF_fast <- density(datCapture_DL$Undershoot[lClustScore_DF$pchL == 16] )
dens_turn_DF_slow <- density(datCapture_DL$Undershoot[lClustScore_DF$pchL == 1])
## Plot TURN RATIO ##
plot(dens_turn_NF_all,xlim=c(0.0,2),col=colourLegL[1],lwd=4,lty=1,ylim=c(0,3),
main=NA,cex=cex,xlab=NA,ylab=NA)
lines(dens_turn_NF_fast,col=colourLegL[1],lwd=2,lty=2)
lines(dens_turn_NF_slow,col=colourLegE[1],lwd=2,lty=2)
plot(dens_turn_LF_all,xlim=c(0.0,2),col=colourLegL[2],lwd=4,lty=1,ylim=c(0,3))
lines(dens_turn_LF_fast,col=colourLegL[2],lwd=2,lty=2)
lines(dens_turn_LF_slow,col=colourLegE[2],lwd=2,lty=2)
plot(dens_turn_DF_all,xlim=c(0.0,2),col=colourLegL[3],lwd=4,lty=1,ylim=c(0,3))
lines(dens_turn_DF_fast$x,dens_turn_DF_fast$y*(1-fracSlow_DF),col=colourLegL[3],lwd=2,lty=2)
lines(dens_turn_DF_slow$x,dens_turn_DF_slow$y*fracSlow_DF,col=colourLegE[3],lwd=2,lty=2)
####### END OF Speed ###
pdf(file= paste(strPlotExportPath,"distal",strDataPDFFileName,sep=""))
layout(matrix(c(1,2,3),3,1, byrow = FALSE))
##Margin: (Bottom,Left,Top,Right )
par(mar = c(3.9,4.5,1,1))
plot(datCapture_NL$Undershoot, datCapture_NL$CaptureSpeed,col=colourLegL[1],pch=lClustScore_NF$pchL,
xlab=NA,ylab=NA,ylim=c(0,60),xlim=c(0,2),main=NA,cex=cex)
lFit <- lm(datCapture_NL$CaptureSpeed ~ datCapture_NL$Undershoot)
abline(lFit,col=colourLegL[1],lwd=3.0) ##Fit Line / Regression
contour(densNL, drawlabels=FALSE, nlevels=7,add=TRUE,col=colourL[4],lty=2,lwd=1)
legend("topright",
legend=paste("NF int.:",prettyNum(digits=3,lFit$coefficients[1])," slope: ",prettyNum(digits=3,lFit$coefficients[2]) ) ,cex=cex) #prettyNum(digits=3, cov(datTurnVsStrikeSpeed_NL$Undershoot, datTurnVsStrikeSpeed_NL$CaptureSpeed)
plot(datCapture_LL$Undershoot, datCapture_LL$CaptureSpeed,col=colourLegL[2],pch=lClustScore_LF$pchL,
ylim=c(0,60),xlim=c(0,2),xlab=NA,ylab=NA,cex=cex)
lFit <- lm(datCapture_LL$CaptureSpeed ~ datCapture_LL$Undershoot)
abline(lFit,col=colourLegL[2],lwd=3.0) ##Fit Line / Regression
contour(densLL, drawlabels=FALSE, nlevels=7,add=TRUE,col=colourL[4],lty=2,lwd=1)
mtext(side = 2,cex=cex, line = lineAxis-0.7, expression("Capture Speed (mm/sec) " ))
legend("topright",
legend=paste("LF int.:",prettyNum(digits=3,lFit$coefficients[1])," slope: ",prettyNum(digits=3,lFit$coefficients[2]) ),cex=cex )
plot(datCapture_DL$Undershoot, datCapture_DL$CaptureSpeed,col=colourLegL[3],pch=lClustScore_DF$pchL,
ylim=c(0,60),xlim=c(0,2),
xlab=NA,ylab=NA,main=NA,cex=cex)
lFit <- lm(datCapture_DL$CaptureSpeed ~ datCapture_DL$Undershoot)
abline(lFit,col=colourLegL[3],lwd=3.0) ##Fit Line / Regression
contour(densDL, drawlabels=FALSE, nlevels=7,add=TRUE,col=colourL[4],lty=2,lwd=1)
mtext(side = 1,cex=cex, line = lineXAxis, expression("Turn ratio ["~gamma~"]" ))
legend("topright",
legend=paste("DF int.:",prettyNum(digits=3,lFit$coefficients[1])," slope: ",prettyNum(digits=3,lFit$coefficients[2]) ),cex=cex )
dev.off()
## EMPIRICAL - UNdeshoot vs Prey Distance
pdf(file= paste(strPlotExportPath,"/stat/UndershootAnalysis/fig7-UndershootDistanceCV_Distal_scatter.pdf",sep=""))
layout(matrix(c(1,2,3),3,1, byrow = FALSE))
##Margin: (Bottom,Left,Top,Right )
par(mar = c(4.5,4.3,0.5,1))
plot(datCapture_NL$Undershoot, datCapture_NL$DistanceToPrey,col=colourLegL[1],pch=lClustScore_NF$pchL,
xlab=NA,ylab=NA,ylim=c(0,1.0),xlim=c(0,2),main=NA,cex=cex)
lFit <- lm(datCapture_NL$DistanceToPrey ~ datCapture_NL$Undershoot)
abline(lFit,col=colourLegL[1],lwd=3.0) ##Fit Line / Regression
legend("topright",
legend=paste("NF int.:",prettyNum(digits=3,lFit$coefficients[1])," slope: ",prettyNum(digits=3,lFit$coefficients[2]) ),cex=cex ) #prettyNum(digits=3, cov(datTurnVsStrikeSpeed_NL$Undershoot, datTurnVsStrikeSpeed_NL$CaptureSpeed)
plot(datCapture_LL$Undershoot, datCapture_LL$DistanceToPrey,col=colourLegL[2],pch=lClustScore_LF$pchL,
ylim=c(0,1),xlim=c(0,2.0),xlab=NA,ylab=NA,cex=cex)
lFit <- lm(datCapture_LL$DistanceToPrey ~ datCapture_LL$Undershoot)
abline(lFit,col=colourLegL[2],lwd=3.0) ##Fit Line / Regression
mtext(side = 2,cex=cex, line = 2.2, expression("Distance to prey (mm) " ))
legend("topright",
legend=paste("LF int.:",prettyNum(digits=3,lFit$coefficients[1])," slope: ",prettyNum(digits=3,lFit$coefficients[2]) ),cex=cex )
plot(datCapture_DL$Undershoot, datCapture_DL$DistanceToPrey,col=colourLegL[3],pch=lClustScore_DF$pchL,
ylim=c(0,1.0),xlim=c(0,2), xlab=NA,ylab=NA,main=NA,cex=cex)
lFit <- lm(datCapture_DL$DistanceToPrey ~ datCapture_DL$Undershoot)
abline(lFit,col=colourLegL[3],lwd=3.0) ##Fit Line / Regression
mtext(side = 1,cex=cex, line = lineXAxis, expression("Turn ratio ["~gamma~"]" ))
legend("topright",
legend=paste("DF int.:",prettyNum(digits=3,lFit$coefficients[1])," slope: ",prettyNum(digits=3,lFit$coefficients[2]) ) ,cex=cex)
dev.off()
########## END oF CaptureSpeed vs Distance ###
##Make SPeed Density Of Each Cluster
dens_dist_NF_all <- density(datCapture_NL$DistanceToPrey)
dens_dist_NF_fast <- density(datCapture_NL$DistanceToPrey[lClustScore_NF$pchL == 16])
dens_dist_NF_slow <- density(datCapture_NL$DistanceToPrey[lClustScore_NF$pchL == 1])
##Make SPeed Density Of Each Cluster
dens_dist_LF_all <- density(datCapture_LL$DistanceToPrey)
dens_dist_LF_fast <- density(datCapture_LL$DistanceToPrey[lClustScore_LF$pchL == 16])
dens_dist_LF_slow <- density(datCapture_LL$DistanceToPrey[lClustScore_LF$pchL == 1])
##Make SPeed Density Of Each Cluster
dens_dist_DF_all <- density(datCapture_DL$DistanceToPrey)
dens_dist_DF_fast <- density(datCapture_DL$DistanceToPrey[lClustScore_DF$pchL == 16])
dens_dist_DF_slow <- density(datCapture_DL$DistanceToPrey[lClustScore_DF$pchL == 1])
outer = FALSE
line = 1 ## SubFig Label Params
lineAxis = 2.4
lineXAxis = 3.0
cex = 1.4
adj = 3.5
padj <- -8.0
las <- 1
####################################################
############## # GAPE-TIMING # #############