Package 'ILSM'

Title: Analyze Interconnection Structure of Multilayer Interaction Networks
Description: In view of the analysis of the structural characteristics of the multilayer network has been complete, however, there is still a lack of a unified operation that can quickly obtain the corresponding characteristics of the multilayer network. To solve this insufficiency, 'ILSM' was designed for supporting calculating such metrics of multilayer networks by functions of this R package.
Authors: WeiCheng Sun [aut, cre], Chuan Yan [aut], Yangyang Zhao [aut]
Maintainer: WeiCheng Sun <[email protected]>
License: MIT + file LICENSE
Version: 1.0.3.2
Built: 2024-11-04 06:43:20 UTC
Source: CRAN

Help Index


Generating tripartite network

Description

Generating a network of three layers. All layers of network contain lay_0, lay_1 and lay_2 nodes respectively.

Usage

build_net(lay_0, lay_1, lay_2, C_lay, asmatrices = FALSE)

Arguments

lay_0

The number of nodes in the first layer.

lay_1

The number of nodes in the second layer.

lay_2

The number of nodes in the third layer.

C_lay

The probability of each node interact with the other one. It ranges from 0 to 1.

asmatrices

Logical. whether to output the overall adjacency matrix of the network and the corresponding interaction matrix of the respective subnetworks. Defaults to FALSE.

Value

Return a tripatite network of direction. The network contains three groups of species and interactions within layers, and there is no link among each group of nodes within one layer.

Examples

set.seed(12)
d <- build_net(11,15,16,0.2)
plot(d)

set.seed(12)
N <- build_net(11,15,16,0.2,asmatrices=FALSE)
N

Correlation of Interaction Degree: CoID

Description

Calculating correlation of interaction degree among subnetworks ("CoID_~").

Usage

coid(network.or.subnet_mat1, subnet_mat2 = NULL, weighted = FALSE)

Arguments

network.or.subnet_mat1

Either a multilayer(tripartite) network of 'igraph' class which contains three groups of species and interactions within layers without interactions between each group of species, or a numeric matrix(or data.frame) representing interactions between two groups of species. Each row and column of matrix represents single species in the second and first groups of the tripartite network respectively. Elements of matrix are non-zero numbers if the two groups of species are connected, and 0 otherwise.

subnet_mat2

A numeric matrix(or data.frame) representing interactions between two groups of species. Each row and column of matrix represents single species in the second and third groups of the tripartite network respectively. Elements of matrix are non-zero numbers if the two groups of species are connected, and 0 otherwise. If network.or.subnet_mat1 is "igraph", subnet_mat2 defaults to NULL.

weighted

Logical. should elements of matrix be fractional? Default to FALSE. Generally, 'igraph' network represent a spare matrix, so weighted is FALSE. While elements of matrix represent interaction strength, weighted is TRUE.

Details

weighted

If the weighted = FALSE, the input for the parameter can be:

  • network.or.subnet_mat1: input a 'igraph' of network data independently or input sparse matrix together with subnet_mat2.

If the weighted = TRUE, the input for the parameter can be:

  • network.or.subnet_mat1: must input matrix(or data.frame) together with subnet_mat2. the matrix can be sparse matrix and matrix of interaction strength.

network.or.subnet_mat1 and subnet_mat2

There are two types of network.or.subnet_mat1 that can be processed:

  • (1). Input in a network of type "igraph" alone.

  • (2). Must be entered as data frame or matrix with subnet_mat2.

If the type of inputting is data frame or matrix, please make sure the row of network.or.subnet_mat1 and subnet_mat2 correspond with the second group of species that both belong to two subnetworks and interact with other groups of species.

  • Try to make the rows of both matrices have the same attributes. Or we default:

  • When the two matrices can have different numbers of rows:

    • (1). If both matrices have row names, then the function counts all row names to produce two new matrices with the same row names.

    • (2). If at most one matrix has row names, the function assigns new row names to both matrices on a row-to-row basis (any extra row names are assigned a new value) and then counts all row names to produce two new matrices with the same row names.

  • When the two matrices can have the same numbers of rows:

    • No matter how the row names of the two matrices are arranged, as long as the row names are exactly the same; But we don't handle matrices with empty row names (the function will give an error).

  • The two matrices can have different numbers of rows, but read our default handling carefully to make sure the calculation is accurate when using this function!!!

About a network of type "igraph", It can be obtained from the connection matrices of subnetworks by the function igraph_from_matrices.

Value

Return a numeric value representing correlation of interaction degree: CoID.

If weighted = FALSE, the results will show "CoID= ;" and If weighted = TRUE, the results will show "CoID_weight= ;"

References

Sauve, A. M., Thébault, 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

set.seed(12)
d <- build_net(11,15,17,0.2)
coid(d)

md1<-matrix(sample(c(0,1),110,replace=TRUE),10,11)
md2<-matrix(sample(c(0,1),120,replace=TRUE),10,12)
coid(md1,md2)
coid(md1,md2,weighted=TRUE)

md1<-matrix(sample(c(0,1),80,replace=TRUE),8,10)
md2<-matrix(sample(c(0,1),120,replace=TRUE),10,12)
coid(md1,md2)

mdw1<-matrix(runif(110,0,1),10,11)
mdw2<-matrix(runif(120,0,1),10,12)
coid(mdw1,mdw2,weighted=TRUE)

