boot_networklevel_n: Bootstrap network level metric multiple times.

View source: R/boot_networklevel.r

boot_networklevel_nR Documentation

Bootstrap network level metric multiple times.

Description

Bootstrap a single network of interactions n times in parallel and collects the network level metrics. Starts with a small sample size of interactions (e.g. start = 30), builds the corresponding web matrix/network, computes its metric (e.g. index = "nestedness") using networklevel, then adds new interactions (e.g. step = 20) until all interactions are sampled. The last sample is actually the entire network. Repeats n times (as given in n_boot) these steps in parallel on multiple CPUs.

Usage

boot_networklevel_n(
  data,
  col_lower,
  col_higher,
  index,
  level,
  start,
  step,
  n_boot,
  n_cpu,
  ...
)

Arguments

data

Data frame of interactions from which to build and sample web matrices. Each interaction (row in the data frame) must be repeated as many times as it was observed. E.g. if the interaction species_1 x species_2 was observed 5 times, then repeat that row 5 times within the data frame. See examples below.

col_lower

Quoted column name in data for lower trophic level species (plants).

col_higher

Quoted column name in data for higher trophic level species (insects).

index

Passed to networklevel. See ?bipartite::networklevel for details.

level

Passed to networklevel. See ?bipartite::networklevel for details. For which level should the level-specific indices be computed: 'both' (default), 'lower' or 'higher'?

start

Integer. The sample size (number of interactions) to start the bootstrap with. If the start sample size is small (e.g. 5 or 10), then first iterations might results in NaN-s and warning messages are displayed. Consider to set start to maybe 10\% of your total unique interactions.

step

Integer. Sample size (number of interactions) used to increase gradually the sampled network until all interactions are sampled. If step is too small (e.g. 1) then the computation time is very long depending on your total number of interactions from which samples are taken. Consider to set step to maybe 5-10\% of your total unique interactions.

n_boot

Number of desired bootstraps (50 or 100 can be enough).

n_cpu

Number of CPU-s to use for parallel processing.

...

Other arguments passed to networklevel like logbase, etc.

Value

Returns a list of a single matrix or a list of two matrices depending on the provided index metric and level value. For example if index='nestedness' and level='both', then it returns a list of a single matrix. But in the case of index='niche overlap', it returns a list of two matrices, first matrix (niche.overlap.HL) corresponding to the higher level (e.g. insects), and the second (niche.overlap.LL) for the lower level (e.g. plants). The number of rows of a matrix indicates how many iterations took place. This is decided internally based on the given values to start, step and the total number of rows (interactions) in data.The row names give the sample size at each iteration. The last iteration (last row name) is always the entire network (total number of interactions in data). The number of columns corresponds to n_boot (number of bootstraps).

Examples


library(bootstrapnet)
library(magrittr)
library(bipartite)
data(Safariland)

Safariland %>%
  web_matrix_to_df() %>%
  boot_networklevel_n(col_lower = "lower", # column name for plants
                      col_higher = "higher", # column name for insects
                      index = "niche overlap",
                      level = "both",
                      start = 100,
                      step = 100,
                      n_boot = 10,
                      n_cpu = 2)


valentinitnelav/bootstrapnet documentation built on June 5, 2024, 3:21 p.m.