Diversity.jl
A package for measuring and partitioning diversity
The main Diversity package provides basic numbers-equivalent diversity measures (described in Hill, 1973), similarity-sensitive diversity measures (generalised from Hill, and described in Leinster and Cobbold, 2012), and related alpha, beta and gamma diversity measures at the level of the metacommunity and its component subcommunities (generalised in turn from Leinster and Cobbold, and described in Reeve et al, 2014). The diversity functions exist both with unicode names (e.g. ᾱ()
), which are not automatically exported (as we feel they are too short) and with matching longer ASCII names (e.g. NormalisedAlpha()
), which are. We also provide functions to calculate appropriate subdiv()
and metadiv()
values for each measure, a general diversity()
function for extract any diversity measure at a series of scales.
Accessing the main functionality in the package is simple:
julia> # Load the package into R
using Diversity
julia> # Example population
pop = [1 1 0; 2 0 0; 3 1 4];
julia> pop = pop ./ sum(pop);
julia> # Create Metacommunity object
meta = Metacommunity(pop);
julia> diversities = norm_meta_alpha(meta, [0, 1, 2, Inf])
4×8 DataFrame
Row │ div_type measure q type_level type_name partition_level partition_name diversity
│ String String Float64 String String String String Float64
─────┼───────────────────────────────────────────────────────────────────────────────────────────────────────
1 │ Unique NormalisedAlpha 0.0 types metacommunity 2.16667
2 │ Unique NormalisedAlpha 1.0 types metacommunity 1.86121
3 │ Unique NormalisedAlpha 2.0 types metacommunity 1.63636
4 │ Unique NormalisedAlpha Inf types metacommunity 1.0
julia> Z = [1.0 0 0; 0 1 1; 1 1 1];
julia> meta_z = Metacommunity(pop, Z);
julia> rho = RawRho(meta_z);
julia> redundancies = subdiv(rho, 2)
3×8 DataFrame
Row │ div_type measure q type_level type_name partition_level partition_name diversity
│ String String Int64 String String String String Float64
─────┼────────────────────────────────────────────────────────────────────────────────────────────────
1 │ Arbitrary Z RawRho 2 types subcommunity 1 2.0
2 │ Arbitrary Z RawRho 2 types subcommunity 2 3.0
3 │ Arbitrary Z RawRho 2 types subcommunity 3 3.0
Diversity.Diversity
— ModuleDiversity package
The main Diversity package provides basic numbers-equivalent diversity measures (described in Hill, 1973), similarity-sensitive diversity measures (generalised from Hill, and described in Leinster and Cobbold, 2012), and related alpha, beta and gamma diversity measures at the level of the metacommunity and its component subcommunities (generalised in turn from Leinster and Cobbold, and described in Reeve et al, 2014). The diversity functions exist both with unicode names (e.g. ᾱ()
), which are not automatically exported (as we feel they are too short) and with matching longer ASCII names (e.g. NormalisedAlpha()
), which are. We also provide functions to calculate appropriate subcommunityDiversity()
and metacommunityDiversity()
values for each measure, a general diversity()
function for extract any diversity measure at a series of scales.
Diversity.individualDiversity
— ConstantGenerates the function to calculate individual diversities
Generates the function to calculate individual diversities for a series of orders, represented as a vector of qs.
Arguments:
dm
: DiversityMeasure
Returns:
- Function which takes a single number or vector of values of parameter q, and returns the individual diversities for those values.
Diversity.metacommunityDiversity
— ConstantGenerates the function to calculate metacommunity diversity
Generates the function to calculate metacommunity diversity for a series of orders, represented as a vector of qs.
Arguments:
dm
: DiversityMeasure
Returns:
- Function which takes a single number or vector of values of parameter q, and returns the metacommunity diversities for those values.
Diversity.subcommunityDiversity
— ConstantGenerates the function to calculate subcommunity diversity
Generates the function to calculate subcommunity diversity for a series of orders, represented as a vector of qs.
Arguments:
dm
: DiversityMeasure
Returns:
- Function which takes a single number or vector of values of parameter q, and returns the subcommunity diversities for those values.
Diversity.DiversityLevel
— TypeEnumeration of levels that can exist / be calculated for a metacommunity.
Diversity.DiversityMeasure
— TypeDiversityMeasure
This type is the abstract supertype of all diversity measure types. DiversityMeasure subtypes allow you to calculate and cache any kind of diversity of a metacommunity.
Diversity.Gamma
— TypeGamma
Calculates gamma diversity (γ) of all of the individuals in a metacommunity, and caches them for subsequent analysis. This is a subtype of PowerMeanMeasure, meaning that all composite diversity measures are simple powermeans of the individual measures.
Constructor arguments:
meta
: a Metacommunity
Diversity.GeneralTypes
— TypeGeneralTypes{FP, M, LABELS}
An AbstractTypes subtype with a general similarity matrix. This subtype simply holds a matrix with similarities between individuals.
Members:
z
A two-dimensional matrix representing similarity between
individuals.
names
Vector of type names.
Diversity.GeneralTypes
— MethodGeneralTypes(zmatrix::M)
GeneralTypes(zmatrix::M, names::LABELS)
Constructors for GeneralTypes. Creates an instance of the GeneralTypes class, with an arbitrary zmatrix
similarity matrix and an optional vector of type names
.
Diversity.Metacommunity
— TypeMetacommunity{FP, ARaw, AProcessed, Part, Sim}
Metacommunity type, representing a whole metacommunity containing a single community or a collection of subcommunities. The metacommunity of individuals may be further partitioned into smaller groups. For instance this may be an ecosystem, which consists of a series of subcommunities. The AbstractPartition subtype within it stores relative abundances of different types, e.g. species, and also allows for similarity between individuals.
Constructor:
Metacommunity(abundances::AbstractArray, part::AbstractPartition, types::AbstractTypes)
Members:
abundances
the abundance matrix for the metacommunity.partition
the instance of the AbstractPartition subtype, containing the subcommunities.types
The instance of the AbstractTypes subtype, from which similarities between individuals can be calculated.ordinariness
A cache of the ordinariness of the individuals in the Partition. Should only be accessed through getordinariness!(::Metacommunity), which will populate the cache if it has not yet been calculated.
Diversity.NormalisedAlpha
— TypeNormalisedAlpha
Calculates normalised alpha diversity (ᾱ) of all of the individuals in a metacommunity, and caches them for subsequent analysis. This is a subtype of PowerMeanMeasure, meaning that all composite diversity measures are simple powermeans of the individual measures.
Constructor arguments:
meta
: a Metacommunity
Diversity.NormalisedBeta
— TypeNormalisedBeta
Calculates normalised beta diversity (β̄) of all of the individuals in a metacommunity, and caches them for subsequent analysis. This is a subtype of RelativeEntropyMeasure, meaning that subcommunity and type composite diversity measures are relative entropies, and their composite types are powermeans of those measures.
Constructor arguments:
meta
: a Metacommunity
Diversity.NormalisedRho
— TypeNormalisedRho
Calculates redundancy (ρ̄, normalised beta diversity) of all of the individuals in a metacommunity, and caches them for subsequent analysis. This is a subtype of PowerMeanMeasure, meaning that all composite diversity measures are simple powermeans of the individual measures.
Constructor arguments:
meta
: a Metacommunity
Diversity.Onecommunity
— TypeOnecommunity
AbstractPartition subtype containing only one subcommunity.
Diversity.PowerMeanMeasure
— TypePowerMeanMeasure
This abstract DiversityMeasure subtype is the supertype of all diversity measures which are straight power means. PowerMeanMeasure subtypes allow you to calculate and cache any kind of diversity of a metacommunity.
Diversity.RawAlpha
— TypeRawAlpha
Calculates raw alpha diversity (α) of all of the individuals in a metacommunity, and caches them for subsequent analysis. This is a subtype of PowerMeanMeasure, meaning that all composite diversity measures are simple powermeans of the individual measures.
Constructor arguments:
meta
: a Metacommunity
Diversity.RawBeta
— TypeRawBeta
Calculates distinctiveness (β, raw beta diversity) of all of the individuals in a metacommunity, and caches them for subsequent analysis. This is a subtype of RelativeEntropyMeasure, meaning that subcommunity and type composite diversity measures are relative entropies, and their composite types are powermeans of those measures.
Constructor arguments:
meta
: a Metacommunity
Diversity.RawRho
— TypeRawRho
Calculates redundancy (ρ, raw beta diversity) of all of the individuals in a metacommunity, and caches them for subsequent analysis. This is a subtype of PowerMeanMeasure, meaning that all composite diversity measures are simple powermeans of the individual measures.
Constructor arguments:
meta
: a Metacommunity
Diversity.RelativeEntropyMeasure
— TypeRelativeEntropyMeasure
This abstract DiversityMeasure subtype is the supertype of all diversity measures which are relative entropy-based diversity measures. RelativeEntropyMeasure subtypes allow you to calculate and cache any kind of diversity of a metacommunity.
Diversity.Species
— TypeSpecies
A subtype of AbstractTypes where all species are completely distinct. This type is the simplest AbstractTypes subtype, which identifies all species as unique and completely distinct from each other.
Diversity.Subcommunities
— TypeSubcommunities(num)
AbstractPartition subtype with multiple subcommunities.
Diversity.Taxonomy
— TypeTaxonomy
A subtype of AbstractTypes with similarity between related taxa, creating taxonomic similarity matrices.
Diversity.UniqueTypes
— TypeUniqueTypes
A subtype of AbstractTypes where all individuals are completely distinct. This type is the simplest AbstractTypes subtype, which identifies all individuals as unique and completely distinct from each other.
Diversity.addedoutputcols
— Functionaddedoutputcols(m::AbstractAssemblage)
addedoutputcols(t::AbstractTypes)
Returns the name of any additional columns needed to disambiguate the diversity type used.
Diversity.calcsimilarity
— Methodcalcsimilarity(t::AbstractTypes, scale::Real)
Retrieves (and possibly calculates) a similarity matrix from t.
Diversity.countsubcommunities
— Functioncountsubcommunities(m::AbstractAssemblage)
countsubcommunities(p::AbstractPartition)
Returns number of subcommunities in an AbstractPartition
object or the AbstractAssemblage
containing it.
Diversity.counttypes
— Functioncounttypes(m::AbstractAssemblage[, raw::Bool = false])
counttypes(t::AbstractTypes[, raw::Bool = false])
Returns number of types in an AbstractTypes
object or the AbstractAssemblage
containing it. raw
determines whether to count the number of raw or processed types, which varies, for instance, when the types are determined by a phylogeny.
Diversity.diversity
— MethodCalculates subcommunity and metacommunity diversities
Calculates any diversity of a Metacommunity for a series of orders, repesented as one or a vector of qs.
Arguments:
dls
: an iterable collection of DiversityLevelsdms
: an iterable collection of DiversityMeasuresmeta
: a Metacommunityqs
: single number or vector of values of parameter q
Returns:
A vector containing all of the diversity levels of all of the requested diversities.
Diversity.getASCIIName
— MethodgetASCIIName(dm::DiversityMeasure)
Return the ASCII name of the DiversityMeasure
Arguments:
dm
: DiversityMeasure
Returns:
- String containing simple ASCII name of DiversityMeasure
Diversity.getFullName
— FunctiongetFullName(dm::DiversityMeasure)
Return the full name of the DiversityMeasure.
Arguments:
dm
: DiversityMeasure
Returns:
- String containing full descriptive name of DiversityMeasure
Diversity.getName
— FunctiongetName(dm::DiversityMeasure)
Return the character corresponding to the DiversityMeasure.
Arguments:
dm
: DiversityMeasure
Returns:
- String containing unicode (greek) name of DiversityMeasure.
Diversity.getabundance
— Functiongetabundance(m::AbstractAssemblage, raw::Bool)
Returns the abundances array of the metacommunity.
Diversity.getaddedoutput
— Functiongetaddedoutput(::AbstractTypes)
Returns the contents of any additional columns to be added to outputs.
Diversity.getdiversityname
— Functiongetdiversityname(m::AbstractAssemblage)
getdiversityname(t::AbstractTypes)
Returns the name of the diversity type used.
Diversity.getmetaabundance
— Functiongetmetaabundance(m::AbstractAssemblage)
Returns the metacommunity abundances of the metacommunity.
Diversity.getmetaordinariness!
— Methodgetmetaordinariness!(m::AbstractAssemblage)
Returns (and possibly calculates) the ordinariness of the metacommunity as a whole.
Diversity.getordinariness!
— Methodgetordinariness!(m::AbstractAssemblage)
Returns (and possibly calculates) the ordinariness array of the subcommunities.
Diversity.getpartition
— Methodgetpartition(m::AbstractAssemblage)
Returns the AbstractPartition component of the metacommunity.
Diversity.getsubcommunitynames
— Functiongetsubcommunitynames(m::AbstractAssemblage)
getsubcommunitynames(p::AbstractPartition)
Returns the names of the subcommunities in an AbstractPartition
object or the AbstractAssemblage
containing it.
Diversity.gettypenames
— Functiongettypenames(m::AbstractAssemblage[, raw::Bool = false])
gettypenames(t::AbstractTypes[, raw::Bool = false])
Returns the names of the types of the AbstractTypes
object or the AbstractAssemblage
containing it. raw
determines whether to count the number of raw or processed types, which varies, for instance, when the types are determined by a phylogeny.
Diversity.gettypes
— Methodgettypes(m::AbstractAssemblage)
Returns the AbstractTypes component of the metacommunity.
Diversity.getweight
— Methodgetweight(m::AbstractAssemblage)
Returns the subcommunity weights of the metacommunity.
Diversity.hassimilarity
— Functionhassimilarity(t::AbstractAssemblage)
hassimilarity(t::AbstractThings)
Is there similarity of some non-trivial type in the object?
Diversity.inddiv
— Functioninddiv(measure::DiversityMeasure, q::Real)
inddiv(measure::DiversityMeasure, qs::AbstractVector{Real})
Takes a diversity measure and single order or vector of orders, and returns a DataFrame containing the individual diversities for those values.
Arguments:
dm
: DiversityMeasureq
/qs
: a single order or a vector of orders
Returns:
- Returns individual diversities of
dm
for a single orderq
or a vector of orderqs
.
Diversity.metadiv
— Functionmetadiv(measure::DiversityMeasure, q::Real)
metadiv(measure::DiversityMeasure, qs::AbstractVector{Real})
Takes a diversity measure and single order or vector of orders, and calculates and returns the metacommunity diversities for those values.
Arguments:
dm
: DiversityMeasureq
/qs
: a single order or a vector of orders
Returns:
- Returns metacommunity diversities of
dm
for a single orderq
or a vector of orderqs
.
Diversity.qD
— FunctionqD
Calculates Hill / naive-similarity diversity of order(s) qs of a population with given relative proportions.
Arguments:
proportions
: relative proportions of different types in populationqs
: single number or vector of orders of diversity measurement
Returns:
- Diversity of order qs (single number or vector of diversities)
Diversity.qDZ
— FunctionqDZ
Calculates Leinster-Cobbold / similarity-sensitive diversity of >= 1 order(s) qs of a population with given relative proportions, and similarity matrix Z.
Arguments:
proportions
: relative proportions of different types in a populationqs
: single number or vector of orders of diversity measurementZ
: similarity matrix
Returns:
Diversity of order qs (single number or vector of diversities)
Diversity.subdiv
— Functionsubdiv(measure::DiversityMeasure, q::Real)
subdiv(measure::DiversityMeasure, qs::AbstractVector{Real})
Takes a diversity measure and single order or vector of orders, and calculates and returns the subcommunity diversities for those values.
Arguments:
dm
: DiversityMeasureq
/qs
: a single order or a vector of orders
Returns:
- Returns subcommunity diversities of
dm
for a single orderq
or a vector of orderqs
.
Diversity.ShortNames
— ModuleDiversity.ShortNames submodule
We do not directly export ᾱ
, α
, β̄
, β
, ρ̄
, ρ
, γ
as they're too short. γ
actually can't be exported like this - it'll always just be Shortnames.γ
, so we export Γ
instead.
All of these can only be accessed via Diversity.ShortNames
.
Private functions in module Diversity:
Diversity._getmeta
— Method_getmeta(dm::DiversityMeasure)
Return the metacommunity belonging to the DiversityMeasure.
Diversity.powermean
— Functionpowermean
Calculates the weighted powermean of a series of numbers
Calculates orderth power mean of values, weighted by weights. By default, weights are equal and order is 1, so this is just the arithmetic mean.
Arguments:
values
: values for which to calculate meanorder[s]
: order[s] of power meanweights
: weights of elements, normalised to 1 inside function
Returns:
- weighted power mean(s)
Diversity.API
Diversity.Diversity
Diversity.Ecology
Diversity.Hill
Diversity.Jost
Diversity.ShortNames
Diversity.individualDiversity
Diversity.metacommunityDiversity
Diversity.subcommunityDiversity
Diversity.API.AbstractMetacommunity
Diversity.API.AbstractPartition
Diversity.API.AbstractTypes
Diversity.DiversityLevel
Diversity.DiversityMeasure
Diversity.Gamma
Diversity.GeneralTypes
Diversity.GeneralTypes
Diversity.Metacommunity
Diversity.NormalisedAlpha
Diversity.NormalisedBeta
Diversity.NormalisedRho
Diversity.Onecommunity
Diversity.PowerMeanMeasure
Diversity.RawAlpha
Diversity.RawBeta
Diversity.RawRho
Diversity.RelativeEntropyMeasure
Diversity.Species
Diversity.Subcommunities
Diversity.Taxonomy
Diversity.UniqueTypes
Diversity.API._addedoutputcols
Diversity.API._calcabundance
Diversity.API._calcordinariness
Diversity.API._calcsimilarity
Diversity.API._countsubcommunities
Diversity.API._counttypes
Diversity.API._getabundance
Diversity.API._getaddedoutput
Diversity.API._getdiversityname
Diversity.API._getmetaabundance
Diversity.API._getmetaordinariness!
Diversity.API._getordinariness!
Diversity.API._getpartition
Diversity.API._getscale
Diversity.API._getsubcommunitynames
Diversity.API._gettypenames
Diversity.API._gettypes
Diversity.API._getweight
Diversity.API.floattypes
Diversity.API.mcmatch
Diversity.API.typematch
Diversity.Ecology.generalisedjaccard
Diversity.Ecology.generalisedrichness
Diversity.Ecology.generalisedshannon
Diversity.Ecology.generalisedsimpson
Diversity.Ecology.gower
Diversity.Ecology.jaccard
Diversity.Ecology.pielou
Diversity.Ecology.richness
Diversity.Ecology.shannon
Diversity.Ecology.simpson
Diversity.Hill.hillnumber
Diversity.Jost.jostalpha
Diversity.Jost.jostbeta
Diversity._getmeta
Diversity.addedoutputcols
Diversity.calcsimilarity
Diversity.countsubcommunities
Diversity.counttypes
Diversity.diversity
Diversity.getASCIIName
Diversity.getFullName
Diversity.getName
Diversity.getabundance
Diversity.getaddedoutput
Diversity.getdiversityname
Diversity.getmetaabundance
Diversity.getmetaordinariness!
Diversity.getordinariness!
Diversity.getpartition
Diversity.getsubcommunitynames
Diversity.gettypenames
Diversity.gettypes
Diversity.getweight
Diversity.hassimilarity
Diversity.inddiv
Diversity.metadiv
Diversity.powermean
Diversity.qD
Diversity.qDZ
Diversity.subdiv