set.seed(1)
mdw1<-matrix(runif(80,0,1),8,10)
mdw2<-matrix(runif(120,0,1),10,12)
coid(mdw1,mdw2,weighted=TRUE)

Correlation of Interaction Similarity for Shared species: CoIS

Description

Calculating correlation of interaction similarity for shared species("COis_ ~") in two subnetworks.

Usage

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

Arguments

network.or.subnet_mat1

Either a multilayer(tripartite) network of 'igraph' class which contains three groups of species and interactions within layers without interactions between each group of species, or a numeric matrix(or data.frame) representing interactions between two groups of species. Each row and column of matrix represents single species in the second and first groups of the tripartite network respectively. Elements of matrix are non-zero numbers if the two groups of species are connected, and 0 otherwise.

subnet_mat2

A numeric matrix(or data.frame) representing interactions between two groups of species. Each row and column of matrix represents single species in the second and third groups of the tripartite network respectively. Elements of matrix are non-zero numbers if the two groups of species are connected, and 0 otherwise. If network.or.subnet_mat1 is "igraph", subnet_mat2 defaults to NULL.

weighted

Logical. should elements of matrix be fractional? Default to FALSE. Generally, 'igraph' network represent a spare matrix, so weighted is FALSE. While elements of matrix represent interaction strength, weighted is TRUE.

Details

weighted

If the weighted = FALSE, the input for the parameter can be:

  • network.or.subnet_mat1: input a 'igraph' of network data independently or input sparse matrix together with subnet_mat2.

If the weighted = TRUE, the input for the parameter can be:

  • network.or.subnet_mat1: must input matrix(or data.frame) together with subnet_mat2. the matrix can be sparse matrix and matrix of interaction strength.

network.or.subnet_mat1 and subnet_mat2

There are two types of network.or.subnet_mat1 that can be processed:

  • (1). Input in a network of type "igraph" alone.

  • (2). Must be entered as data frame or matrix with subnet_mat2.

If the type of inputting is data frame or matrix, please make sure the row of network.or.subnet_mat1 and subnet_mat2 correspond with the second group of species that both belong to two subnetworks and interact with other groups of species.

  • Try to make the rows of both matrices have the same attributes. Or we default:

  • When the two matrices can have different numbers of rows:

    • (1). If both matrices have row names, then the function counts all row names to produce two new matrices with the same row names.

    • (2). If at most one matrix has row names, the function assigns new row names to both matrices on a row-to-row basis (any extra row names are assigned a new value) and then counts all row names to produce two new matrices with the same row names.

  • When the two matrices can have the same numbers of rows:

    • No matter how the row names of the two matrices are arranged, as long as the row names are exactly the same; But we don't handle matrices with empty row names (the function will give an error).

  • The two matrices can have different numbers of rows, but read our default handling carefully to make sure the calculation is accurate when using this function!!!

About a network of type "igraph", It can be obtained from the connection matrices of subnetworks by the function igraph_from_matrices.

Value

Return a numeric value representing correlation of interaction similarity for shared species among subnetworks .

If weighted = FALSE, the results will show "CoIS= ;" and If weighted = TRUE, the results will show "CoIS_weight= ;"

References

Sauve, A. M., Thébault, 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

set.seed(12)
d <- build_net(11,15,17,0.2)
cois(d)

md1<-matrix(sample(c(0,1),110,replace=TRUE),10,11)
md2<-matrix(sample(c(0,1),120,replace=TRUE),10,12)
cois(md1,md2)
cois(md1,md2,weighted=TRUE)

md1<-matrix(sample(c(0,1),80,replace=TRUE),8,10)
md2<-matrix(sample(c(0,1),120,replace=TRUE),10,12)
cois(md1,md2)

mdw1<-matrix(runif(110,0,1),10,11)
mdw2<-matrix(runif(120,0,1),10,12)
cois(mdw1,mdw2,weighted=TRUE)

set.seed(1)
mdw1<-matrix(runif(80,0,1),8,10)
mdw2<-matrix(runif(120,0,1),10,12)
cois(mdw1,mdw2,weighted=TRUE)

Counting the degree hub of multilayer network

Description

This function counts degree hub that the proportion of interconnecting species serving as the core node of the network degree.

Usage

hc(network.or.subnet_mat1, subnet_mat2 = NULL)

Arguments

network.or.subnet_mat1

Either a multilayer(tripartite) network of 'igraph' class which contains three groups of species and interactions within layers without interactions between each group of species, or a numeric matrix(or data.frame) representing interactions between two groups of species. Each row and column of matrix represents single species in the second and first groups of the tripartite network respectively. Elements of matrix are non-zero numbers if the two groups of species are connected, and 0 otherwise.

subnet_mat2

A numeric matrix(or data.frame) representing interactions between two groups of species. Each row and column of matrix represents single species in the second and third groups of the tripartite network respectively. Elements of matrix are non-zero numbers if the two groups of species are connected, and 0 otherwise. If network.or.subnet_mat1 is "igraph", subnet_mat2 defaults to NULL.

Details

network.or.subnet_mat1 and subnet_mat2

There are two types of network.or.subnet_mat1 that can be processed:

  • (1). Input in a network of type "igraph" alone.

  • (2). Must be entered as data frame or matrix with subnet_mat2.

