subnet_cor {ILSM} | R Documentation |
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 |
weighted |
Logical. should elements of matrix be fractional? Default to FALSE. Generally, 'igraph' network represent a spare matrix, so |
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 withsubnet_mat2
.
If the weighted
= TRUE, the input for the parameter can be:
network.or.subnet_mat1
: must input matrix(or data.frame) together withsubnet_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)