-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvignette.Rmd
121 lines (97 loc) · 6.63 KB
/
vignette.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
---
title: "Vignette wildxing"
author: "Guillaume Bastille-Rousseau"
date: "August 2, 2017"
output:
html_document: default
pdf_document: default
---
``` {r eval=T, echo=F, message=F, warning=F}
library(devtools)
#install_github("BastilleRousseau/wildxing")
library(wildxing)
library(adehabitatLT)
#library(raster)
library(sp)
#library(uuid)
#library(rgeos)
#library(adehabitatMA)
#library(CircStats)
#library(MASS)
#library(boot)
#library(Rsymphony)
```
The overall approach relies on a few simple steps: 1- Segmenting the linear features into segment of equal length, 2- Intersecting an animal trajectory with the segmented corridor, 3- Repeating for all individuals, 4- Optimizing based on population level responses. An additional function is also available that intersect home-range of an individual with the linear corridor to evaluate size of created fragments.
# 1- Segmenting of linear corridors in smaller fragments - *SegmentSpL*
The function *SegmentSpL* was taken from http://rstudio-pubs-static.s3.amazonaws.com/10685_1f7266d60db7432486517a111c76ac8b.html. This function split a *SpatialLines* object into segments of equal length.The user can specify how the last segment is considered (separated or merged). We can generate a SpatialLines object from scratch, apply the function using different segment lengths, and plot the resulting segmentation:<br> <br>
\newline
``` {r eval=T}
x <- c(0,0)
y <- c(-6500000,-4500000)
Spl<-SpatialLines(list(Lines(Line(cbind(x,y)), ID="a")))
t1<-SegmentSpL(Spl, n.parts=30, merge.last=F) #Segment in 20 parts
t2<-SegmentSpL(Spl, length=50000, merge.last=F) #Segment based on length
par(mfrow=c(1,2))
plot(t1, col = rep(c(1, 2), length.out = length(t2)), axes = T)
plot(t2, col = rep(c(1, 2), length.out = length(t2)), axes = T)
```
# 2- Intersect of an animal trajectory with a corridor - *corriIntersects*
The function *corriIntersects* intersect a trajectory object from *adehabitatLT* with a segmented corridor (the output of *SegmentSpL*). The user can specify if standardisation for the individual occured over the time or number of locations of sampling. THe former is more suitable when individuals have different frequency of location, but long gap in the data should be identified. The function include a plot option and also a separate function *plotcorri_ind*. We will intersect the corridor created earlier with an albatross individual which movement is provided by package *adehabitatLT*. Albatross (and all birds really,) are well known to be impacted by linear features!
<br> <br>
\newline
``` {r eval=T}
data (albatross) #From package adehabitatLT
#We are using the segmented corridor from previous step
t3<-corriIntersects(albatross[3], t1, plot=F)
par(mfrow=c(1,2))
plot(t1, col = rep(c(1, 2), length.out = length(t2)), axes = T)
plot(ltraj2sldf(albatross[3]), add=T)
plotcorri_ind(t3, nb_breaks=4)
```
# 3- Intersect of multiple animal trajectories with a corridor and population average - *corriIntersects_All* and *avg_inds*
*wildxing* also provides functions to facilitate the execution of the analysis over multiple individuals. *corriIntersects_All* is a wrapper that applies the function *corriIntersects* to all individual (not burst) of a *traj* object and produces a list contianing the analysis for each individual. *avg_inds* then takes this list and compute summary statistics at the population level. We will now perform the analysis using the same corridor as define in step 1, but applying it over all albatrosses.*plotcorri_grp* plot the output of *avg_inds* <br> <br>
\newline
``` {r eval=T}
data(albatross)
t4<-corriIntersects_All(albatross, t1)
length(t4) #6 different individuals
t5<-avg_inds(t4)
head(t5@data) #View at the column stored
par(mfrow=c(1:2))
plotcorri_grp(t5, nb_breaks=5, var=4, main="Counts")
plotcorri_grp(t5, nb_breaks=5, var=5, main="Individuals")
```
# 4- Optimization of crossing structures positioning - *corri_optim*
*optim_corri* takes the output of *avg_inds* and performs an optimization to select ideal segment for wildlife crossing structures. The algorithm maximizes the importance of a segment for crossing and the spatial spread among selected segment. The user can also specify a series of locations where segment that should be excluded or a series of locations where crossing structures will be added by default. These locations should be specified as *SpatialPoints* objects. Many additional arguments can be specifed (see help file for more details). The algorithm called the *Rsymphony* package using the *symphony* solver for linear programming. *plot_optim* plots the output of the function. <br> <br>
\newline
``` {r eval=T}
#Equal weight, minimum of 1 individual
opti1<-optim_mclp(t4, var=4, n=3, nb_ind=1, weight=0.5, plot=F)
#More weight to crossing, minimum of 2 individuals
opti2<-optim_corri(t5, var=4, n=3, nb_ind=3, weight=0.25, plot=F)
#Equal weight, additional point
Pts<-SpatialPoints(matrix(c(0,-5500000), nrow=1, ncol=2))
opti3<-optim_corri(t5, var=4, n=3, nb_ind=1, weight=0.5, add=Pts, plot=F)
par(mfrow=c(1,3))
plot_optim(t5, var=4, opti1, main="")
plot_optim(t5, var=4, opti2, main="")
plot_optim(t5, var=4, opti3, main="") #Additional points in red
```
# 5- Optimization of crossing structures positioning - *corri_mclp*
*optim_mclp* takes the output of *corriIntersects_All* and performs an optimization to select ideal segment for wildlife crossing structures using the maximum coverage location problem. The user can also specify a series of locations where segment that should be excluded or a series of locations where crossing structures will be added by default. These locations should be specified as *SpatialPoints* objects. Many additional arguments can be specifed (see help file for more details). The algorithm called the *Rsymphony* package using the *symphony* solver for linear programming. <br> <br>
\newline
``` {r eval=T}
#Two crossings
opti1<-optim_mclp(t4, n=2, dist=5*1000, plot=T)
opti1[[1]]$objval #All 6 individuals are covered by selected crossing.
```
# 6- Intersect of animal home-ranges with linear features - *hr_split*
We also provide a function that intersects a *SpatialPolygons* object with a *SpatialLines* object and return the segmented polygons and summary statistics. The function *hr_split* will return a list with the first element being the *SpatialPolygons* object. FOr this example, we will keep the same corridor and will generate an home-range for one albatross using the mcp function from the package *adehabitatLT*.
``` {r eval=T}
hr<-adehabitatHR::mcp(SpatialPoints(ld(albatross[3])[,1:2]))
plot(hr)
plot(Spl, add=T)
hr2<-hr_split(hr, Spl)
plot(hr2[[1]])#Plot fragmented home-range
hr2[2:4] #Summary statistics
```