boot_networklevel: Prepare for plotting the bootstrapped network level metric...

View source: R/boot_networklevel.r

boot_networklevelR Documentation

Prepare for plotting the bootstrapped network level metric results of one or multiple networks.

Description

Takes a list of network interactions (each interaction being repeated as many times as it was observed), and bootstraps the network level metric (index) for each network. Runs boot_networklevel_n() for a list of network interactions and prepares the data for plotting with ggplot. The output list can be passed to gg_networklevel. See examples below.

Usage

boot_networklevel(
  lst,
  col_lower,
  col_higher,
  index,
  level,
  start,
  step,
  n_boot,
  n_cpu,
  probs = c(0.025, 0.975),
  ...
)

Arguments

lst

A list of one or multiple data frames 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.

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

The name of the network level metric. Passed to networklevel. See ?bipartite::networklevel for details.

level

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

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.

probs

A numeric vector of two probabilities in ⁠[0, 1]⁠. Passed to rowQuantiles and used for building the lower and upper bounds of the confidence intervals. Defaults to c(0.025, 0.975), which corresponds to a 95\% confidence interval.

...

Other arguments passed to networklevel like logbase, etc.

Value

A list of one (when level = 'lower' or level = 'higher') or two sub-lists (when level = 'both'). The list can be passed to gg_networklevel. Each sub-list, contains two data frames: stats_df and lines_df, which can be used by the ggplot2::geom_line() function. See the return section of get_stats_single for more details about stats_df and lines_df data frames.

Examples


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

set.seed(321)
Safariland_1 <- Safariland[, sort(sample.int(ncol(Safariland), 10))]
set.seed(123)
Safariland_2 <- Safariland[, sort(sample.int(ncol(Safariland), 10))]

lst <- list(s1 = Safariland_1, s2 = Safariland_2) %>%
  lapply(web_matrix_to_df) %>%
  boot_networklevel(col_lower = "lower", # column name for plants
                    col_higher = "higher", # column name for insects
                    index = "nestedness",
                    level = "both",
                    start = 10,
                    step = 10,
                    n_boot = 10,
                    n_cpu = 2)
gg_networklevel(lst)


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