knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

The biomonitoR package was primarily developed for dealing with taxonomic dataset and for calculating diversity, functional and biomonitoring indices at different taxonomic resolution. Although its focus is on freshwater macroinvertebrates, it actually works with multiple biotic groups.

Import data into biomonitoR format

To import a taxonomic dataset in the biomonitoR format a data.frame with a column called "Taxa" where store taxa names and samples on the other columns is needed.

library(biomonitoR)

# built-in example

data(macro_ex)

head(macro_ex)

The first step is to import taxonomic dataset with the function as_biomonitor() that return an object of class asb. Basically this function adds the taxonomic tree to the taxonomic data. The taxonomic tree is built from a reference database, specified in the option group. biomonitoR implements 3 reference database for macroinvertebrates, macrophytes and fish but a reference database can be added by the user.

# import macroinvertebrate data
data_bio <- as_biomonitor(macro_ex, group = "mi")

taxonomic dataset can be imported as presence-absence by levaragin on the FUN option. This option need to be thinked carefully. It is needed because biomonitoR accepts duplicated taxa names in the "Taxa" column. For abundance data sum is thus the natural choice for aggregating data. Case sensitive function for aggregating data could be used when decimal numbers are present (e.g. pecentages) and biomonitoR will remind this issue with a warning.

# import macroinvertebrate data
data_bio_bin <- as_biomonitor(macro_ex, group = "mi", FUN = bin)

An important feature of the biomonitoR package is the spell checker, built from the reference database. By default biomonitoR remove taxa that are not recognized by the reference database and will provide suggestion for unrecognized names. The taxonomic dataset can thus be corrected by modifying the original file, directly in R or by using the spell checker. The spell checker is enabled by setting the option correct_names to to TRUE and it will run interactively. Every taxon needs to be present in the reference database, otherwise the user is forced to exit. This behaviour is important to assure consistency with further calculations. The option traceB will list suggestions and correction.

# introduce an error into taxonomic data

macro_ex_wrong <- macro_ex
macro_ex_wrong$Taxa <- as.character(macro_ex_wrong$Taxa)
macro_ex_wrong[macro_ex_wrong$Taxa %in% "Acentrella", "Taxa"] <- "Acentrela"

data_bio.wrong <- as_biomonitor(macro_ex_wrong, group = "mi", traceB = TRUE)

# "Acentrela" has been removed and a suggestion is proposed

as_biomonitor() will create an object of class asb that is needed for perfroming further calculation in biomonitoR. It is possible to export both the taxonomic dataset and the suggestion/correction as data.frame objects using the function as.data.frame().

# export the taxonomic dataset and suggestions as data.frame

macro_ex.df <- as.data.frame(data_bio.wrong)
macro_ex_correction.df <- as.data.frame(data_bio.wrong, object = 2)

The calculation of biomonitoring indices in biomonitoR can be done by creating an object with the function aggregate_taxa(). This function aggregates data at various taxonomic levels.

data_agg <- aggregate_taxa(data_bio)

It is possible to subset data prior to import them with the aggregate_taxa() function. This is useful, for example, when the calculations need to be done with some Orders only.

# select EPT Taxa (Ephemeroptera, Plecoptera and Trichoptera)

subset(data_bio, taxa = c("Ephemeroptera", "Plecoptera", "Trichoptera"))

# select Trichoptera excluding the trichopteran family Hydropsychidae

tricho <- subset(data_bio, taxa = "Trichoptera", exclude = "Hydropsychidae")
tricho

# import tricho with the aggregate_taxa() function
tricho_agg <- aggregate_taxa(tricho)

Building your own reference database

Users can provide their own reference database, but they need to imported in the correct format. biomonitoR assists the user in creating their own reference database with the function refFromTree.

# import data

data(Tree)

# Tree is a standard taxonomic tree that needs to be transformed into a reference database
# We can use the function refFromTree

ref_custom <- ref_from_tree(Tree)

The number of taxonomic levels of the reference database is 11 and their number and names cannot be modified. There is the hope to change this beahviour in a next version of biomonitoR.



alexology/biomonitoR documentation built on April 7, 2024, 10:15 a.m.