If the type of inputting is data frame or matrix, please make sure the row of network.or.subnet_mat1 and subnet_mat2 correspond with the second group of species that both belong to two subnetworks and interact with other groups of species.

  • Try to make the rows of both matrices have the same attributes. Or we default:

  • (1). If both matrices have row names, then the function counts all row names to produce two new matrices with the same row names.

  • (2). If at most one matrix has row names, the function assigns new row names to both matrices on a row-to-row basis (any extra row names are assigned a new value) and then counts all row names to produce two new matrices with the same row names.

  • The two matrices can have different numbers of rows, but read our default handling carefully to make sure the calculation is accurate when using this function!!!

About a network of type "igraph", It can be obtained from the connection matrices of subnetworks by the function igraph_from_matrices.

Value

Print a "hc= ;" and Return a numeric value representing the degree hub of network.

References

Battiston, F., Nicosia, V. & Latora, V. (2014) Structural measures for multiplex networks. Physical Review E, 89, 032804.

Domínguez-García, V., & Kéfi, S. (2024). The structure and robustness of ecological networks with two interaction types. PLOS Computational Biology, 20(1), e1011770.

Guimera, R. & Amaral, L.A.N. (2005) Cartography of complex networks: modules and universal roles. Journal of Statistical Mechanics: Theory and Experiment, 2005, P02001.

Examples

set.seed(15)
d <- build_net(11,15,17,0.2)
hc(d)

md1<-matrix(sample(c(0,1),80,replace=TRUE),8,10)
md2<-matrix(sample(c(0,1),120,replace=TRUE),10,12)
hc(md1,md2)

mdw1<-matrix(sample(c(rep(0,60),runif(60,0,1))),12,10)
mdw2<-matrix(sample(c(rep(0,40),runif(80,0,1))),10,12)
hc(mdw1,mdw2)

Calculating the number of 48 motifs

Description

Calculating the number of 48 motifs from a tripartite interaction network.

Usage

icmotif_count(network.or.subnet_mat1, subnet_mat2 = NULL)

Arguments

network.or.subnet_mat1

Either a multilayer(tripartite) network of 'igraph' class which contains three groups of species and interactions within layers without interactions between each group of species, or a numeric matrix(or data.frame) representing interactions between two groups of species. Each row and column of matrix represents single species in the second and first groups of the tripartite network respectively. Elements of matrix are non-zero numbers if the two groups of species are connected, and 0 otherwise.

subnet_mat2

A numeric matrix(or data.frame) representing interactions between two groups of species. Each row and column of matrix represents single species in the second and third groups of the tripartite network respectively. Elements of matrix are non-zero numbers if the two groups of species are connected, and 0 otherwise. If network.or.subnet_mat1 is "igraph", subnet_mat2 defaults to NULL.

Details

network.or.subnet_mat1 and subnet_mat2

There are two types of network.or.subnet_mat1 that can be processed:

  • (1). Input in a network of type "igraph" alone.

  • (2). Must be entered as data frame or matrix with subnet_mat2.

If the type of inputting is data frame or matrix, please make sure the row of network.or.subnet_mat1 and subnet_mat2 correspond with the second group of species that both belong to two subnetworks and interact with other groups of species.

  • Try to make the rows of both matrices have the same attributes. Or we default:

  • When the two matrices can have different numbers of rows:

    • (1). If both matrices have row names, then the function counts all row names to produce two new matrices with the same row names.

    • (2). If at most one matrix has row names, the function assigns new row names to both matrices on a row-to-row basis (any extra row names are assigned a new value) and then counts all row names to produce two new matrices with the same row names.

  • When the two matrices can have the same numbers of rows:

    • No matter how the row names of the two matrices are arranged, as long as the row names are exactly the same; But we don't handle matrices with empty row names (the function will give an error).

  • The two matrices can have different numbers of rows, but read our default handling carefully to make sure the calculation is accurate when using this function!!!

About a network of type "igraph", It can be obtained from the connection matrices of subnetworks by the function igraph_from_matrices.

Value

Return a numeric vector with the number of 48 motifs: M111, M112, M113, M114, M211, M212, M213, M311, M312, M411, M121_1, M122_1, M122_2, M122_3, M123_1, M123_2, M123_3, M123_4, M123_5, M221_1, M221_2, M221_3, M222_1, M222_2, M222_3, M222_4, M222_5, M222_6, M222_7, M222_8, M222_8, M321_1, M321_2, M321_3, M321_4, M321_5, M131, M132-1, M132-2, M132-3, M132-4, M132-5, M231-1, M231-2, M231-3, M231-4, M231-5, M141.

References

Pilosof, S., Porter, M. A., Pascual, M., & Kéfi, S. (2017). The multilayer nature of ecological networks. Nature Ecology & Evolution, 1(4), 0101.

Simmons, B. I., Sweering, M. J., Schillinger, M., Dicks, L. V., Sutherland, W. J., & Di Clemente, R. (2019). bmotif: A package for motif analyses of bipartite networks. Methods in Ecology and Evolution, 10(5), 695-701.

Examples

set.seed(12)
d <- build_net(11,22,21,0.2)
m <- icmotif_count(d)
m

set.seed(12)
d <- build_net(11,22,21,0.2,asmatrices=TRUE)

MAT<-d
icmotif_count(MAT[[3]],MAT[[4]])

md1<-matrix(sample(c(0,1),120,replace=TRUE),8,15)
md2<-matrix(sample(c(0,1),120,replace=TRUE),10,12)
icmotif_count(md1,md2)

R<-rownames(MAT[[4]])[12]
MR<-MAT[[4]][12,]
MAT[[4]]<-MAT[[4]][-12,]
MAT[[4]]<-rbind(MAT[[4]],MR)
rownames(MAT[[4]])[22]<-R

