-
Notifications
You must be signed in to change notification settings - Fork 0
/
Appendix S1.Rmd
2082 lines (1703 loc) · 84.9 KB
/
Appendix S1.Rmd
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
---
title: '**Appendix S1**'
author: "Aimee Chhen, Alessandra Bertassoni, Arnaud LJ Desbiez, Michael J Noonan"
date: "This document was created on `r format(Sys.Date(), '%B %d, %Y')`."
output:
html_document:
toc: true
#toc_float: true
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
<hr style="border: 1px solid black;">
# **Overview**
Our primary aim was to understand the movement ecology of giant anteaters (*Myrmecophaga tridactyla*) at the social-spatial interface. Specifically, we aimed to address two overarching questions:
- Is the spatial arrangement of giant anteater home ranges governed by social factors (e.g., territoriality, mating groups, social groups, etc.)?
- Does giant anteater movement within their home range exhibit signs of social interactions (e.g., avoidance, attraction, correlated movement, etc.)?
In order to answer our two core research questions, we carried out three separate analyses focused on estimating patterns in:
i) home-range overlap;
ii) proximity and encounter rates; and
iii) correlated movement.
To do this, we used GPS data to quantify key socio-spatial patterns using the methods implemented in the `ctmm` and the `corrMove` packages in `R`. In this appendix, we describe the workflow and specific steps that was used to carry out in each of these analyses below.
Data visualisation and analysis were carried out using R (version 4.2.2, R Core Team, 2022) and the following R packages: ctmm (version 1.1.0, Fleming & Calabrese, 2022), lme4 (version 1.1.31, Bates et al., 2015), glmmTMB (version 1.1.7, Brooks et al., 2017), corrMove (version 0.1.0, Calabrese & Fleming, 2023), and ggplot2 (version 3.4.2, Wickham, 2016). All R scripts can be found in the GitHub repository at https://github.com/QuantitativeEcologyLab/Giant_Anteater.
<hr style="border: 1px solid black;">
# **Data**
Before analysis, we calibrated the GPS measurement error and removed any outlying data points (for full details on data pre-processing see Appendix S2 in (Noonan et al., 2022). First step of the analysis is to import the data and convert to a telemetry object for use in the ```ctmm``` package.
```{r load-packages, message = FALSE}
#load packages
library(readr)
library(ggplot2)
library(dplyr)
library(tidyr)
library(tibble)
library(lubridate)
library(gridExtra)
library(egg)
library(scales)
library(osmdata)
library(terra)
library(tidyterra)
library(sf)
library(ctmm)
library(lme4)
library(glmmTMB)
library(corrMove)
```
```{r load-files, echo=FALSE}
#load data
load("data/anteater/anteater_data.rda")
load("data/anteater/bio_data.rda")
load("data/anteater/telemetry_data.rda")
#movement models and home range estimate
load("data/anteater_fit.rda")
load("data/anteater_akdes.rda")
#home range
load("data/home_range/HR_size.rda")
load("data/home_range/AKDE_1.rda")
load("data/home_range/AKDE_2.rda")
load("data/home_range/overlap_1_df.rda")
load("data/home_range/overlap_2_df.rda")
load("data/home_range/overlap_df.rda")
#encounters
load("data/encounter/proximity_df.rda")
load("data/encounter/distance_df.rda")
encounter_radius_df <- readRDS("data/encounter/encounter_radius_df.RDS")
load("data/encounter/proximity_identified_pairs_df.rda")
distance_pairs_df <- readRDS("data/encounter/distance_pairs_df.RDS")
#load correlated movement data
cm_pair1 <- readRDS("data/correlative_movement/cm_pair1.RDS")
cm_pair2 <- readRDS("data/correlative_movement/cm_pair2.RDS")
cm_pair3 <- readRDS("data/correlative_movement/cm_pair3.RDS")
cm_pair4 <- readRDS("data/correlative_movement/cm_pair4.RDS")
cm_pair5 <- readRDS("data/correlative_movement/cm_pair5.RDS")
cm_pair6 <- readRDS("data/correlative_movement/cm_pair6.RDS")
cm_pair7 <- readRDS("data/correlative_movement/cm_pair7.RDS")
cm_pair8 <- readRDS("data/correlative_movement/cm_pair8.RDS")
cm_pair9 <- readRDS("data/correlative_movement/cm_pair9.RDS")
cm_pair10 <- readRDS("data/correlative_movement/cm_pair10.RDS")
cm_pair11 <- readRDS("data/correlative_movement/cm_pair11.RDS")
cm_pair12 <- readRDS("data/correlative_movement/cm_pair12.RDS")
```
```{r import-data, message = FALSE}
#import data, cleaned giant anteater GPS tracking data, containing no outliers
DATA_GPS <- read.csv("data/anteater/Anteaters_NoOutliers.csv")
#import supplementary data containing biological information
DATA_META <- read.csv("data/anteater/Anteater_Results_Final.csv")
#correct mismatch ID entries
DATA_GPS$ID[DATA_GPS$ID == "Larry 267"] <- "Larry"
DATA_GPS$ID[DATA_GPS$ID == "Little Rick"] <- "Little_Rick"
#correct mismatch ID entries
DATA_META$ID[DATA_META$ID == "Little Rick"] <- "Little_Rick"
```
While a total of 43 individuals were collared as part of the larger monitoring effort (Noonan et al., 2022), here we restricted our analyses to 23 range-resident individuals living in three separate clusters. These individuals were selected as they resided in areas where there was high confidence that all resident giant anteaters were equipped with GPS trackers. The resulting dataset consisted of 528,324 GPS fixes.
```{r import-meta, message = FALSE}
#subset to the 23 range-resident individuals
anteater_data <- DATA_GPS[which(DATA_GPS$ID %in% c("Alexander", "Annie", "Anthony", "Beto", "Bumpus",
"Cate", "Christoffer","Elaine", "Hannah","Jackson",
"Jane","Kyle", "Larry", "Little_Rick", "Luigi",
"Makao", "Margaret", "Maria", "Puji", "Reid",
"Rodolfo", "Sheron", "Thomas")),]
#subset to the 23 range-resident individuals
bio_data <- DATA_META[c(1:3,8:10,12,14,17,19,20,22,23,25:29,33:35,37,38),]
#subset the biological data
bio_data <- bio_data[,c(1:3,5)]
#add site location to the dataframe
bio_data$Site <- NA
bio_data$Site[bio_data$Road == "MS-040"] <- 1
bio_data$Site[bio_data$Road == "BR_267"] <- 2
bio_data
#convert GPS dataset to a telemetry object
DATA_TELEMETRY <- as.telemetry(anteater_data)
#summary of the dataset
summary(DATA_TELEMETRY)
#visualisation of the data
plot(DATA_TELEMETRY)
```
```{r eval = FALSE, echo=FALSE}
#save GPS dataframe
save(anteater_data, file = "data/anteater/anteater_data.rda")
#save biological information dataframe
save(bio_data, file = "data/anteater/bio_data.rda")
#save telemetry data
save(DATA_TELEMETRY, file = "data/anteater/telemetry_data.rda")
```
<hr style="border: 1px solid black;">
# **Movement Models**
After preparing the data, we fit the continuous-time movement models following the workflow described in Calabrese et al. (2016).
```{r eval = FALSE}
#fit movement models
GUESS <- lapply(DATA_TELEMETRY[1:23], function(b) ctmm.guess(b,interactive=FALSE))
FIT <- lapply(1:23, function(i) ctmm.select(DATA_TELEMETRY[[i]],GUESS[[i]]))
names(FIT) <- names(DATA_TELEMETRY[1:23])
overlap(FIT)
```
```{r}
#summary of the fitted model
summary(FIT)
```
```{r eval = FALSE, echo=FALSE}
#save movement model
save(FIT, file = "data/anteater_fit.rda")
```
<hr style="border: 1px solid black;">
# **Home-Range Overlap**
## Estimating home-range areas
We estimated giant anteater home ranges using Autocorrelated Kernel Density Estimation (AKDE; Fleming et al., 2015) using the ```ctmm``` package. AKDE, corrects for autocorrelation induced bias (Noonan et al., 2019) by conditioning the bandwidth optimisation on the data’s autocorrelation structure (Fleming & Calabrese, 2017). Thus, home-range estimation first required fitting a series of continuous-time movement models to the GPS tracking data and identifying the best model via small sample-sized corrected Akaike’s Information Criterion (AICc) (Fleming & Calabrese, 2022). Giant anteater home ranges were then estimated conditional on each individual’s best-fit movement model.
```{r eval = FALSE}
#calculate AKDE home-range estimates based on the best fit model, create aligned UDs
AKDE <- akde(DATA_TELEMETRY[1:23],FIT)
overlap(AKDE)
```
```{r eval=FALSE, echo=FALSE}
#save AKDE home-range estimations
save(AKDE, file = "data/anteater_akdes.rda")
```
## Home-range results
```{r}
meta(AKDE)
```
```{r extract-hr,eval=FALSE,echo=FALSE}
#create a dataframe to store home range area statistics from the AKDE
HR_size <- data.frame()
#loop through each object in the AKDE list
for (i in 1:length(AKDE)) {
#extract the home range area statistics summary
summary <- summary(AKDE[[i]])$CI
#bind the summary to the dataframe
HR_size <- rbind(HR_size, as.data.frame(summary))
}
row.names(HR_size) <- NULL
#add biological data to dataframe
HR_size <- cbind(HR_size, bio_df)
HR_size <- relocate(HR_size, c(low, est, high), .after = Site)
names(HR_size)[6] <- "HR_low"
names(HR_size)[7] <- "HR_est"
names(HR_size)[8] <- "HR_high"
save(HR_size, file = "data/home_range/HR_size.rda")
```
```{r}
#calculate the mean total home range size
round(mean(HR_size$HR_est), 2)
#calculate CIs of the mean total home range size
round(mean(HR_size$HR_low), 2)
round(mean(HR_size$HR_high), 2)
```
Here, we calculate the home-range statistics based on a sex parameter using the `ctmm` function `meta()`.
```{r hr-sex-analysis}
#Does home-range size differ between sexes?
#subset each individual based on their sex
AKDE_male <- AKDE[c("Alexander", "Anthony", "Beto","Christoffer","Jackson",
"Kyle", "Larry", "Little_Rick", "Luigi", "Reid",
"Rodolfo", "Thomas")]
AKDE_female <- AKDE[c("Annie", "Bumpus", "Cate", "Elaine", "Hannah",
"Jane","Makao", "Margaret", "Maria", "Puji",
"Sheron")]
#calculate mean home range sizes for male
meta(AKDE_male)
#calculate mean home range sizes for female
meta(AKDE_female)
#test to see significance of sex on home range
AKDE_sex_compare <- list(male = AKDE_male,
female = AKDE_female)
COL_sex <- c("#004488", "#A50026")
meta(AKDE_sex_compare, col = COL_sex, sort = TRUE)
```
We investigated if weight was a factor in home-range size. We used a GLMM with a gamma distribution, a log link function, and site as a random effect to determine whether the weight differed between individuals. This model was then compared to similar model that excluded the weight predictor variable using a likelihood ratio test.
```{r hr-weight}
#import supplementary data containing biological information
DATA_META <- read.csv("data/anteater/Anteater_Results_Final.csv")
#subset biological data from supplementary data
bio_data <- DATA_META[c(1:3,8:10,12,14,17,19,20,22,23,25:29,33:35,37,38), c(1:5)]
#add site location
bio_data$Site[bio_data$Road == "MS-040"] <- 1
bio_data$Site[bio_data$Road == "BR_267"] <- 2
#load home range size data
load("data/home_range/HR_size.rda")
Weight <- bio_data[,4]
HR_size <- cbind(HR_size, Weight)
#without luigi
HR_size <- HR_size[HR_size$ID != "Luigi",]
#............................................................
# Is weight a factor in home-range size?
#compare model with and without weight as a variable
HR_weight_test <- glmmTMB(HR_est ~ Weight + (1|Site),
family = Gamma(link = "log"), data = HR_size)
HR_weight_test2 <- glmmTMB(HR_est ~ 1 + (1|Site),
family = Gamma(link = "log"), data = HR_size)
HR_weight_test_results <- anova(HR_weight_test, HR_weight_test2)
HR_weight_test_results
#calculate weight impact via likelihood ratio test
HR_weight_test_pvalue <- round(HR_weight_test_results$`Pr(>Chisq)`[2], 2)
HR_weight_test_pvalue
summary(HR_weight_test)
plot(HR_size$HR_est ~ HR_size$Weight)
summary(HR_weight_test)
```
---
## Estimating home-range overlap
Home-range overlap was estimated for all pairs of individuals (i.e., dyads) via the Bhattacharyya coefficient (Winner et al., 2018).
```{r}
#subset home-range overlap based on the site location
AKDE_1 <- AKDE[c("Alexander", "Anthony", "Bumpus", "Cate", "Christoffer",
"Elaine", "Jackson", "Kyle", "Little_Rick", "Makao",
"Puji", "Rodolfo")]
AKDE_2 <- AKDE[c("Annie", "Beto", "Hannah", "Jane", "Larry",
"Luigi", "Margaret", "Maria", "Reid", "Sheron",
"Thomas")]
```
```{r eval=FALSE, echo=FALSE}
#save home range estimates for each site
save(AKDE_1, file = "data/home_range/AKDE_1.rda")
save(AKDE_2, file = "data/home_range/AKDE_2.rda")
```
```{r overlap}
#calculate 95% AKDE home-range overlap for a pairwise comparison for each site
overlap_1 <- overlap(AKDE_1, level = 0.95)
overlap_2 <- overlap(AKDE_2, level = 0.95)
```
```{r eval = FALSE}
#create a pairwise dataframe by pairing up every individual at each site
#extract CI 'est' matrix from array
overlap_1_est <- overlap_1$CI[ , , 2]
#remove duplicate values of the matrix
overlap_1_est[upper.tri(overlap_1_est, diag = TRUE)] <- NA
#Create a new data frame based on the overlap values
overlap_1_df <- as.data.frame(overlap_1_est)
overlap_1_df$anteater_A <- rownames(overlap_1_df)
overlap_1_df <- pivot_longer(overlap_1_df, cols = -anteater_A,
names_to = 'anteater_B', values_to = 'overlap_est', values_drop_na = TRUE)
#extract CI 'low' matrix from array
overlap_1_low <- overlap_1$CI[ , , 1]
#remove duplicate values of the matrix
overlap_1_low[upper.tri(overlap_1_low, diag = TRUE)] <- NA
#create a new dataframe based on the overlap values
overlap_1_low <- as.data.frame(overlap_1_low)
overlap_1_low$anteater_A <- rownames(overlap_1_low)
overlap_1_low <- pivot_longer(overlap_1_low, cols = -anteater_A,
names_to = 'anteater_B', values_to = 'overlap_low',
values_drop_na = TRUE)
overlap_1_df <- left_join(overlap_1_df, overlap_1_low,
by = c("anteater_A", "anteater_B"))
overlap_1_df <- relocate(overlap_1_df, overlap_low, .before = overlap_est)
#extract CI 'high' matrix from array
overlap_1_high <- overlap_1$CI[ , , 3]
#remove duplicate values of the matrix
overlap_1_high[upper.tri(overlap_1_high, diag = TRUE)] <- NA
#create a new dataframe based on the overlap values
overlap_1_high <- as.data.frame(overlap_1_high)
overlap_1_high$anteater_A <- rownames(overlap_1_high)
overlap_1_high <- pivot_longer(overlap_1_high, cols = -anteater_A,
names_to = 'anteater_B', values_to = 'overlap_high',
values_drop_na = TRUE)
overlap_1_df <- left_join(overlap_1_df, overlap_1_high,
by = c("anteater_A", "anteater_B"))
#add biological data to dataframe
overlap_1_df <- left_join(overlap_1_df, rename(bio_data, anteater_A = ID),
by = "anteater_A")
overlap_1_df <- left_join(overlap_1_df, rename(bio_data, anteater_B = ID),
by = "anteater_B", suffix = c(".A", ".B"))
#add column to indicate which sexes that are being compared
overlap_1_df <- mutate(overlap_1_df,
sex_comparison =
case_when(paste(Sex.A, Sex.B) == "Male Male" ~ "male-male",
paste(Sex.A, Sex.B) == "Female Female" ~ "female-female",
paste(Sex.A, Sex.B) == "Male Female" ~ "female-male",
paste(Sex.A, Sex.B) == "Female Male" ~ "female-male"))
#assign site
overlap_1_df$site <- 1
overlap_1_df <- relocate(overlap_1_df,
c("overlap_low", "overlap_est", "overlap_high"), .after = site)
```
```{r eval = FALSE}
#extract CI 'est' matrix from array
overlap_2_est <- overlap_2$CI[ , , 2]
#remove duplicate values of the matrix
overlap_2_est[upper.tri(overlap_2_est, diag = TRUE)] <- NA
#create a new data frame based on the overlap values
overlap_2_df <- as.data.frame(overlap_2_est)
overlap_2_df$anteater_A <- rownames(overlap_2_df)
overlap_2_df <- pivot_longer(overlap_2_df, cols = -anteater_A,
names_to = 'anteater_B', values_to = 'overlap_est', values_drop_na = TRUE)
#extract CI 'low' matrix from array
overlap_2_low <- overlap_2$CI[ , , 1]
#remove duplicate values of the matrix
overlap_2_low[upper.tri(overlap_2_low, diag = TRUE)] <- NA
#create a new data frame based on the overlap values
overlap_2_low <- as.data.frame(overlap_2_low)
overlap_2_low$anteater_A <- rownames(overlap_2_low)
overlap_2_low <- pivot_longer(overlap_2_low, cols = -anteater_A,
names_to = 'anteater_B', values_to = 'overlap_low',
values_drop_na = TRUE)
overlap_2_df <- left_join(overlap_2_df, overlap_2_low,
by = c("anteater_A", "anteater_B"))
overlap_2_df <- relocate(overlap_2_df, overlap_low, .before = overlap_est)
#extract CI 'high' matrix from array
overlap_2_high <- overlap_2$CI[ , , 3]
#remove duplicate values of the matrix
overlap_2_high[upper.tri(overlap_2_high, diag = TRUE)] <- NA
#create a new data frame based on the overlap values
overlap_2_high <- as.data.frame(overlap_2_high)
overlap_2_high$anteater_A <- rownames(overlap_2_high)
overlap_2_high <- pivot_longer(overlap_2_high, cols = -anteater_A,
names_to = 'anteater_B', values_to = 'overlap_high',
values_drop_na = TRUE)
overlap_2_df <- left_join(overlap_2_df, overlap_2_high,
by = c("anteater_A", "anteater_B"))
#add biological data to dataframe
overlap_2_df <- left_join(overlap_2_df, rename(bio_data, anteater_A = ID),
by = "anteater_A")
overlap_2_df <- left_join(overlap_2_df, rename(bio_data, anteater_B = ID),
by = "anteater_B", suffix = c(".A", ".B"))
#add column to indicate which sexes that are being compared
overlap_2_df <- mutate(overlap_2_df,
sex_comparison =
case_when(paste(Sex.A, Sex.B) == "Male Male" ~ "male-male",
paste(Sex.A, Sex.B) == "Female Female" ~ "female-female",
paste(Sex.A, Sex.B) == "Male Female" ~ "female-male",
paste(Sex.A, Sex.B) == "Female Male" ~ "female-male"))
#assign site
overlap_2_df$site <- 2
overlap_2_df <- relocate(overlap_2_df,
c("overlap_low", "overlap_est", "overlap_high"), .after = site)
```
```{r eval = FALSE}
#combine both sites into one dataframe
overlap_df <- rbind(overlap_1_df, overlap_2_df)
overlap_df$pair_ID <- paste(overlap_df$anteater_A, overlap_df$anteater_B, sep = "_")
overlap_df <- relocate(overlap_df, pair_ID, .before = anteater_A)
#clean up environment
rm(overlap_1_low, overlap_1_est, overlap_1_high,
overlap_2_low, overlap_2_est, overlap_2_high)
```
```{r eval = FALSE, echo=FALSE}
#save home range overlap dataframes
save(object = overlap_1_df, file = "data/home_range/overlap_1_df.rda")
save(object = overlap_2_df, file = "data/home_range/overlap_2_df.rda")
save(object = overlap_df, file = "data/home_range/overlap_df.rda")
```
## Home-range overlap results
```{r}
#calculate mean total home-range overlap
round(mean(overlap_df$overlap_est), 2)
#calculate range of total home-range overlap
round(min(overlap_df$overlap_est), 2)
round(max(overlap_df$overlap_est), 2)
```
To determine if sex was a factor underpinning the degree of pairwise overlap, we fit a Generalized Linear Mixed Model (GLMM) with a beta distribution and a logit link function to the home-range overlap estimates, with pairwise sex as a predictor variable (i.e., male-male, female-female, and female-male). In addition, site was included as a random effect. Because the overlap values ranged between [0,1], we rescaled the values as (y(n-1) + 0.5)/n in order for them to lie within the (0,1) interval (Smithson & Verkuilen, 2006). This model was then compared to a similar model that excluded the pairwise sex predictor variable using a likelihood ratio test.
```{r}
#rescale the values
min_val <- min(overlap_df$overlap_est)
max_val <- max(overlap_df$overlap_est)
squeeze_min <- 0.001
squeeze_max <- 0.999
overlap_df$overlap_est_squeezed <- ((overlap_df$overlap_est - min_val) / (max_val - min_val)) * (squeeze_max - squeeze_min) + squeeze_min
overlap_df <- relocate(overlap_df, overlap_est_squeezed, .after = overlap_high)
#test for significance in sex, compare model with and without sex as a variable
HRO_test <- glmmTMB(overlap_est_squeezed ~ sex_comparison + (1|site),
family = beta_family(link = "logit"), data = overlap_df)
HRO_test2 <- glmmTMB(overlap_est_squeezed ~ 1 + (1|site),
family = beta_family(link = "logit"), data = overlap_df)
HRO_test_results <- anova(HRO_test, HRO_test2)
HRO_test_results
HRO_test_pvalue <- round(HRO_test_results$`Pr(>Chisq)`[2], 2)
HRO_test_pvalue
```
Home-range overlap results based on sex comparisons (i.e.. male-male, female-female, and female-male).
```{r}
#number of home-range overlap in each sex comparison category
table(overlap_df$sex_comparison)
#calculate mean home-range overlap and the range based on sex comparisons
round(mean(overlap_df$overlap_est[overlap_df$sex_comparison == "male-male"]), 2)
round(min(overlap_df$overlap_est[overlap_df$sex_comparison == "male-male"]), 2)
round(max(overlap_df$overlap_est[overlap_df$sex_comparison == "male-male"]), 2)
round(mean(overlap_df$overlap_est[overlap_df$sex_comparison == "female-female"]), 2)
round(min(overlap_df$overlap_est[overlap_df$sex_comparison == "female-female"]), 2)
round(max(overlap_df$overlap_est[overlap_df$sex_comparison == "female-female"]), 2)
round(mean(overlap_df$overlap_est[overlap_df$sex_comparison == "female-male"]), 2)
round(min(overlap_df$overlap_est[overlap_df$sex_comparison == "female-male"]), 2)
round(max(overlap_df$overlap_est[overlap_df$sex_comparison == "female-male"]), 2)
```
<hr style="border: 1px solid black;">
# **Proximity and Encounters**
While home-range overlap describes patterns in spatial structuring, it does not directly indicate whether individuals are likely to be in the same place at the same time (Winner et al., 2018). In order to understand the temporal component of giant anteaters’ socio-spatial behaviour, we estimated a proximity ratio for all dyads via the `ctmm` function `proximity()`.
## Proximity
### Estimating proximity ratio
The proximity ratio was estimated by comparing a dyad’s observed separation distances with the separation distances expected under completely random movement. A proximity ratio of 1 is thus consistent with independent movement, values <1 indicate that the two individuals are closer on average than expected for independent movement, and vice versa for values >1.
```{r}
#subset movement models of individuals based on their site location
FIT_1 <- FIT[c("Alexander", "Anthony", "Bumpus", "Cate", "Christoffer",
"Elaine", "Jackson", "Kyle", "Little_Rick", "Makao",
"Puji", "Rodolfo")]
FIT_2 <- FIT[c("Annie", "Beto", "Hannah", "Jane", "Larry",
"Luigi", "Margaret", "Maria", "Reid", "Sheron",
"Thomas")]
```
```{r eval = FALSE}
#create empty columns for the results to be saved to
overlap_1_df$proximity_low <- NA
overlap_1_df$proximity_est <- NA
overlap_1_df$proximity_high <- NA
#calculate the proximity statistics
for(i in 1:nrow(overlap_1)){
ANIMAL_A <- as.character(overlap_1_df[i, 'anteater_A'])
ANIMAL_B <- as.character(overlap_1_df[i, 'anteater_B'])
TRACKING_DATA.1 <- DATA_TELEMETRY[c(ANIMAL_A, ANIMAL_B)]
MODELS.1 <- list(FIT_1[ANIMAL_A][[1]], FIT_1[ANIMAL_B][[1]])
PROXIMITY1 <- tryCatch(
{
#calculate the proximity statistic
PROXIMITY_1 <- proximity(data = TRACKING_DATA.1, CTMM = MODELS.1, GUESS=ctmm(error=FALSE))},
error=function(err){
PROXIMITY_1 <- c(NA,NA,NA)
return(PROXIMITY_1)
}
)
overlap_1_df[i, c("proximity_low")] <- PROXIMITY_1[1]
overlap_1_df[i, c("proximity_est")] <- PROXIMITY_1[2]
overlap_1_df[i, c("proximity_high")] <- PROXIMITY_1[3]
#save results to a csv file
write.csv(overlap_1_df, "data/encounter/DATA_proximity_1.csv", row.names = FALSE)
#track progress
cat("finished index", i, "\n")
}
```
```{r eval = FALSE}
#create empty columns for the results to be saved to
overlap_2_df$proximity_low <- NA
overlap_2_df$proximity_est <- NA
overlap_2_df$proximity_high <- NA
#calculate the proximity statistics
for(i in 1:nrow(overlap_2_df)){
ANIMAL_A <- as.character(overlap_2_df[i, 'anteater_A'])
ANIMAL_B <- as.character(overlap_2_df[i, 'anteater_B'])
TRACKING_DATA_2 <- DATA_TELEMETRY[c(ANIMAL_A, ANIMAL_B)]
MODELS_2 <- list(FIT_2[ANIMAL_A][[1]], FIT_2[ANIMAL_B][[1]])
PROXIMITY_2 <- tryCatch(
{
#calculate the proximity statistic
PROXIMITY_2 <- proximity(data = TRACKING_DATA_2,
CTMM = MODELS_2,
GUESS=ctmm(error=FALSE))},
error=function(err){
PROXIMITY_2 <- c(NA,NA,NA)
return(PROXIMITY_2)
}
)
overlap_2_df[i, c("proximity_low")] <- PROXIMITY_2[1]
overlap_2_df[i, c("proximity_est")] <- PROXIMITY_2[2]
overlap_2_df[i, c("proximity_high")] <- PROXIMITY_2[3]
#save results in a csv file
write.csv(overlap_2_df, "data/enocunter/DATA_proximity_2.csv", row.names = FALSE)
#track progress
cat("finished index", i, "\n")
}
```
```{r eval = FALSE, message = FALSE}
#import proximity statistics data
DATA_proximity_1 <- read.csv("data/encounter/DATA_proximity_1.csv")
DATA_proximity_2 <- read.csv("data/encounter/DATA_proximity_2.csv")
#correct mismatch entry
DATA_proximity_1$anteater_A[DATA_proximity_1$anteater_A == "Little Rick"] <- "Little_Rick"
DATA_proximity_1$anteater_B[DATA_proximity_1$anteater_B == "Little Rick"] <- "Little_Rick"
DATA_proximity_2$anteater_A[DATA_proximity_2$anteater_A == "Larry 267"] <- "Larry"
DATA_proximity_2$anteater_B[DATA_proximity_2$anteater_B == "Larry 267"] <- "Larry"
#add missing site column to dataframe for site 2
DATA_proximity_2$site <- 2
DATA_proximity_2 <- relocate(DATA_proximity_2, site, .before = proximity_low)
#create a proximity dataframe
proximity_df <- bind_rows(DATA_proximity_1, DATA_proximity_2)
proximity_df <- proximity_df[,-3]
proximity_df <- mutate(proximity_df,
sex_comparison =
case_when(paste(Sex.A, Sex.B) == "Male Male" ~ "male-male",
paste(Sex.A, Sex.B) == "Female Female" ~ "female-female",
paste(Sex.A, Sex.B) == "Male Female" ~ "female-male",
paste(Sex.A, Sex.B) == "Female Male" ~ "female-male"))
#add home-range overlap data to proximity dataframe
proximity_df <- left_join(overlap_df, proximity_df, by = c("anteater_A", "anteater_B",
"Sex.A", "Sex.B",
"Age.A", "Age.B",
"sex_comparison",
"site"))
```
```{r eval = FALSE, echo=FALSE}
#save proximity dataframe
save(proximity_df, file = "data/encounter/proximity_df.rda")
```
### Proximity ratio results
We used a GLMM with a gamma distribution, a log link function, and site as a random effect to determine whether the estimated proximity ratios differed between pairwise sex combinations. This model was then compared to similar model that excluded the pairwise sex predictor variable using a likelihood ratio test.
```{r proximity-analysis}
#test for significance in sex, compare model with and without sex as a variable
proximity_test <- glmer(proximity_est ~ sex_comparison + (1|site),
family = Gamma(link = "log"), data = proximity_df)
proximity_test2 <- glmer(proximity_est ~ 1 + (1|site),
family = Gamma(link = "log"), data = proximity_df)
proximity_test_results <- anova(proximity_test, proximity_test2)
proximity_test_results
proximity_test_pvalue <- round(proximity_test_results$`Pr(>Chisq)`[2], 2)
proximity_test_pvalue
#test for significance in home-range overlap, compare model with and without overlap as a variable
prox_overlap_test <- glmer(proximity_est ~ overlap_est + (1|site),
family = Gamma(link = "log"), data = proximity_df)
prox_overlap_test2 <- glmer(proximity_est ~ 1 + (1|site),
family = Gamma(link = "log"), data = proximity_df)
prox_overlap_test_results <- anova(prox_overlap_test, prox_overlap_test2)
prox_overlap_test_results
prox_overlap_test_pvalue <- round(prox_overlap_test_results$`Pr(>Chisq)`[2], 2)
prox_overlap_test_pvalue
```
---
## Encounters
In order to calculate the number of encounter events, we needed to estimate the Euclidean distance between the individuals in each dyads at each timepoint using the `ctmm` function `distances()`. From these separation distances we estimated the number of encounter events for each dyad using a 15m distance threshold. We also performed a sensitivity analysis on the 15m threshold.
### Estimating distance
```{r distance, eval = FALSE}
#create empty columns for the results to be saved to
proximity_df$distance_low <- NA
proximity_df$distance_est <- NA
proximity_df$distance_high <- NA
#create empty list for the results to be saved to
RES <- list()
#calculate the distance statistics
for (i in 1:nrow(overlap_df)) {
ANIMAL_A <- as.character(overlap_df[i, 'anteater_A'])
ANIMAL_B <- as.character(overlap_df[i, 'anteater_B'])
TRACKING_DATA <- DATA_TELEMETRY[c(ANIMAL_A, ANIMAL_B)]
MODELS <- list(FIT[[ANIMAL_A]], FIT[[ANIMAL_B]])
DISTANCES_RES <- tryCatch({
distances_result <- distances(data = TRACKING_DATA,
CTMM = MODELS,
GUESS = ctmm(error = FALSE))
data.frame(pair_ID = paste(ANIMAL_A, ANIMAL_B, sep = "_"),
distance_low = distances_result$low,
distance_est = distances_result$est,
distance_high = distances_result$high,
t = distances_result$t,
timestamp = distances_result$timestamp)
}, error = function(err) {
data.frame(pair_ID = paste(ANIMAL_A, ANIMAL_B, sep = "_"),
distance_low = NA,
distance_est = NA,
distance_high = NA,
t = NA,
timestamp = NA)
})
RES[[i]] <- DISTANCES_RES
#track progress
cat("finished index", i, "\n")
}
#turn the list of list into a dataframe
DATA_DISTANCE <- do.call(rbind, RES)
```
```{r eval = FALSE, echo=FALSE}
#save distance data
saveRDS(DATA_DISTANCE, file = "data/encounter/DATA_DISTANCE.rds")
```
```{r eval = FALSE}
#import the distance statistics data
DATA_DISTANCE <- readRDS("data/encounter/DATA_DISTANCE.rds")
#locate NA values within the dataframe
DATA_DISTANCE[!complete.cases(DATA_DISTANCE), ]
#drop the 3 fixes that had no distance values
DATA_DISTANCE <- na.omit(DATA_DISTANCE)
#add overlap and proximity information to the distance dataframe
distance_df <- merge(DATA_DISTANCE, proximity_df, by = "pair_ID")
distance_df <- relocate(distance_df, c(distance_low, distance_est, distance_high,
t, timestamp), .after = proximity_high)
```
```{r eval = FALSE, echo=FALSE}
#save the distance dataframe
save(distance_df, file = "data/encounter/distance_df.rda")
```
### Sensitivity analysis
```{r}
#set encounter radius
enc_radius <- 0:1000
enc_count <- vector("numeric", length(enc_radius))
#calculate the number of encounters occurring within each radius size
for(i in 1:length(enc_radius)){
enc_count[i] <- sum(distance_df$distance_est < enc_radius[i])
}
```
```{r eval=FALSE}
plot_enc_radius_count <-
ggplot() +
geom_line(aes(x = enc_radius, y = enc_count)) +
labs(x = "Encounter radius (m)",
y = "Encounter count (x1000)") +
scale_y_continuous(labels = function(enc_count) enc_count / 1000) +
theme_bw() +
theme(panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
plot.title = element_text( size = 14, family = "sans", face = "bold"),
axis.title.y = element_text(size=10, family = "sans", face = "bold"),
axis.title.x = element_text(size=10, family = "sans", face = "bold"),
axis.text.y = element_text(size=8, family = "sans"),
axis.text.x = element_text(size=8, family = "sans"),
legend.position="none",
panel.background = element_rect(fill = "transparent"),
legend.background = element_rect(fill = "transparent"),
plot.background = element_rect(fill = "transparent", color = NA),
plot.margin = unit(c(0.2,0.1,0.2,0.2), "cm"))
```
```{r eval=FALSE, echo=FALSE}
ggsave(plot_enc_radius_count,
file = "figures/individual figures/enc_radius_count.png",
width = 6.86, height = 3, units = "in", dpi = 600, bg = "transparent")
```
![](figures/individual figures/enc_radius_count.png)
```{r eval = FALSE, message=FALSE}
#sensitivity analysis on female-male encounter significance
#create empty columns for the results to be saved to
encounter_radius_pvalue <- vector("numeric", length(enc_radius))
pair_ID <- unique(overlap_df$pair_ID)
#loop over encounter radii
for(i in 1:length(enc_radius)){
res <- list()
for (j in pair_ID){
subset_A <- distance_df[distance_df$pair_ID == j,]
#count the number of times "distance_est" is below some threshold distance i
encounter_count <- sum(subset_A$distance_est < enc_radius[i])
#save results
res[[j]] <- data.frame(encounter_count = encounter_count,
overlap_est = subset_A$overlap_est[1],
sex_comparison = subset_A$sex_comparison[1],
site = subset_A$site[1])
}
res <- do.call(rbind, res)
encounter_radius_test <- try(glmer(encounter_count ~
overlap_est + sex_comparison + (1|site),
family = poisson(link = "log"),
data = res, subset = res > 0))
encounter_radius_test2 <- try(glmer(encounter_count ~ 1 + (1|site),
family = poisson(link = "log"),
data = res, subset = res > 0))
encounter_radius_test_results <- try(anova(encounter_radius_test, encounter_radius_test2))
p_val <- try(encounter_radius_test_results$`Pr(>Chisq)`[2])
encounter_radius_pvalue[i] <- ifelse(class(p_val) == "try-error", NA, p_val)
#track progress
cat("finished index", i, "\n")
}
#create an encounter radius dataframe
encounter_radius_df <- data.frame(x = enc_radius,
y = encounter_radius_pvalue)
saveRDS(encounter_radius_df, file = "data/encounter/encounter_radius_df.RDS")
```
```{r eval=FALSE}
plot_enc_radius_pvalue <-
ggplot() +
geom_line(data = encounter_radius_df,
aes(x = x, y = y),
size = 0.15) +
geom_hline(yintercept = 0.05, linetype = "dashed", color = "red") +
xlab("Encounter radius (m)") +
ylab("p-value") +
theme_bw() +
theme(panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
plot.title = element_text(size = 14, family = "sans", face = "bold"),
axis.title.y = element_text(size=10, family = "sans", face = "bold"),
axis.title.x = element_text(size=10, family = "sans", face = "bold"),
axis.text.y = element_text(size=8, family = "sans"),
axis.text.x = element_text(size=8, family = "sans"),
panel.background = element_rect(fill = "transparent"),
plot.background = element_rect(fill = "transparent", color = NA),
plot.margin = unit(c(0.1,0.1,0.05,0.2), "cm")) #top, right, bot, left)
```
```{r eval=FALSE, echo=FALSE}
ggsave(plot_enc_radius_pvalue,
file = "figures/individual figures/enc_radius_pvalue.png",
width = 6.86, height = 3, units = "in", dpi = 600, bg = "transparent")
```
![](figures/individual figures/enc_radius_pvalue.png)
### Estimating encounters
```{r encounters}
#create an empty column for the results to be saved to
proximity_df$encounter_count <- NA
pair_ID <- unique(proximity_df$pair_ID)
#calculate total encounters of all individuals based on sex comparison type
for (i in pair_ID){
subset_A <- distance_df[distance_df$pair_ID == i,]
#count the number of times distance is below 15
encounter_count <- sum(subset_A$distance_est < 15)
#save results
proximity_df[proximity_df$pair_ID == i, "encounter_count"] <- encounter_count
}
#number of pairs that had 0 encounters
proximity_df[proximity_df$encounter_count == 0,]
#number of pairs that had at least 1 encounter
proximity_df[proximity_df$encounter_count != 0,]
#calculate the number of encounters based on threshold of 15m
sum(proximity_df$encounter_count)
sum(proximity_df$encounter_count[proximity_df$sex_comparison == "male-male"])
sum(proximity_df$encounter_count[proximity_df$sex_comparison == "female-female"])
sum(proximity_df$encounter_count[proximity_df$sex_comparison == "female-male"])
```
### Encounter results
We used a GLMM with a Poisson distribution, a log link function, and site as a random effect to determine whether encounter rates differed between the pairwise sex combinations. This model was then compared to similar model that excluded the pairwise sex predictor variable using a likelihood ratio test. Additionally, we used a Hierarchical Generalized Additive Model (HGAM) with a Poisson distribution, a log link function, to test for any temporal trends in encounters.
```{r encounter-analysis}
#effect of sex and overlap on encounter rates and does not include 0 encounter counts
encounter_test <- glmer(encounter_count ~ overlap_est + sex_comparison + (1|site),
family = poisson(link = "log"),
data = proximity_df, subset = encounter_count > 0)
encounter_test2 <- glmer(encounter_count ~ 1 + (1|site),
family = poisson(link = "log"),
data = proximity_df, subset = encounter_count > 0)
encounter_test_results <- anova(encounter_test, encounter_test2)
encounter_test_results
encounter_test_pvalue <- round(encounter_test_results$`Pr(>Chisq)`[2], 2)
encounter_test_pvalue
#amount of home-range overlap and the number of observed encounters
summary(encounter_test)
```
<hr style="border: 1px solid black;">
# **Correlated Movement**
To evaluate if pairs of giant anteaters exhibited any correlation in their movement, all dyads with a proximity ratio that differed significantly from 1 (based on the 95% confidence interval) were identified and carried forward to our subsequent, correlated movement analysis.
## Exploring deviations in proximity ratios
```{r eval = FALSE}
#identify pairs that did not have a proximity ratio of 1
proximity_above1 <- proximity_df[proximity_df$proximity_low > 1,]
proximity_below1 <- proximity_df[proximity_df$proximity_high < 1,]
#exclude pairs with a HR overlap of 0
proximity_below1[proximity_below1$overlap_est < 0.0001,]
proximity_below1 <- proximity_below1[!(proximity_below1$overlap_est < 0.0001),]
#create a dataframe of the deviated pairs
proximity_identified_pairs_df <- rbind(proximity_above1, proximity_below1)
proximity_identified_pairs_df$pair_ID_number <- seq(from = 1, to = 12, by = 1)
proximity_identified_pairs_df <- relocate(proximity_identified_pairs_df, pair_ID_number, .before = anteater_A)
#correct the sex_comparison output to female-male
proximity_identified_pairs_df <- mutate(proximity_identified_pairs_df, sex_comparison =
case_when(paste(Sex.A, Sex.B) == "Male Male" ~ "male-male",
paste(Sex.A, Sex.B) == "Female Female" ~ "female-female",
paste(Sex.A, Sex.B) == "Male Female" ~ "female-male",
paste(Sex.A, Sex.B) == "Female Male" ~ "female-male"))
#clean up environment
rm(proximity_above1, proximity_below1)
```
```{r eval=FALSE, echo=FALSE}
#save deviated pairs dataframe
save(proximity_identified_pairs_df, file = "data/encounter/proximity_identified_pairs_df.rda")
```
## Deviated pairs results
```{r prox-pair-analysis}
#number of pairs with a deviated proximity ratio based on sex comparison
table(proximity_identified_pairs_df$sex_comparison)
#test for significance in sex, compare model with and without sex as a variable
proximity_test_pairs <- glmer(proximity_est ~ sex_comparison + (1|site),
family = Gamma(link = "log"),
data = proximity_identified_pairs_df)
proximity_test2_pairs <- glmer(proximity_est ~ 1 + (1|site),
family = Gamma(link = "log"),
data = proximity_identified_pairs_df)
proximity_test_results_pairs <- anova(proximity_test_pairs, proximity_test2_pairs)
proximity_test_results_pairs
proximity_test_pvalue_pairs <- round(proximity_test_results_pairs$`Pr(>Chisq)`[2], 2)
proximity_test_pvalue_pairs
#test for significance in home-range overlap, compare model with and without overlap as a variable
prox_overlap_test_pairs <- glmer(proximity_est ~ overlap_est + (1|site),
family = Gamma(link = "log"),
data = proximity_identified_pairs_df)
prox_overlap_test2_pairs <- glmer(proximity_est ~ 1 + (1|site),
family = Gamma(link = "log"),
data = proximity_identified_pairs_df)
prox_overlap_test_results_pairs <- anova(prox_overlap_test_pairs, prox_overlap_test2_pairs)
prox_overlap_test_results_pairs