cois: Correlation of Interaction Similarity for connector nodes

View source: R/cois.R

coisR Documentation

Correlation of Interaction Similarity for connector nodes

Description

Calculating correlation of interaction similarity for connector nodes.

Usage

cois(
  network.or.subnet_mat1,
  subnet_mat2 = NULL,
  weighted = FALSE,
  method = "kendall"
)

Arguments

network.or.subnet_mat1

An igraph object or matrix. An "igraph" object with node attribute 'level' or a matrix representing one subnetwork. See details.

subnet_mat2

A matrix representing one subnetwork.

weighted

Logical. Default to FALSE. See details.

method

Correlation method ("pearson", "kendall" or "spearman"). Default to "kendall".

Details

In this package, a tripartite network contains three groups of nodes (a-nodes,b-nodes,c-nodes) and two subnetworks (P includes the links between a-nodes and b-nodes, Q includes the links between b-nodes and c-nodes). Connector nodes belong to b-nodes.

This function follows Sauve et al.(2016) to calculate the correlation of interaction similarity of connector nodes. When weighted=FALSE, the Jaccard similarity coefficients between all pairs of connector nodes in each subnetwork, defined as the number of shared interaction partners divided by the total number of interaction partners involved (i.e. the maximum number of interactions they could share). When weighted=TRUE, the quantitative similarities of all pairs of connector nodes in each subnetwork were measured using the generalised Jaccard coefficient. Three correlation methods are provided. Kendall correlation is recommended following Sauve et al.(2016).

Two types of inputs network.or.subnet_mat1 can be processed:

  • An "igraph" object with node attribute 'level' (0 for a-nodes, 1 for b-nodes,2 for c-nodes). If the input is a weighted network, the edge should have a 'weight' attribute.

  • Or a matrix representing subnetwork P, and must be input with subnet_mat2 representing subnetwork Q.

If the inputs are two matrices, please make sure the rows of network.or.subnet_mat1 and subnet_mat2 both represent the groups of connector species,i.e, the b-group species. If both matrices have row names, then the function matches row names to produce connector nodes. Otherwise, row numbers are assigned to row names and matched. Within the two matrices (P and Q), columns represents a-group nodes and c-group nodes respectively. Elements in matrices are non-zero values if two nodes are linked with or without weights, and 0 otherwise.

Value

Return a numeric value representing correlation of interaction similarity for connector species.

References

Sauve, A. M., Thebault, E., Pocock, M. J., & Fontaine, C. (2016). How plants connect pollination and herbivory networks and their contribution to community stability. Ecology, 97(4), 908-917.

Examples


## generate a random binary tripartite network
set.seed(12)
Net <- build_toy_net(11,15,16,0.2)
cois(Net)
## empirical network
data(PPH_Coltparkmeadow)
Net <- PPH_Coltparkmeadow
cois(Net)
set.seed(13)
library(igraph)
E(Net)$weight<-runif(length(E(Net)),0.1,1.5)#random weights assigned
cois(Net,weighted=TRUE)

##input as binary matrices,with row names.
md1 <- matrix(sample(c(0,1),8*11,replace=TRUE),8,11,
       dimnames = list(paste0("b",1:8),paste0("c",1:11)))
md2 <- matrix(sample(c(0,1),10*12,replace=TRUE),10,12,
       dimnames = list(paste0("b",1:10),paste0("a",1:12)))
cois(md1,md2)

##input as weighted matrices,with row numbers as row names.
mdw1 <- matrix(sample(c(rep(0,40),runif(48,0,1))),8,11)
mdw2 <- matrix(sample(c(rep(0,40),runif(80,0,1))),10,12)
cois(mdw1,mdw2)
cois(mdw1,mdw2,weighted=TRUE)


ILSM documentation built on Aug. 8, 2025, 7:42 p.m.