icmotif_count(MAT[[3]],MAT[[4]])

Analyzing role of interconnecting node in motifs

Description

Counting the number of 70 roles about interconnecting species in multilayer network motifs.

Usage

icmotif_role(network.or.subnet_mat1, subnet_mat2 = NULL)

Arguments

network.or.subnet_mat1

Either a multilayer(tripartite) network of 'igraph' class which contains three groups of species and interactions within layers without interactions between each group of species, or a numeric matrix(or data.frame) representing interactions between two groups of species. Each row and column of matrix represents single species in the second and first groups of the tripartite network respectively. Elements of matrix are non-zero numbers if the two groups of species are connected, and 0 otherwise.

subnet_mat2

A numeric matrix(or data.frame) representing interactions between two groups of species. Each row and column of matrix represents single species in the second and third groups of the tripartite network respectively. Elements of matrix are non-zero numbers if the two groups of species are connected, and 0 otherwise. If network.or.subnet_mat1 is "igraph", subnet_mat2 defaults to NULL.

Details

network.or.subnet_mat1 and subnet_mat2

There are two types of network.or.subnet_mat1 that can be processed:

  • (1). Input in a network of type "igraph" alone.

  • (2). Must be entered as data frame or matrix with subnet_mat2.

If the type of inputting is data frame or matrix, please make sure the row of network.or.subnet_mat1 and subnet_mat2 correspond with the second group of species that both belong to two subnetworks and interact with other groups of species.

  • Try to make the rows of both matrices have the same attributes. Or we default:

  • When the two matrices can have different numbers of rows:

    • (1). If both matrices have row names, then the function counts all row names to produce two new matrices with the same row names.

    • (2). If at most one matrix has row names, the function assigns new row names to both matrices on a row-to-row basis (any extra row names are assigned a new value) and then counts all row names to produce two new matrices with the same row names.

  • When the two matrices can have the same numbers of rows:

    • No matter how the row names of the two matrices are arranged, as long as the row names are exactly the same; But we don't handle matrices with empty row names (the function will give an error).

  • The two matrices can have different numbers of rows, but read our default handling carefully to make sure the calculation is accurate when using this function!!!

About a network of type "igraph", It can be obtained from the connection matrices of subnetworks by the function igraph_from_matrices.

Value

Returns a matrix of 70 columns representing the roles of interconnecting species in the motifs. Columns names are Role1, Role2, Role3 ... Role70.

Each row of matrix corresponds to a interconnecting species in the second layer of network. If a interconnecting species is linked to both the second and third level species, the elements in this row are not all zero, otherwise the elements are all zero.

References

Simmons, B. I., Sweering, M. J., Schillinger, M., Dicks, L. V., Sutherland, W. J., & Di Clemente, R. (2019). bmotif: A package for motif analyses of bipartite networks. Methods in Ecology and Evolution, 10(5), 695-701.

Examples

set.seed(12)
d <- build_net(11,22,21,0.2)
icmotif_role(d)

set.seed(12)
MAT <- build_net(11,22,21,0.2,asmatrices=TRUE)

icmotif_role(MAT[[3]],MAT[[4]])

md1<-matrix(sample(c(0,1),88,replace=TRUE),8,11)
md2<-matrix(sample(c(0,1),120,replace=TRUE),10,12)
icmotif_role(md1,md2)

R<-rownames(MAT[[4]])[12]
MR<-MAT[[4]][12,]
MAT[[4]]<-MAT[[4]][-12,]
MAT[[4]]<-rbind(MAT[[4]],MR)
rownames(MAT[[4]])[22]<-R

icmotif_role(MAT[[3]],MAT[[4]])

Transforming matrices into network

Description

Two matrices contain three groups of tropical level species. A multilayer network can be transformed from existing matrices data.

Usage

igraph_from_matrices(mat1, mat2, isDirected1 = TRUE, isDirected2 = TRUE)

Arguments

mat1

A numeric matrix(or data.frame) representing interactions between two groups of species.Each row and column of matrix represents single species in the second and first groups of the tripartite network respectively. Elements of matrix are non-zero numbers if the two groups of species are connected, and 0 otherwise.

mat2

A numeric matrix(or data.frame) representing interactions between two groups of species.Each row and column of matrix represents single species in the second and third groups of the tripartite network respectively. Elements of matrix are non-zero numbers if the two groups of species are connected, and 0 otherwise.

isDirected1

Logical. Whether the interaction between the two groups of species in mat1 is unidirectional.Default to TRUE, such as Predation and Herbivory. Otherwise it is bidirectional, such as Mutualism.

isDirected2

Logical. Whether the interaction between the two groups of species in mat2 is unidirectional.Default to TRUE, such as Predation and Herbivory. Otherwise it is bidirectional, such as Mutualism.

Details

mat1 and mat2

The type of inputting is data frame or matrix, please make sure the row of mat1 and mat2 correspond with the second group of species that both belong to two subnetworks and interact with other groups of species.

  • Try to make the rows of both matrices have the same attributes. Or we default:

  • When the two matrices can have different numbers of rows:

    • (1). If both matrices have row names, then the function counts all row names to produce two new matrices with the same row names.

    • (2). If at most one matrix has row names, the function assigns new row names to both matrices on a row-to-row basis (any extra row names are assigned a new value) and then counts all row names to produce two new matrices with the same row names.

  • When the two matrices can have the same numbers of rows:

    • No matter how the row names of the two matrices are arranged, as long as the row names are exactly the same; But we don't handle matrices with empty row names (the function will give an error).

  • The two matrices can have different numbers of rows, but read our default handling carefully to make sure the calculation is accurate when using this function!!!

