get_stats_single: Prepare bootstrapped results of a single network for 'ggplot'...

View source: R/helpers.r

get_stats_singleR Documentation

Prepare bootstrapped results of a single network for ggplot friendly data format.

Description

Helper to prepare the bootstrapped metric output of a single web/network from boot_networklevel_n or boot_specieslevel_n in a format ready for ggplot.

Usage

get_stats_single(x, probs = c(0.025, 0.975))

Arguments

x

A bootstrap matrix or an array of matrices from boot_networklevel_n or boot_specieslevel_n.

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.

Value

A list of two data frames to be used with ggplot. First one, stats_df is a 4 columns data frame, containing the sample size (spl_size) at each iteration and the corresponding mean metric (mean) together with its bootstrap confidence interval limits (ci_low, ci_up). The second one, lines_df, contains all the bootstrapped values (value) of a given network metric at each iteration (simulation_id) and its corresponding sample size (spl_size). Can be used for enhancing visual effect when plotting the mean bootstrap values.

Examples

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

stats_d_lower <- Safariland %>%
  web_matrix_to_df() %>%
  boot_specieslevel_n(col_lower = "lower", # column name for plants
                        col_higher = "higher", # column name for insects
                        index = "d",
                        level = "both",
                        start = 100,
                        step = 100,
                        n_boot = 10,
                        n_cpu = 2) %>%
  .[["lower_level"]] %>%
  get_stats_single()


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