View source: R/ig_overlap_guild.R
ig_overlap_guild | R Documentation |
Calculating species-level intra-guild and inter_guild interaction overlap for a tripartite network with intra-guild interactions.
ig_overlap_guild(mat, guilds, method = "horn")
mat |
A square block interaction matrix representing a tripartite network including intra-guild and inter-guild interactions. See details. |
guilds |
A character vector matching rows of |
method |
The distance method. Same with vegan::vegdist. Default to "horn" |
The input is a block matrix (M
) to represent interactions among three groups of species (a-nodes, b-nodes and c-nodes): three intra-guild interaction matrices (m_{aa},m_{bb},m_{cc}
),
two inter-guild matrices of a and b-nodes (m_{ab},m_{ba}
with symmetric links), and two inter-guild matrices of b- and c-nodes(m_{bc},m_{cb}
with symmetric links). Connector species belong to b-nodes.
\left(
\begin{array}{ccc}
m_{aa} & m_{ab} & 0 \\
m_{ba} & m_{bb} & m_{bc} \\
0 & m_{cb} & m_{cc}
\end{array}
\right)
guilds
should be a vector of the same length as the row of mat
like c("a","a"..."b","b"..."c","c"..)
This function follows the definition by Garcia-Callejas et al (2023). Species-level interaction overlap is derived from the overlap between each pair of species, calculated using the dissimilarity index (d_{ij}
, default to Morisita-Horn index) as in the R package vegan.
The net overlap of species (o_{i}
)is represented by the sum of pairwise overlaps with every other species:
o_i = \sum_{j \in S} (1 - d_{ij})
Return a list including three species-level intra-guild overlap vectors for a-, b- and c-nodes (a_intra_overlap,b_intra_overlap,c_intra_overlap), two vectors of inter-guild interaction overlap for a-nodes (a_inter_b_overlap) and b-nodes (b_inter_a_overlap), and two vectors of inter-guild interaction overlap for b-nodes (b_inter_c_overlap) and c-nodes(c_inter_b_overlap).
Garcia-Callejas, D., Godoy, O., Buche, L., Hurtado, M., Lanuza, J.B., Allen-Perkins, A. et al. (2023) Non-random interactions within and across guilds shape the potential to coexist in multi-trophic ecological communities. Ecology Letters, 26, 831-842.
##A toy tripartite network with intra-guild negative interactions,
##Inter-guild mutualistic interactions and inter-guild antagonistic interactions.
set.seed(12)
##4 a-nodes, 5 b-nodes, and 3 c-nodes
##Intra-guild interaction matrices
mat_aa<-matrix(runif(16,-0.8,-0.2),4,4)
mat_bb<-matrix(runif(25,-0.8,-0.2),5,5)
mat_cc<-matrix(runif(9,-0.8,-0.2),3,3)
##Inter-guild interaction matrices between a- and b-nodes.
mat_ab<-mat_ba<-matrix(sample(c(rep(0,8),runif(12,0,0.5))),4,5,byrow=TRUE)
mat_ba[mat_ba>0]<-runif(12,0,0.5);mat_ba<-t(mat_ba)
##Inter-guild interaction matrices between b- and c-nodes.
mat_cb<-mat_bc<-matrix(sample(c(rep(0,8),runif(7,0,0.5))),3,5,byrow=TRUE)
mat_bc[mat_bc>0]<-runif(7,0,0.5);mat_bc<--t(mat_bc)
mat<-rbind(cbind(mat_aa,mat_ab,matrix(0,4,3)),cbind(mat_ba,mat_bb,mat_bc))
mat<-rbind(mat,cbind(matrix(0,3,4),mat_cb,mat_cc))
##Set the node names
rownames(mat)<-c(paste0("a",1:4),paste0("b",1:5),paste0("c",1:3))
colnames(mat)<-c(paste0("a",1:4),paste0("b",1:5),paste0("c",1:3))
diag(mat)<--1 #assume -1 for diagonal elements
##Visualization of this block matrix.
library(plot.matrix)
pal <- colorRampPalette(c("darkblue", "lightblue", "white", "pink", "darkred"))(100)
par(mar=c(5,5,5,5));plot(mat,col = pal,
breaks = seq(-max(abs(mat)), max(abs(mat)), length.out = 101),
main = "Matrix visualization")
clip(x1 = 0.5,# Left boundary
x2 = ncol(mat) + 0.5, # Right boundary
y1 = 0.5, # Top boundary
y2 = nrow(mat) + 0.5 )
abline(v = c(4.5,9.5), h = c(3.5,8.5), lwd = 3, col = "black")
myguilds=c(rep("a",4),rep("b",5),rep("c",3))
ig_overlap_guild(mat,guilds=myguilds)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.