The columns of mat1 and mat2 could be empty. If empty, the function also defaults to the suggested assignment.

Value

Return a network of type "igraph".

Examples

set.seed(12)
MAT <- build_net(11,22,21,0.2,asmatrices=TRUE)
MAT[[1]]

tmat<-t(MAT[[3]])
colnames(tmat)<-NULL
igraph_from_matrices(MAT[[3]],MAT[[4]])
M <- igraph_from_matrices(tmat,MAT[[4]])
M

Defined multilayer motifs

Description

Acquiring each or all of 48 motifs of definition of multilayer network.

Usage

Multi_motif(
  type = c("M111", "M112", "M113", "M114", "M211", "M212", "M213", "M311", "M312",
    "M411", "M121", "M122-1", "M122-2", "M122-3", "M123-1", "M123-2", "M123-3", "M123-4",
    "M123-5", "M221-1", "M221-2", "M221-3", "M222-1", "M222-2", "M222-3", "M222-4",
    "M222-5", "M222-6", "M222-7", "M222-8", "M222-9", "M321-1", "M321-2", "M321-3",
    "M321-4", "M321-5", "M131", "M132-1", "M132-2", "M132-3", "M132-4", "M132-5",
    "M231-1", "M231-2", "M231-3", "M231-4", "M231-5", "M141", "all")
)

Arguments

type

Character. 49 values representing each and all types of multilayer motifs.

Value

If type is one of 48 motifs of definition, function returns a corresponding motif of "igraph".

If type is "all", function returns a list containing 48 corresponding motifs of "igraph".

Examples

type<-c("M111","M112","M113","M114","M211","M212","M213","M311",
"M312","M411","M121","M122-1","M122-2","M122-3","M123-1",
"M123-2","M123-3","M123-4","M123-5","M221-1","M221-2",
"M221-3","M222-1","M222-2","M222-3","M222-4","M222-5",
"M222-6","M222-7","M222-8","M222-9","M321-1","M321-2",
"M321-3","M321-4","M321-5","M131","M132-1","M132-2",
"M132-3","M132-4","M132-5","M231-1","M231-2","M231-3",
"M231-4","M231-5","M141")

m<-Multi_motif("M222-4")
plot(m,main="M222-4")

mr <- par(mfrow=c(6,8),mar=c(1,1,3,1))
for(i in 1:48){
    plot(Multi_motif("all")[[i]],
    vertex.size=30, vertex.label=NA,
    vertex.color="blue",main=type[i])
}
par(mr)

Measuring node versatility of multilayer network

Description

The versatility of nodes is revealed by several centrality measures that have now been applied to multilayer networks, such as Degree, Pagerank, Hub, Authority, Katz, Eigenvector, and Closeness centrality.

Usage

node_cv(
  network.or.subnet_mat1,
  subnet_mat2 = NULL,
  isDirected1 = TRUE,
  isDirected2 = TRUE,
  type = c("degree", "pagerank", "hub", "authority", "katz", "eigenvector", "closeness",
    "all")
)

Arguments

network.or.subnet_mat1

Either a multilayer(tripartite) network of 'igraph' class which contains three groups of species and interactions within layers without interactions between each group of species, or a numeric matrix(or data.frame) representing interactions between two groups of species. Each row and column of matrix represents single species in the second and first groups of the tripartite network respectively. Elements of matrix are non-zero numbers if the two groups of species are connected, and 0 otherwise.

subnet_mat2

A numeric matrix(or data.frame) representing interactions between two groups of species. Each row and column of matrix represents single species in the second and third groups of the tripartite network respectively. Elements of matrix are non-zero numbers if the two groups of species are connected, and 0 otherwise. If network.or.subnet_mat1 is "igraph", subnet_mat2 defaults to NULL.

isDirected1

Logical. Whether the interaction between the two groups of species in mat1 is unidirectional.Default to TRUE, such as Predation and Herbivory. Otherwise it is bidirectional, such as Mutualism.

isDirected2

Logical. Whether the interaction between the two groups of species in mat2 is unidirectional.Default to TRUE, such as Predation and Herbivory. Otherwise it is bidirectional, such as Mutualism.

type

Character. Including "degree", "pagerank", "hub", "authority", "katz", "eigenvector", "closeness", and "all".

Details

network.or.subnet_mat1 and subnet_mat2

There are two types of network.or.subnet_mat1 that can be processed:

  • (1). Input in a network of type "igraph" alone.

  • (2). Must be entered as data frame or matrix with subnet_mat2.

If the type of inputting is data frame or matrix, please make sure the row of network.or.subnet_mat1 and subnet_mat2 correspond with the second group of species that both belong to two subnetworks and interact with other groups of species.

  • Try to make the rows of both matrices have the same attributes. Or we default:

  • When the two matrices can have different numbers of rows:

    • (1). If both matrices have row names, then the function counts all row names to produce two new matrices with the same row names.

    • (2). If at most one matrix has row names, the function assigns new row names to both matrices on a row-to-row basis (any extra row names are assigned a new value) and then counts all row names to produce two new matrices with the same row names.

  • When the two matrices can have the same numbers of rows:

    • No matter how the row names of the two matrices are arranged, as long as the row names are exactly the same; But we don't handle matrices with empty row names (the function will give an error).

  • The two matrices can have different numbers of rows, but read our default handling carefully to make sure the calculation is accurate when using this function!!!

