standardize.Rdstandardize_taxonomy checks taxonomic datasets - fills in blands, checks for duplicates
standardize_trait checks trait data (in wide format) so that modalities for one trait sum to 1
standardize_trait(trait, taxon_column = 1,
trait_class, trait_modality,
meta = data.frame(trait_class = trait_class,
trait_modality = trait_modality))
standardize_taxonomy(taxonomy, verbose = FALSE)(taxon x trait) data or (descriptor x trait) data, in *WIDE* format, and containing numerical values only. Traits can be fuzzy coded. The number of columns with taxonomic information is specified with taxon_column. The default is to have the first column contain the name of the taxon, and taxon_column=1. It is also allowed to have the taxa as row.names of the data.frame; in this case, taxon_column=0.
position(s) or name(s) of the column(s) that holds the taxon names of the (trait) data set, and that should be removed for any calculations. The default is to have the first column holding the taxa. If NULL, or 0, then there is no separate column with names, so the row.names of the dataset are used as taxon names.
indices to trait levels, a vector. The length of this vector should equal the number of columns of trait or wide minus the value of taxon_column. The order should be conform the order in the trait columns (not checked).
names of the modalities of the trait, a vector. Should be of same length as trait_class; it will be matched to the column names of trait
The trait metadata, containing the trait class and modalities.
taxonomic information (the relationships between the taxa), a data.frame; first column will be matched with taxon (in the data.frames data and trait). The subsequent columns should have increasing taxonomic level. (e.g. the column order should be *species, genus, family, ...*. The taxonomic relations from data and trait are used to estimate traits of taxa that are not accounted for, and that will be estimated based on taxa at the nearest taxonomic level. See details.
when TRUE, will write warnings to the screen.
get_taxon_info returns a data.frame with the traits of the species whose modalities are not Null, NULL or None.
get_taxonomy returns the occurrences of taxon within taxonomy.
metadata returns a data.frame with a description of the contents of the database.
. MWTL for the data sets.
map_key for simple plotting functions.
get_density for functions working with density data.
get_Db_index for extracting bioturbation and bioirrigation indices.
extend_trait for functions working with traits.
## ====================================================
## standardizing a trait database
## ====================================================
Btraits <- data.frame(
taxon = c("sp.1","sp.2","sp.3","sp.5","sp.6"),
T1_M1 = c(0 , 0 , 0 , 1 , 0.5),
T1_M2 = c(1 , 0 , 1 , 2 , 0),
T1_M3 = c(0 , 1 , 1 , 3 , 0),
T2_M1 = c(0 , 0 , 1 , 1 , 1),
T2_M2 = c(1 , 1 , 0 , 1 , 0)
)
# The metadata for this trait
Meta <- data.frame(
trait = c("T1" , "T1" , "T1" , "T2" , "T2"),
modality = c("T1_M1", "T1_M2", "T1_M3", "T2_M1", "T2_M2")
)
Btraits
#> taxon T1_M1 T1_M2 T1_M3 T2_M1 T2_M2
#> 1 sp.1 0.0 1 0 0 1
#> 2 sp.2 0.0 0 1 0 1
#> 3 sp.3 0.0 1 1 1 0
#> 4 sp.5 1.0 2 3 1 1
#> 5 sp.6 0.5 0 0 1 0
Meta
#> trait modality
#> 1 T1 T1_M1
#> 2 T1 T1_M2
#> 3 T1 T1_M3
#> 4 T2 T2_M1
#> 5 T2 T2_M2
standardize_trait(Btraits,
trait_class = Meta$trait,
trait_modality = Meta$modality)
#> taxon T1_M1 T1_M2 T1_M3 T2_M1 T2_M2
#> 1 sp.1 0.0000000 1.0000000 0.0 0.0 1.0
#> 2 sp.2 0.0000000 0.0000000 1.0 0.0 1.0
#> 3 sp.3 0.0000000 0.5000000 0.5 1.0 0.0
#> 4 sp.5 0.1666667 0.3333333 0.5 0.5 0.5
#> 5 sp.6 1.0000000 0.0000000 0.0 1.0 0.0
# This will give an error
if (FALSE) { # \dontrun{
# The metadata lack one modality
Meta2 <- data.frame(
trait = c("T2" , "T2", "T1" , "T1" ),
modality = c("T2_M1", "T2_M2", "T1_M1", "T1_M2" )
)
# gives an error
standardize_trait(Btraits,
trait_class = Meta2$trait,
trait_modality = Meta2$modality)
# The traits for species sp1 and sp 2 do not have modality for trait 1:
standardize_trait(Btraits[,-ncol(Btraits)], # remove last column
trait_class = Meta$trait,
trait_modality = Meta$modality)
} # }
## ====================================================
## Standardizing taxonomy
## ====================================================
Btaxonomy <- data.frame(
species = c("sp.1","sp.2","sp.3","sp.4","sp.5","sp.6"),
genus = c( "g.1", " ", "g.2", "g.2", "g.3", "g.4"),
family = c( "f.1", " ", "f.1", "f.1", "f.2", "f.3"),
order = c( "o.1", "o.1", "o.1", "", "o.2", "o.2"),
class = c( "c.1", "c.1", "c.1", "c.1", "c.1", "c.1")
)
Btaxonomy
#> species genus family order class
#> 1 sp.1 g.1 f.1 o.1 c.1
#> 2 sp.2 o.1 c.1
#> 3 sp.3 g.2 f.1 o.1 c.1
#> 4 sp.4 g.2 f.1 c.1
#> 5 sp.5 g.3 f.2 o.2 c.1
#> 6 sp.6 g.4 f.3 o.2 c.1
standardize_taxonomy(Btaxonomy)
#> species genus family order class
#> 1 sp.1 g.1 f.1 o.1 c.1
#> 2 sp.2 sp.2 sp.2 o.1 c.1
#> 3 sp.3 g.2 f.1 o.1 c.1
#> 4 sp.4 g.2 f.1 f.1 c.1
#> 5 sp.5 g.3 f.2 o.2 c.1
#> 6 sp.6 g.4 f.3 o.2 c.1