Individual patch connectivity

February 27, 2019
By

(This article was first published on R Code – Geekcologist , and kindly contributed to R-bloggers)

Answering questions from users is actually a good way to find potentially interesting things to post…

With the obvious advantage that other people might find it useful too!

So… let’s start… This MetaLandSim user wanted a way to derive the contribution of each individual patch to overall landscape connectivity. Here I used the method presented in the paper by Saura & Pascual-Hortal (2007) “A new habitat availability index to integrate connectivity in landscape conservation planning: Comparison with existing indices and application to a case study“, using his Integral Index of Connectivity (IIC) and equation 1 to derive each patch relevance to overall connectivity.

As allways, start by loading the package:

library(MetaLandSim)

Now, we create a new landscape graph (rl1), which will be plotted if we set plotG to TRUE:

set.seed(123)

rl1 <- rland.graph(mapsize=500, dist_m=50, areaM=0.1, 
    areaSD=0.02, Npatch=50,
    disp=70, plotG=TRUE)

fig1

This landscape has 50 patches, and we eant to know each individual dIIC, or their individual contribution to connectivity.

If we are following eq. 1 on Saura’s paper we have to start by computing the IIC of the full landscape, with all the patches (full.IIC):

#as.numeric is just to guarantee the output is just a number
full.IIC <- as.numeric(metrics.graph (rl=rl1, metric="IIC"))

Now we extract the data frame with the information on the patches:

patches <- rl1$nodes.characteristics

#Here are the top 6 rows:
head(patches)
##           x        y      areas   radius cluster    colour nneighbour ID
## 1 143.78876 394.1526 0.08410288 16.36178       1 #FF0000FF   64.01614  1
## 2 132.51637 282.2952 0.07285381 15.22829       1 #FF0000FF   51.84446  2
## 3 338.78532 286.3167 0.12808067 20.19142       1 #FF0000FF   67.61306  3
## 4  12.30684 238.8980 0.08026654 15.98425       1 #FF0000FF   67.02337  4
## 5 275.71751 228.3074 0.13367483 20.62766       1 #FF0000FF   50.44706  5
## 6  71.40001 207.2732 0.08448427 16.39883       1 #FF0000FF   51.92737  6

Then we create a vector to insert the values of the partial IIC (dIIC). I had to modify the function removepoints, which I had originally in the package. The original version removes a number of patches randomly. This adapted version removes one specific patch (by ID), it’s called removepoints.byID.

dIIC <- rep(NA, 50)

#the new version of the function:
removepoints.byID <-
function (rl, nr=1, ID)
  {
if (class(rl)!="landscape") 
  {
    stop(paste(rl, " should be an object of class class 'landscape'.", sep=""), call. = FALSE)
  } 
    mapsize2 <- rl$mapsize
    dist_m2 <- rl$minimum.distance
    areaM2 <- rl$mean.area
    areaSD2 <- rl$SD.area
    Npatch2 <- rl$number.patches
    disp2 <- rl$dispersal
    rl_0 <- rl$nodes.characteristics
    ID2 <- rl_0$ID
    nr_select <- nrow(rl_0)-nr
    rl_1 <- rl_0[-ID, ]
    rl_2 <- rl_1[sort.list(as.numeric(rownames(rl_1))), ]
    names(rl_2)[names(rl_2) == "ID2"] <- "ID"
    rl_3 <- list(mapsize=mapsize2, minimum.distance=dist_m2,
                 mean.area=mean(rl_2$areas), SD.area=sd(rl_2$areas),
                 number.patches=nrow(rl_2), dispersal=disp2,
                 nodes.characteristics=rl_2)
    class(rl_3) <- "landscape"
    rl_4 <- cluster.id(rl_3)
    rownames(rl_4$nodes.characteristics) <- 1:nrow(rl_4$nodes.characteristics)
    class(rl_4) <- "landscape"
    return(rl_4)
  }

Finally… compute the dIIC (partial connectivity) to each patch:

#Set up the loop to do the calculations
for (i in 1:50){

rl2 <- rl1 #This is just no to change rl1

rl3 <- removepoints.byID(rl1,ID=i)#removing patch i

partial.IIC <- as.numeric(metrics.graph (rl=rl3, metric="IIC"))

dIIC[i] <- 100*((full.IIC-partial.IIC)/full.IIC)#send the result to the vector

}

#And here's the result:

dIIC

##  [1]  3.4090909 14.7727273  7.9545455  2.8409091 13.0681818  5.1136364
##  [7]  2.8409091  7.9545455  7.3863636  6.8181818 11.3636364  3.9772727
## [13]  3.4090909 10.7954545  3.4090909 13.6363636 15.9090909  2.2727273
## [19]  3.9772727  2.2727273  1.7045455  0.5681818  1.7045455  1.7045455
## [25]  3.4090909  2.8409091  1.1363636  4.5454545  2.2727273 10.2272727
## [31]  5.6818182  2.8409091  6.8181818  3.9772727  6.2500000  7.3863636
## [37]  3.4090909  1.1363636  2.2727273  2.2727273  0.5681818  1.7045455
## [43]  2.8409091  4.5454545  2.2727273  1.7045455  2.8409091  3.9772727
## [49]  1.1363636  2.2727273

Let’s plot it:

plot_graph(rl=rl1, species=FALSE, links=TRUE)

#The individual connectivity patches
text(x = patches[,'x'],y = patches[,'y'], pos = 3, 
offset = 0.2, labels = round(dIIC,2))

fig2.jpg

And that’s all.

To leave a comment for the author, please follow the link and comment on their blog: R Code – Geekcologist .

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers

Sponsors

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)