About a network of type "igraph", It can be obtained from the connection matrices of subnetworks by the function igraph_from_matrices.

type

type "degree", "pagerank", "hub", "authority", "katz", "eigenvector", and "closeness" correspond to Degree, PageRank, Hub, Authority, Katz, Eigenvector, and Closeness centrality. type "all" integrates the above centrality.

Value

Return a data frame with the first row "node" for each node of network representing each species.

  • If type is either of "degree", "pagerank", "hub", "authority", "katz", "eigenvector", "closeness", the data frame has two columns, and the second column corresponds to either of "Degree", "Pagerank_versatility", "Hub_versatility", "Authority_versatility", "Katz_versatility", "Eigenvector_versatility", "Closeness_versatility".

  • If type is "all", the data frame has eight columns, and columns form the second to the eighth correspond to "Degree", "Pagerank_versatility", "Hub_versatility", "Authority_versatility", "Katz_versatility", "Eigenvector_versatility", "Closeness_versatility".

References

De Domenico, M., Nicosia, V., Arenas, A., & Latora, V. (2015). Structural reducibility of multilayer networks. Nature communications, 6(1), 6864.

De Domenico, M., Solé-Ribalta, A., Omodei, E., Gómez, S., & Arenas, A. (2013). Centrality in interconnected multilayer networks. arXiv preprint arXiv:1311.2906.

De Domenico, M. (2022). Multilayer Networks: Analysis and Visualization. Introduction to muxViz with R. Cham: Springer.

Page, L., Brin, S., Motwani, R., & Winograd, T. (1999). The pagerank citation ranking: Bringing order to the web.

Magnani, M., Micenkova, B., & Rossi, L. (2013). Combinatorial analysis of multiple networks. arXiv preprint arXiv:1303.4986.

Examples

set.seed(12)
d <- build_net(11,22,21,0.2,asmatrices=TRUE)
d
node_cv(d[[1]])

MAT<-d
tmat<-t(MAT[[3]])
colnames(tmat)<-NULL
node_cv(MAT[[3]],MAT[[4]])
node_cv(tmat,MAT[[4]])
node_cv(MAT[[3]],MAT[[4]],type="pagerank")

node_cv(MAT[[3]],MAT[[4]],isDirected2=FALSE)

Null model of multilayer network

Description

The null model could be generated according to different matrix scrambling algorithms for interconnection patterns in the multilayer network

Usage

null_model(
  network,
  number = NULL,
  null_type = c("subnetwork1", "subnetwork2", "all", "Savue")
)

Arguments

network

A multilayer(tripartite) network of 'igraph' class. The network contains three groups of species and interactions within layers without interactions between each group of species.

number

A numeric value. The number of null model. Default to NULL representing number 1.

null_type

Logical. Four matrix scrambling algorithms. If null_type = NULL, default to "all".

Details

null_type

  • For each of the four types of null models, there are corresponding algorithms. The first type, “subnetwork1”, involved scrambling the adjacency matrix of the first and second groups of the multilayer network.

  • The second type, “subnetwork2”, focused on scrambling the adjacency matrix of the second and third groups.

  • Comprehensively, the third type, “all”, blended the approaches of the first two to disarrange the entire network's adjacency matrix, achieving a thorough perturbation of the network's structure.

  • The last type named “Savue” that disarranged inherent structure in terms of the groups of species connected by each interconnecting species of every subnetworks, thus exhibiting different interconnection patterns.

network

About a network of type "igraph", It can be obtained from the connection matrices of subnetworks by the function igraph_from_matrices

Value

Return a list contains one or more elements. Each element represent a null model of multilayer network.

References

Vázquez, D. P., C. J. Melian, N. M. Williams, N. Blüthgen, B. R. Krasnov, and R. Poulin. 2007. Species abundance and asymmetric interaction strength in ecological networks. Oikos 116: 1120-1127.

Sauve, A. M., Thébault, 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

set.seed(12)
d <- build_net(11,22,21,0.2)

set.seed(123)
null_model(d)
set.seed(123)
null_model(d,null_type="subnetwork1")
set.seed(123)
null_model(d,null_type="Savue")
set.seed(123)
null_model(d,number=2,null_type="Savue")

Participation ratio of interconnecting code

Description

Counting participation ratio that the difference in the degree of interconnecting nodes within two subnetworks.

Usage

pc(network.or.subnet_mat1, subnet_mat2 = NULL)

Arguments

network.or.subnet_mat1

Either a multilayer(tripartite) network of 'igraph' class which contains three groups of species and interactions within layers without interactions between each group of species, or a numeric matrix(or data.frame) representing interactions between two groups of species. Each row and column of matrix represents single species in the second and first groups of the tripartite network respectively. Elements of matrix are non-zero numbers if two groups of species are connected, and 0 otherwise.

subnet_mat2

A numeric matrix(or data.frame) representing interactions between two groups of species. Each row and column of matrix represents single species in the second and third groups of the tripartite network respectively. Elements of matrix are non-zero numbers if the two groups of species are connected, and 0 otherwise. If network.or.subnet_mat1 is "igraph", subnet_mat2 defaults to NULL.

Details

network.or.subnet_mat1 and subnet_mat2

