| Title: | Using Block Model to Estimate the Robustness of Ecological Network |
|---|---|
| Description: | Implementation of a variety of methods to compute the robustness of ecological interaction networks with binary interactions as described in <doi:10.1002/env.2709>. In particular, using the Stochastic Block Model and its bipartite counterpart, the Latent Block Model to put a parametric model on the network, allows the comparison of the robustness of networks differing in species richness and number of interactions. It also deals with networks that are partially sampled and/or with missing values. |
| Authors: | Saint-Clair Chabert-Liddell [aut, cre] (ORCID: <https://orcid.org/0000-0001-5604-7308>) |
| Maintainer: | Saint-Clair Chabert-Liddell <[email protected]> |
| License: | GPL-3 |
| Version: | 0.2.4 |
| Built: | 2026-06-03 10:54:24 UTC |
| Source: | https://github.com/chabert-liddell/robber |
This function provides much faster computation than robustness_lbm for
the case where ext_seq = "uniform", when just the AUC statistic is
needed and the robustness function is not needed. This is particularly
useful if nr gets large.
auc_robustness_lbm(con, pi, rho, nr, nc)auc_robustness_lbm(con, pi, rho, nr, nc)
con |
A matrix, the connectivity parameter |
pi |
A vector of length |
rho |
A vector of length |
nr |
An integer, the number of row (primary) species |
nc |
An integer, the number of column (secondary) species |
The AUC of the LBM Robustness function for uniform primary extinctions sequences.
con <- matrix(c(.5,.3,.3,.1), 2, 2) pi <- c(.25,.75) rho <- c(1/3, 2/3) nr <- 50 nc <- 30 auc_robustness_lbm(con, pi, rho, nr, nc)con <- matrix(c(.5,.3,.3,.1), 2, 2) pi <- c(.25,.75) rho <- c(1/3, 2/3) nr <- 50 nc <- 30 auc_robustness_lbm(con, pi, rho, nr, nc)
This function is designed to be used with a list of parameters
as the one given by the function get_lbm_param(). The default
parameters are designed such that the return value for a uniform extinction
sequence is bounded above by 0.5.
compare_robustness( list_param, dens = 0.0156, new_nr = 100, new_nc = 100, ext_seq = "uniform" )compare_robustness( list_param, dens = 0.0156, new_nr = 100, new_nc = 100, ext_seq = "uniform" )
list_param |
A list of list of LBM parameters, each list must contain at
list |
dens |
The density (connectance) used to compare the network. The
|
new_nr |
The number of rows of the normalized networks. Default to 100. |
new_nc |
The number of columns of the normalized networks. Default to 100. |
ext_seq |
The distribution of the primary extinction sequence used to
compare the networks. One of |
A list of the sames length as list_param, the robustness (AUC)
after normalization for all set of parameters.
par1 <- list(con = matrix(c(.5,.3,.3,.1), 2, 2), pi = c(.25,.75), rho = c(1/3, 2/3)) par2 <- list(con = matrix(c(.4,.1,.1,.4), 2, 2), pi = c(.25,.75), rho = c(1/2, 1/2)) compare_robustness(list_param = list(par1, par2), ext_seq = "decreasing") compare_robustness(list_param = list(par1, par2), ext_seq = "increasing")par1 <- list(con = matrix(c(.5,.3,.3,.1), 2, 2), pi = c(.25,.75), rho = c(1/3, 2/3)) par2 <- list(con = matrix(c(.4,.1,.1,.4), 2, 2), pi = c(.25,.75), rho = c(1/2, 1/2)) compare_robustness(list_param = list(par1, par2), ext_seq = "decreasing") compare_robustness(list_param = list(par1, par2), ext_seq = "increasing")
Estimate the parameters of a LBM
get_lbm_param(A, model_size = NULL, ...)get_lbm_param(A, model_size = NULL, ...)
A |
A matrix, the incident matrix of the network |
model_size |
A vector of size 2, the size of the model parameters.
If |
... |
Additional arguments pass to the inference function of
package |
A list of the LBM parameters. The list is set
# When the size of the model is unknown: data("seeddispersal") param <- get_lbm_param(seeddispersal, ncores = 1L) do.call(auc_robustness_lbm, param) # For a fixed number of blocks (useful for comparison) param <- get_lbm_param(seeddispersal, model_size = c(1, 3), ncores = 1L) do.call(auc_robustness_lbm, param) # For data with missing observations A <- seeddispersal A[sample(seq_len(nrow(A)), 5), sample(seq_len(ncol(A)), 10)] <- NA param <- get_lbm_param(A, nbCores = 1L) do.call(auc_robustness_lbm, param)# When the size of the model is unknown: data("seeddispersal") param <- get_lbm_param(seeddispersal, ncores = 1L) do.call(auc_robustness_lbm, param) # For a fixed number of blocks (useful for comparison) param <- get_lbm_param(seeddispersal, model_size = c(1, 3), ncores = 1L) do.call(auc_robustness_lbm, param) # For data with missing observations A <- seeddispersal A[sample(seq_len(nrow(A)), 5), sample(seq_len(ncol(A)), 10)] <- NA param <- get_lbm_param(A, nbCores = 1L) do.call(auc_robustness_lbm, param)
Locality: Tomsk-Tumen Reference:Hadfield JD, Krasnov BR, Poulin R, Shinichi N (2013) A tale of two phylogenies: comparative analyses of ecological interactions. The American Naturalist 183(2): 174-187
hostparasitehostparasite
A matrix of binary entries with 27 rows and 26 columns
https://datadryad.org/stash/dataset/doi:10.5061/dryad.jf3tj
Plot function pour robber class
## S3 method for class 'robber' plot(x, type = "function", add = FALSE, ...)## S3 method for class 'robber' plot(x, type = "function", add = FALSE, ...)
x |
An object of class robber |
type |
Type of the plot, just function |
add |
Whether it should be added to a previous ggplot |
... |
|
A ggplot2 object
data("hostparasite", package = "robber") rob <- robustness_emp(hostparasite) plot(rob)data("hostparasite", package = "robber") rob <- robustness_emp(hostparasite) plot(rob)
Locality: Tenerife, Canary Islands Stald L (2003). Struktur og dynamik i rum og tid af et bestøvningsnetværk på Tenerife, De Kanariske Øer. Msc thesis (Univ of Aarhus, Aarhus, Denmark)
pollinationpollination
A matrix of binary entries with 17 rows and 51 columns
Compute the robustness of an ecological network by averaging over a great number of randomly generated primary extinctions sequences
robustness_emp( A, ext_seq = "uniform", nb_iter = 300, net_type = "bipartite", method = "ordered", power = 1, block = NULL )robustness_emp( A, ext_seq = "uniform", nb_iter = 300, net_type = "bipartite", method = "ordered", power = 1, block = NULL )
A |
A binary incident matrix |
ext_seq |
A string, the rule for the primary extinctions sequences,
one of |
nb_iter |
An integer, the number of generated sequences. Default to
|
net_type |
A string, the type of network. For now, only "bipartite" is available. |
method |
A string used when
|
power |
An integer (default to 1). Only used when
|
block |
A vector of row species memberships for |
A list (robber object) with the following fields:
$model, $ext_seq, $method, power
$fun is the robustness function, a vector of size (nrow(A) +1)
$sd Standard deviation of the secondary extinctions
$auc the area under the curve of the robustness function
A <- matrix(c(1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1), nrow = 4, ncol = 3, byrow = TRUE) my_rob <- robustness_emp(A, ext_seq = "increasing") my_rob$fun my_rob$aucA <- matrix(c(1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1), nrow = 4, ncol = 3, byrow = TRUE) my_rob <- robustness_emp(A, ext_seq = "increasing") my_rob$fun my_rob$auc
Compute the robustness for a given set of Latent Block Model parameters.
robustness_lbm( con = NULL, pi = NULL, rho = NULL, nr = NULL, nc = NULL, ext_seq = "uniform", method = "exact", approx_threshold = 10000, net = NULL, ... )robustness_lbm( con = NULL, pi = NULL, rho = NULL, nr = NULL, nc = NULL, ext_seq = "uniform", method = "exact", approx_threshold = 10000, net = NULL, ... )
con |
A matrix, the connectivity parameter |
pi |
A vector of length |
rho |
A vector of length |
nr |
An integer, the number of row (primary) species |
nc |
An integer, the number of column (secondary) species |
ext_seq |
A string, the rule for the primary extinctions sequences, one of:
|
method |
A string, the method used to compute the robustness by block. One of:
|
approx_threshold |
A numeric, the maximum size of the possible block
partition allowed for exact robustness by block calculation. Higher threshold
gives more precise results at the cost of computation times and possibly memory
problem. Do not do anything for |
net |
A network, if given, the function will fit a LBM to obtain the parameters of the network and then compute the robustness. |
... |
Option to be passed to get_ |
A list and a robber type object:
$fun the robustness function, a vector of size nr +1
$auc the area under the curve of the robustness function
$block a vector of size length(pi), the block ordering for
primary extinctions sequence by blocks. NULL if ext_seq = "uniform".
$model, $method, $ext_seq, $param.
con <- matrix(c(.5,.3,.3,.1), 2, 2) pi <- c(.25,.75) rho <- c(1/3, 2/3) nr <- 50 nc <- 30 my_rob <- robustness_lbm(con, pi, rho, nr, nc, ext_seq = "natural") my_rob$fun my_rob$auc # A easier alternative way, if you don't know the parameters of the network: data(hostparasite) (robustness_lbm(net = hostparasite, ncores = 1L))con <- matrix(c(.5,.3,.3,.1), 2, 2) pi <- c(.25,.75) rho <- c(1/3, 2/3) nr <- 50 nc <- 30 my_rob <- robustness_lbm(con, pi, rho, nr, nc, ext_seq = "natural") my_rob$fun my_rob$auc # A easier alternative way, if you don't know the parameters of the network: data(hostparasite) (robustness_lbm(net = hostparasite, ncores = 1L))
Locality: North Negros Forest Reserve, Central Philippi Hammann, A. & Curio, B. (1999) Interactions among frugivores and fleshy fruit trees in a Philippine submontane rainforest.
seeddispersalseeddispersal
A matrix of binary entries with 36 rows and 19 columns
https://conbio.org/publications/conservation-biology
Simulate a bipartite interaction network using block model
simulate_lbm(con, pi, rho, nr, nc, method = "gnp")simulate_lbm(con, pi, rho, nr, nc, method = "gnp")
con |
A matrix, the connectivity between blocks. If
|
pi |
A vector of the same length as |
rho |
A vector of the same length as |
nr |
The number of row Species |
nc |
The number of column Species |
method |
One of |
A list of 3 elements:
A The incident matrix of size nrxnc
Z A vector of length nr, the block assignment of the row
species
W A vector of length nc, the block assignment of the column
species
# For a random number of interactions and blocks sizes con <- matrix(c(.5,.3,.3,.1), 2, 2) pi <- c(.25,.75) rho <- c(1/3, 2/3) nr <- 50 nc <- 30 simulate_lbm(con, pi, rho, nr, nc, method = "gnp") # For a fixed number of ineractions and blocks sizes con <- matrix(c(50, 120, 60, 80), 2, 2) pi <- c(10, 40) rho <- c(10, 20) nr <- 50 nc <- 30 simulate_lbm(con, pi, rho, nr, nc, method = "gnm")# For a random number of interactions and blocks sizes con <- matrix(c(.5,.3,.3,.1), 2, 2) pi <- c(.25,.75) rho <- c(1/3, 2/3) nr <- 50 nc <- 30 simulate_lbm(con, pi, rho, nr, nc, method = "gnp") # For a fixed number of ineractions and blocks sizes con <- matrix(c(50, 120, 60, 80), 2, 2) pi <- c(10, 40) rho <- c(10, 20) nr <- 50 nc <- 30 simulate_lbm(con, pi, rho, nr, nc, method = "gnm")
Compute the Conditional variance of the AUC of the LBM Robustness
var_auc_unif_lbm(con, pi, rho, nr, nc)var_auc_unif_lbm(con, pi, rho, nr, nc)
con |
A matrix, the connectivity parameter |
pi |
A vector of length |
rho |
A vector of length |
nr |
An integer, the number of row (primary) species |
nc |
An integer, the number of column (secondary) species |
A numeric, the variance
con <- matrix(c(.5,.3,.3,.1), 2, 2) pi <- c(.25,.75) rho <- c(1/3, 2/3) nr <- 50 nc <- 30 var_auc_unif_lbm(con, pi, rho, nr, nc)con <- matrix(c(.5,.3,.3,.1), 2, 2) pi <- c(.25,.75) rho <- c(1/3, 2/3) nr <- 50 nc <- 30 var_auc_unif_lbm(con, pi, rho, nr, nc)
Compute the Conditional variance of the LBM Robustness term by term
var_fun_unif_lbm(con, pi, rho, nr, nc)var_fun_unif_lbm(con, pi, rho, nr, nc)
con |
A matrix, the connectivity parameter |
pi |
A vector of length |
rho |
A vector of length |
nr |
An integer, the number of row (primary) species |
nc |
An integer, the number of column (secondary) species |
A vector, the variance after m extinctions
con <- matrix(c(.5,.3,.3,.1), 2, 2) pi <- c(.25,.75) rho <- c(1/3, 2/3) nr <- 50 nc <- 30 var_fun_unif_lbm(con, pi, rho, nr, nc)con <- matrix(c(.5,.3,.3,.1), 2, 2) pi <- c(.25,.75) rho <- c(1/3, 2/3) nr <- 50 nc <- 30 var_fun_unif_lbm(con, pi, rho, nr, nc)