There are two types of network.or.subnet_mat1 that can be processed:

  • (1). Input in a network of type "igraph" alone.

  • (2). Must be entered as data frame or matrix with subnet_mat2.

If the type of inputting is data frame or matrix, please make sure the row of network.or.subnet_mat1 and subnet_mat2 correspond with the second group of species that both belong to two subnetworks and interact with other groups of species.

  • Try to make the rows of both matrices have the same attributes. Or we default:

  • (1). If both matrices have row names, then the function counts all row names to produce two new matrices with the same row names.

  • (2). If at most one matrix has row names, the function assigns new row names to both matrices on a row-to-row basis (any extra row names are assigned a new value) and then counts all row names to produce two new matrices with the same row names.

  • The two matrices can have different numbers of rows, but read our default handling carefully to make sure the calculation is accurate when using this function!!!

About a network of type "igraph", It can be obtained from the connection matrices of subnetworks by the function igraph_from_matrices.

Value

Print a "pc= ;" and Return a numeric value representing difference in the degree of interconnecting nodes within two subnetworks of multialyer network.

References

Battiston, F., Nicosia, V. & Latora, V. (2014) Structural measures for multiplex networks. Physical Review E, 89, 032804.

Domínguez-García, V., & Kéfi, S. (2024). The structure and robustness of ecological networks with two interaction types. PLOS Computational Biology, 20(1), e1011770.

Guimera, R. & Amaral, L.A.N. (2005) Cartography of complex networks: modules and universal roles. Journal of Statistical Mechanics: Theory and Experiment, 2005, P02001.

Examples

set.seed(15)
d <- build_net(11,15,17,0.2)
pc(d)

md1<-matrix(sample(c(0,1),80,replace=TRUE),8,10)
md2<-matrix(sample(c(0,1),120,replace=TRUE),10,12)
pc(md1,md2)

mdw1<-matrix(sample(c(rep(0,60),runif(60,0,1))),12,10)
mdw2<-matrix(sample(c(rep(0,40),runif(80,0,1))),10,12)
pc(mdw1,mdw2)

Proportion of interconnection

Description

Calculating the proportion of species sharing with other species of two subnetworks in intermediate layer.

Usage

poc(network.or.subnet_mat1, subnet_mat2 = NULL)

Arguments

network.or.subnet_mat1

Either a multilayer(tripartite) network of 'igraph' class which contains three groups of species and interactions within layers without interactions between each group of species, or a numeric matrix(or data.frame) representing interactions between two groups of species. Each row and column of matrix represents single species in the second and first groups of the tripartite network respectively. Elements of matrix are non-zero numbers if two groups of species are connected, and 0 otherwise.

subnet_mat2

A numeric matrix(or data.frame) representing interactions between two groups of species. Each row and column of matrix represents single species in the second and third groups of the tripartite network respectively. Elements of matrix are non-zero numbers if the two groups of species are connected, and 0 otherwise. If network.or.subnet_mat1 is "igraph", subnet_mat2 defaults to NULL.

Details

network.or.subnet_mat1 and subnet_mat2

There are two types of network.or.subnet_mat1 that can be processed:

  • (1). Input in a network of type "igraph" alone.

  • (2). Must be entered as data frame or matrix with subnet_mat2.

If the type of inputting is data frame or matrix, please make sure the row of network.or.subnet_mat1 and subnet_mat2 correspond with the second group of species that both belong to two subnetworks and interact with other groups of species.

  • Try to make the rows of both matrices have the same attributes. Or we default:

  • (1). If both matrices have row names, then the function counts all row names to produce two new matrices with the same row names.

  • (2). If at most one matrix has row names, the function assigns new row names to both matrices on a row-to-row basis (any extra row names are assigned a new value) and then counts all row names to produce two new matrices with the same row names.

  • The two matrices can have different numbers of rows, but read our default handling carefully to make sure the calculation is accurate when using this function!!!

About a network of type "igraph", It can be obtained from the connection matrices of subnetworks by the function igraph_from_matrices.

Value

Print a "poc= ;" and Return a numeric value representing the proportion of sharing species in intermediate layer.

References

Battiston, F., Nicosia, V. & Latora, V. (2014) Structural measures for multiplex networks. Physical Review E, 89, 032804.

Domínguez-García, V., & Kéfi, S. (2024). The structure and robustness of ecological networks with two interaction types. PLOS Computational Biology, 20(1), e1011770.

Guimera, R. & Amaral, L.A.N. (2005) Cartography of complex networks: modules and universal roles. Journal of Statistical Mechanics: Theory and Experiment, 2005, P02001.

Examples

set.seed(15)
d <- build_net(11,15,17,0.2)
poc(d)

md1<-matrix(sample(c(0,1),80,replace=TRUE),8,10)
md2<-matrix(sample(c(0,1),120,replace=TRUE),10,12)
poc(md1,md2)

mdw1<-matrix(sample(c(rep(0,40),runif(60,0,1))),10,10)
mdw2<-matrix(sample(c(rep(0,40),runif(80,0,1))),10,12)
poc(mdw1,mdw2)

mdw1<-matrix(sample(c(rep(0,60),runif(60,0,1))),12,10)
mdw2<-matrix(sample(c(rep(0,40),runif(80,0,1))),10,12)
poc(mdw1,mdw2)

A pollinator-plant-herbivore network from Villa-Galaviz et. al. 2020. Journal of Animal Ecology

Description

A pollinator-plant-herbivore network from Villa-Galaviz et. al. 2020. Journal of Animal Ecology

Usage

data(PPH_Coltparkmeadow)

Details

A list with "igraph". This is a classical example of multilayer interaction network.

References

Villa‐Galaviz, E., S. M. Smart, E. L. Clare, S. E. Ward, and J. Memmott. 2021. Differential effects of fertilisers on pollination and parasitoid interaction networks. Journal of animal ecology 90:404-414.

Examples

data(PPH_Coltparkmeadow)

Similarity of roles of interconnecting species

Description

The average of Similarity of 65 roles of interconnecting species of multilayer network.

Usage

role_sim(spe_role_mat)

Arguments

spe_role_mat

A matrix of 65 columns representing the roles of interconnecting species in the motifs. Columns names are Role1, Role2, Role3 ... Role70.

Details

spe_role_mat

Should acquire from function motif_role.

Value

Return a numeric value.

Examples

set.seed(12)
d <- build_net(11,22,21,0.2)
mr <- icmotif_role(d)
role_sim(mr)

set.seed(1)
D <- build_net(11,22,21,0.2)
role_sim(icmotif_role(D))

Correlation of the Structural indices between Subnetworks

Description

Calculating correlation of interconnecting species generalism among Subnetworks ("general_'~'cor") and correlation between similarities of interconnecing species interaction partners in two subnetworks ("similar_'~'cor").

Usage

subnet_cor(network.or.subnet_mat1, subnet_mat2 = NULL, weighted = FALSE)

Arguments

network.or.subnet_mat1

Either a multilayer(tripartite) network of 'igraph' class which contains three groups of species and interactions within layers without interactions between each group of species, or a numeric matrix(or data.frame) representing interactions between two groups of species. Each row and column of matrix represents single species in the second and first groups of the tripartite network respectively. Elements of matrix are non-zero numbers if the two groups of species are connected, and 0 otherwise.

subnet_mat2

A numeric matrix(or data.frame) representing interactions between two groups of species. Each row and column of matrix represents single species in the second and third groups of the tripartite network respectively. Elements of matrix are non-zero numbers if the two groups of species are connected, and 0 otherwise. If network.or.subnet_mat1 is "igraph", subnet_mat2 defaults to NULL.

weighted

Logical. should elements of matrix be fractional? Default to FALSE. Generally, 'igraph' network represent a spare matrix, so weighted is FALSE. While elements of matrix represent interaction strength, weighted is TRUE.

Details

weighted

If the weighted = FALSE, the input for the parameter can be:

  • network.or.subnet_mat1: input a 'igraph' of network data independently or input sparse matrix together with subnet_mat2.

If the weighted = TRUE, the input for the parameter can be:

  • network.or.subnet_mat1: must input matrix(or data.frame) together with subnet_mat2. the matrix can be sparse matrix and matrix of interaction strength.

network.or.subnet_mat1 and subnet_mat2

There are two types of network.or.subnet_mat1 that can be processed:

  • (1). Input in a network of type "igraph" alone.

  • (2). Must be entered as data frame or matrix with subnet_mat2.

If the type of inputting is data frame or matrix, please make sure the row of network.or.subnet_mat1 and subnet_mat2 correspond with the second group of species that both belong to two subnetworks and interact with other groups of species.

  • Try to make the rows of both matrices have the same attributes. Or we default:

  • When the two matrices can have different numbers of rows:

    • (1). If both matrices have row names, then the function counts all row names to produce two new matrices with the same row names.

    • (2). If at most one matrix has row names, the function assigns new row names to both matrices on a row-to-row basis (any extra row names are assigned a new value) and then counts all row names to produce two new matrices with the same row names.

  • When the two matrices can have the same numbers of rows:

    • No matter how the row names of the two matrices are arranged, as long as the row names are exactly the same; But we don't handle matrices with empty row names (the function will give an error).

  • The two matrices can have different numbers of rows, but read our default handling carefully to make sure the calculation is accurate when using this function!!!

About a network of type "igraph", It can be obtained from the connection matrices of subnetworks by the function igraph_from_matrices.

Value

Return a numeric vector of two elements representing correlation of interconnecting species generalism among Subnetworks and correlation between similarities of interconnecing species interaction partners in two subnetworks.

If weighted = FALSE, the results will show "general_cor= ;similar_cor= ;" and If weighted = TRUE, the results will show "general_weight_cor= ;similar_weight_cor= ;"

References

Sauve, A. M., Thébault, 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

set.seed(12)
d <- build_net(11,15,17,0.2)
subnet_cor(d)

md1<-matrix(sample(c(0,1),110,replace=TRUE),10,11)
md2<-matrix(sample(c(0,1),120,replace=TRUE),10,12)
subnet_cor(md1,md2)
subnet_cor(md1,md2,weighted=TRUE)

md1<-matrix(sample(c(0,1),80,replace=TRUE),8,10)
md2<-matrix(sample(c(0,1),120,replace=TRUE),10,12)
subnet_cor(md1,md2)

mdw1<-matrix(runif(110,0,1),10,11)
mdw2<-matrix(runif(120,0,1),10,12)
subnet_cor(mdw1,mdw2,weighted=TRUE)

set.seed(1)
mdw1<-matrix(runif(80,0,1),8,10)
mdw2<-matrix(runif(120,0,1),10,12)
subnet_cor(mdw1,mdw2,weighted=TRUE)