Title: | Measurement and Partitioning of Similarity-Sensitive Biodiversity |
---|---|
Description: | Provides a framework for the measurement and partitioning of the (similarity-sensitive) biodiversity of a metacommunity and its constituent subcommunities. Richard Reeve, et al. (2016) <arXiv:1404.6520v3>. |
Authors: | Sonia Mitchell [aut] |
Maintainer: | Richard Reeve <[email protected]> |
License: | GPL-3 |
Version: | 2.2.0 |
Built: | 2025-03-12 05:15:39 UTC |
Source: | https://github.com/boydorr/rdiversity |
rdiversity
is an R package based around a framework for measuring and
partitioning biodiversity using similarity-sensitive diversity measures. It
provides functionality for measuring alpha, beta and gamma diversity of
metacommunities (e.g. ecosystems) and their constituent subcommunities,
where similarity may be defined as taxonomic, phenotypic, genetic, phylogenetic,
functional, and so on. It uses the diversity measures described in the arXiv
paper, 'How to partition diversity'.
For more information go to our GitHub page; https://github.com/boydorr/rdiversity
Please raise an issue if you find any problems; https://github.com/boydorr/rdiversity/issues
This package is cross-validated against our Julia package; https://github.com/EcoJulia/Diversity.jl
Sonia Mitchell
Richard Reeve <[email protected]> (maintainer)
Reeve, R., T. Leinster, C. Cobbold, J. Thompson, N. Brummitt, S. Mitchell, and L. Matthews. 2016. How to partition diversity. (https://arxiv.org/abs/1404.6520)
Converts an integer (Base10) to a binary (Base2) number. It also converts a logical vector to a binary (Base2) number (see examples).
as.binary(x, signed=FALSE, littleEndian=FALSE, size=2, n=0, logic=FALSE)
as.binary(x, signed=FALSE, littleEndian=FALSE, size=2, n=0, logic=FALSE)
x |
integer or logical vector. |
signed |
TRUE or FALSE. Unsigned by default. (two's complement) |
littleEndian |
if TRUE. Big Endian if FALSE. |
size |
in Byte. Needed if signed is set. (by default 2 Byte) |
n |
in Bit. Can be set if unsigned is set to TRUE. (by default 0 Bit = auto) |
logic |
If set to TRUE, x is expected as logical vector. |
The binary number is represented by a logical vector. The bit order usually follows the same endianess as the byte order. No floating-point support. If logic is set to TRUE an integer vector is intepreted as a logical vector (>0 becomes TRUE and 0 becomes FALSE)
Little Endian (LSB) —> (MSB)
Big Endian (MSB) <— (LSB)
Auto switch to signed if num < 0.
a vector of class binary.
as.binary(0xAF) as.binary(42) as.binary(42, littleEndian=TRUE) as.binary(c(0xAF, 0xBF, 0xFF)) as.binary(c(2,4,8,16,32), signed=TRUE, size=1) as.binary(-1, signed=TRUE, size=1) as.binary(1:7, n=3) as.binary(sample(2^8,3),n=8) as.binary(c(1,1,0), signed=TRUE, logic=TRUE) as.binary(c(TRUE,TRUE,FALSE), logic=TRUE)
as.binary(0xAF) as.binary(42) as.binary(42, littleEndian=TRUE) as.binary(c(0xAF, 0xBF, 0xFF)) as.binary(c(2,4,8,16,32), signed=TRUE, size=1) as.binary(-1, signed=TRUE, size=1) as.binary(1:7, n=3) as.binary(sample(2^8,3),n=8) as.binary(c(1,1,0), signed=TRUE, logic=TRUE) as.binary(c(TRUE,TRUE,FALSE), logic=TRUE)
Adds two binary numbers. (x + y)
binAdd(x, y)
binAdd(x, y)
x |
summand 1 (binary vector) |
y |
summand 2 (binary vector) |
Little-Endian and unsigned is not supported at the moment. No floating point supported. if x or y is signed the return value will also be signed.
The sum of x and y. Returns a binary vector.
base::as.logical , base::is.logical, base::raw
five <- as.binary(5); ten <- as.binary(10); as.numeric(rdiversity:::binAdd(ten, five)) rdiversity:::binAdd(as.binary(c(0,1), logic=TRUE), as.binary(c(1,0), logic=TRUE))
five <- as.binary(5); ten <- as.binary(10); as.numeric(rdiversity:::binAdd(ten, five)) rdiversity:::binAdd(as.binary(c(0,1), logic=TRUE), as.binary(c(1,0), logic=TRUE))
Create objects of type binary.
binary(n, signed=FALSE, littleEndian=FALSE)
binary(n, signed=FALSE, littleEndian=FALSE)
n |
length of vector. Number of bits |
signed |
TRUE or FALSE. Unsigned by default. (two's complement) |
littleEndian |
if TRUE. Big Endian if FALSE. |
The binary number is represented by a logical vector. The bit order usually follows the same endianess as the byte order. How to read:
Little Endian (LSB) —> (MSB)
Big Endian (MSB) <— (LSB)
The Big Endian endianess stores its MSB at the lowest adress. The Little Endian endianess stores its MSB at the highest adress.
e.g. b <-binary(8).
"Little Endian" : MSB at b[1] and LSB at b[8].
"Big Endian" : LSB at b[1] and MSB at b[8].
No floating-point support.
a vector of class binary of length n. By default filled with zeros(0).
b <- rdiversity:::binary(8) summary(b) b <- rdiversity:::binary(16, signed=TRUE) summary(b) b <- rdiversity:::binary(32, littleEndian=TRUE) summary(b)
b <- rdiversity:::binary(8) summary(b) b <- rdiversity:::binary(16, signed=TRUE) summary(b) b <- rdiversity:::binary(32, littleEndian=TRUE) summary(b)
Binary sequence.
binSeq(x, ...)
binSeq(x, ...)
x |
a sequence. |
... |
used for dec2bin(). |
a sequence list of binary digits.
rdiversity:::binSeq(0:4)
rdiversity:::binSeq(0:4)
Used to increase readabilaty
byte()
byte()
The size of one byte (8)
A simple helper function that returns the minimum number of byte needed to hold the amount of n bit.
bytesNeeded(n)
bytesNeeded(n)
n |
The number of bit. |
The number of minimum byte needed to hold n bit.
fillUpToByte or byte
ten <- as.binary(10) rdiversity:::bytesNeeded(length(ten))
ten <- as.binary(10) rdiversity:::bytesNeeded(length(ten))
Function to cut the phylogeny to a specified depth from the tip with the greatest distance from the root.
chainsaw(partition, ps, depth)
chainsaw(partition, ps, depth)
partition |
two-dimensional |
ps |
|
depth |
proportion of total tree height to be conserved (taken as a proportion from the highest tip). Describes how far back we go in the tree, with 0 marking the date of the most recent tip, and 1 marking the most recent common ancestor. Numbers greater than 1 extend the root of the tree |
chainsaw()
returns an object of class metacommunity
Converts distance
objects into similarity
objects.
dist2sim(dist, transform, k = 1, normalise = TRUE, max_d)
dist2sim(dist, transform, k = 1, normalise = TRUE, max_d)
dist |
object of class |
transform |
object of class |
k |
scaling parameter |
normalise |
object of class |
max_d |
object of class |
Distances can be transformed either *linearly* or *exponentially*. That is
1 - k * dist
for non-negative values, or exp(-k * dist)
,
respectively. If normalise
is true, then dist = dist/max_d
.
dist2sim(x)
returns an object of class similarity
.
Container for class distance
.
distance(distance, dat_id) ## S4 method for signature 'matrix,character' distance(distance, dat_id) ## S4 method for signature 'matrix,missing' distance(distance, dat_id)
distance(distance, dat_id) ## S4 method for signature 'matrix,character' distance(distance, dat_id) ## S4 method for signature 'matrix,missing' distance(distance, dat_id)
distance |
distance matrix |
dat_id |
object of class |
distance()
returns an object of class distance
.
Container for class distance
.
## S4 method for signature 'distance' show(object)
## S4 method for signature 'distance' show(object)
object |
object of class |
distance
two-dimensional matrix
of mode numeric
with rows as types, columns as types, and elements containing the pairwise
distance of types
dat_id
object of class character
describing the class of
distance / similarity being used, e.g. "naive", "taxonomic", and so on
components
list containing the components necessary to calculate
similarity. This list is empty when precompute_dist = TRUE
when
calculating distance. When a pairwise distance matrix is too large and
precompute_dist = FALSE
, this list contains all the information
required to calculate pairwise distance between types
Fills up the binary number with zeros(0) or ones(1), to the size n in bit.
fillUpToBit(x, n, value=FALSE)
fillUpToBit(x, n, value=FALSE)
x |
The binary number to fill up with zeros. (Any binary vector). |
n |
size in bit. |
value |
to fill up with FALSE(0) or fill up with TRUE(1). |
No floating point supported.
binary number. A binary vector with the desired size.
rdiversity:::fillUpToBit(as.binary(c(1,1), logic=TRUE), n=4) rdiversity:::fillUpToBit(as.binary(c(1,0,1), logic=TRUE), n=4, value=FALSE)
rdiversity:::fillUpToBit(as.binary(c(1,1), logic=TRUE), n=4) rdiversity:::fillUpToBit(as.binary(c(1,0,1), logic=TRUE), n=4, value=FALSE)
Fills up the binary number with zeros(0) or ones(1), to the size in Byte.
fillUpToByte(x, size=0, value=FALSE)
fillUpToByte(x, size=0, value=FALSE)
x |
The binary number to fill up with zeros. (Any binary vector). |
size |
in Byte. 0 = auto (smallest possible Byte). |
value |
to fill up with FALSE(0) or fill up with TRUE(1). |
No floating point supported.
binary number. A binary vector with the desired size.
rdiversity:::fillUpToByte(as.binary(c(1,1), logic=TRUE), size=2) rdiversity:::fillUpToByte(as.binary(c(1,0,1), logic=TRUE), size=2, value=FALSE)
rdiversity:::fillUpToByte(as.binary(c(1,1), logic=TRUE), size=2) rdiversity:::fillUpToByte(as.binary(c(1,0,1), logic=TRUE), size=2, value=FALSE)
Converts a vcfR object to a matrix of pairwise genetic distances.
gen2dist(vcf, biallelic = FALSE)
gen2dist(vcf, biallelic = FALSE)
vcf |
object of class |
biallelic |
logical describing whether the data is biallelic or not (default). |
gen2dist(x)
returns an object of class distance
containing a matrix
of pairwise genetic distances.
Generic function for calculating individual-level diversity.
inddiv(data, qs) ## S4 method for signature 'powermean' inddiv(data, qs) ## S4 method for signature 'relativeentropy' inddiv(data, qs) ## S4 method for signature 'metacommunity' inddiv(data, qs)
inddiv(data, qs) ## S4 method for signature 'powermean' inddiv(data, qs) ## S4 method for signature 'relativeentropy' inddiv(data, qs) ## S4 method for signature 'metacommunity' inddiv(data, qs)
data |
|
qs |
|
data
may be input as three different classes:
power_mean
: calculates raw and normalised subcommunity alpha, rho
or gamma diversity by taking the powermean of diversity components
relativeentropy
: calculates raw or normalised subcommunity beta
diversity by taking the relative entropy of diversity components
metacommunity
: calculates all subcommunity measures of diversity
inddiv()
returns a standard output of class rdiv
Reeve, R., T. Leinster, C. Cobbold, J. Thompson, N. Brummitt, S. Mitchell, and L. Matthews. 2016. How to partition diversity. arXiv 1404.6520v3:1–9.
subdiv
for subcommunity-level diversity and
metadiv
for metacommunity-level diversity.
# Define metacommunity pop <- cbind.data.frame(A = c(1,1), B = c(2,0), C = c(3,1)) row.names(pop) <- paste0("sp", 1:2) pop <- pop/sum(pop) meta <- metacommunity(pop) # Calculate subcommunity gamma diversity (takes the power mean) g <- raw_gamma(meta) inddiv(g, 0:2) # Calculate subcommunity beta diversity (takes the relative entropy) b <- raw_beta(meta) inddiv(b, 0:2) # Calculate all measures of individual diversity inddiv(meta, 0:2)
# Define metacommunity pop <- cbind.data.frame(A = c(1,1), B = c(2,0), C = c(3,1)) row.names(pop) <- paste0("sp", 1:2) pop <- pop/sum(pop) meta <- metacommunity(pop) # Calculate subcommunity gamma diversity (takes the power mean) g <- raw_gamma(meta) inddiv(g, 0:2) # Calculate subcommunity beta diversity (takes the relative entropy) b <- raw_beta(meta) inddiv(b, 0:2) # Calculate all measures of individual diversity inddiv(meta, 0:2)
test for object "binary".
is.binary(x)
is.binary(x)
x |
object to test. |
TRUE or FALSE.
Helper function load Attributes
loadAttributes(x, l)
loadAttributes(x, l)
x |
x |
l |
l |
Calculates similarity-sensitive metacommunity gamma diversity (the
metacommunity similarity-sensitive diversity). This measure may be
calculated for a series of orders, represented as a vector of qs
.
meta_gamma(meta, qs)
meta_gamma(meta, qs)
meta |
object of class |
qs |
|
meta_gamma
returns a standard output of class rdiv
R. Reeve, T. Leinster, C. Cobbold, J. Thompson, N. Brummitt, S. Mitchell, and L. Matthews. 2016. How to partition diversity. arXiv 1404.6520v3:1–9.
pop <- data.frame(a = c(1,3), b = c(1,1)) row.names(pop) <- paste0("sp", 1:2) pop <- pop/sum(pop) meta <- metacommunity(pop) # Calculate metacommunity gamma diversity meta_gamma(meta, 0:2)
pop <- data.frame(a = c(1,3), b = c(1,1)) row.names(pop) <- paste0("sp", 1:2) pop <- pop/sum(pop) meta <- metacommunity(pop) # Calculate metacommunity gamma diversity meta_gamma(meta, 0:2)
Functions to generate a metacommunity
object.
metacommunity(partition, similarity) ## S4 method for signature 'data.frame,missing' metacommunity(partition) ## S4 method for signature 'numeric,missing' metacommunity(partition) ## S4 method for signature 'matrix,missing' metacommunity(partition) ## S4 method for signature 'missing,similarity' metacommunity(partition, similarity) ## S4 method for signature 'numeric,similarity' metacommunity(partition, similarity) ## S4 method for signature 'data.frame,similarity' metacommunity(partition, similarity) ## S4 method for signature 'matrix,similarity' metacommunity(partition, similarity)
metacommunity(partition, similarity) ## S4 method for signature 'data.frame,missing' metacommunity(partition) ## S4 method for signature 'numeric,missing' metacommunity(partition) ## S4 method for signature 'matrix,missing' metacommunity(partition) ## S4 method for signature 'missing,similarity' metacommunity(partition, similarity) ## S4 method for signature 'numeric,similarity' metacommunity(partition, similarity) ## S4 method for signature 'data.frame,similarity' metacommunity(partition, similarity) ## S4 method for signature 'matrix,similarity' metacommunity(partition, similarity)
partition |
two-dimensional |
similarity |
(optional) object of class |
metacommunity()
returns an object of class
metacommunity
(see Fields).
type_abundance
two-dimensional matrix
of mode numeric
with rows as types (species), columns as subcommunities, and each
element containing the relative abundance of types in each subcommunity
relative to the metacommunity as a whole. In the phylogenetic case, this
corresponds to the proportional abundance of historical species, which is
calculated from the proportional abundance of terminal taxa
similarity
two-dimensional matrix
of mode numeric
with
rows as types, columns as types, and elements containing pairwise
similarities between types
similarity_components
list containing the components necessary to
calculate similarity. This list is empty when precompute_dist = TRUE
when calculating distance. When a pairwise distance matrix is too large and
precompute_dist = FALSE
, this list contains all the information
required to calculate pairwise distance between types
similarity_parameters
list containing parameters associated with
converting pairwise distances to similarities (the dist2sim()
arguments)
ordinariness
two-dimensional matrix
of mode numeric
with rows as types, columns as subcommunities, and elements containing the
ordinariness of types within subcommunities
subcommunity_weights
vector
of mode numeric
containing
subcommunity weights
type_weights
two-dimensional matrix
of mode numeric
,
with rows as types, columns as subcommunities, and elements containing
weights of types within a subcommunity
dat_ID
object of class character
denoting the type of diversity
being calculated. This can be "naive", "genetic", "taxonomic", and so on
raw_abundance
[Phylogenetic] two-dimensional matrix
of mode
numeric
with rows as types, columns as subcommunities, and elements
containing the relative abundance of present day species
raw_structure
[Phylogenetic] two-dimensional matrix
of mode
numeric
with rows as historical species, columns as present day
species, and elements containing historical species lengths within lineages
parameters
[Phylogenetic] data.frame
containing parameters
associated with each historic species in the phylogeny
# Naive-type partition <- cbind(a = c(1,1,1,0,0), b = c(0,1,0,1,1)) row.names(partition) <- paste0("sp", 1:5) partition <- partition / sum(partition) meta <- metacommunity(partition)
# Naive-type partition <- cbind(a = c(1,1,1,0,0), b = c(0,1,0,1,1)) row.names(partition) <- paste0("sp", 1:5) partition <- partition / sum(partition) meta <- metacommunity(partition)
Container for class metacommunity
.
## S4 method for signature 'metacommunity' show(object)
## S4 method for signature 'metacommunity' show(object)
object |
object of class |
type_abundance
two-dimensional matrix
of mode numeric
with rows as types (species), columns as subcommunities, and each
element containing the relative abundance of types in each subcommunity
relative to the metacommunity as a whole. In the phylogenetic case, this
corresponds to the proportional abundance of historical species, which is
calculated from the proportional abundance of terminal taxa
similarity
two-dimensional matrix
of mode numeric
with rows as types, columns as types, and elements containing the pairwise
similarity of types
similarity_components
list containing the components necessary to
calculate similarity. This list is empty when precompute_dist = TRUE
when calculating distance. When a pairwise distance matrix is too large and
precompute_dist = FALSE
, this list contains all the information
required to calculate pairwise distance between types
similarity_parameters
list containing parameters associated with
converting pairwise distances to similarities (the dist2sim()
arguments)
ordinariness
two-dimensional matrix
of mode numeric
with rows as types, columns as subcommunities, and elements containing the
ordinariness of types within subcommunities
subcommunity_weights
vector
of mode numeric
containing
subcommunity weights
type_weights
two-dimensional matrix
of mode numeric
,
with rows as types, columns as subcommunities, and elements containing
weights of types within a subcommunity
dat_id
object of class character
describing the class of
distance / similarity being used, e.g. "naive", "taxonomic", and so on
raw_abundance
[Phylogenetic] two-dimensional matrix
of mode
numeric
with rows as types, columns as subcommunities, and elements
containing the relative abundance of present day species
raw_structure
[Phylogenetic] two-dimensional matrix
of mode
numeric
with rows as historical species, columns as present day
species, and elements containing historical species lengths within lineages
parameters
[Phylogenetic] data.frame
containing parameters
associated with each historic species in the phylogeny
Generic function for calculating metacommunity-level diversity.
metadiv(data, qs) ## S4 method for signature 'powermean' metadiv(data, qs) ## S4 method for signature 'relativeentropy' metadiv(data, qs) ## S4 method for signature 'metacommunity' metadiv(data, qs)
metadiv(data, qs) ## S4 method for signature 'powermean' metadiv(data, qs) ## S4 method for signature 'relativeentropy' metadiv(data, qs) ## S4 method for signature 'metacommunity' metadiv(data, qs)
data |
|
qs |
|
data
may be input as one of three different classes:
powermean
: raw or normalised metacommunity alpha, rho or gamma
diversity components; will calculate metacommunity-level raw or normalised
metacommunity alpha, rho or gamma diversity
relativeentropy
: raw or normalised metacommunity beta
diversity components; will calculate metacommunity-level raw or normalised
metacommunity beta diversity
metacommunity
: will calculate all metacommunity measures of
diversity
metadiv()
returns a standard output of class rdiv
Reeve, R., T. Leinster, C. Cobbold, J. Thompson, N. Brummitt, S. Mitchell, and L. Matthews. 2016. How to partition diversity. arXiv 1404.6520v3:1–9.
inddiv
for type-level diversity and
subdiv
for subcommunity-level diversity.
# Define metacommunity pop <- data.frame(a = c(1,3), b = c(1,1)) pop <- pop / sum(pop) meta <- metacommunity(pop) # Calculate metacommunity gamma diversity (takes the power mean) g <- raw_gamma(meta) metadiv(g, 0:2) # Calculate metacommunity beta diversity (takes the relative entropy) b <- raw_beta(meta) metadiv(b, 0:2) # Calculate all measures of metacommunity diversity metadiv(meta, 0:2)
# Define metacommunity pop <- data.frame(a = c(1,3), b = c(1,1)) pop <- pop / sum(pop) meta <- metacommunity(pop) # Calculate metacommunity gamma diversity (takes the power mean) g <- raw_gamma(meta) metadiv(g, 0:2) # Calculate metacommunity beta diversity (takes the relative entropy) b <- raw_beta(meta) metadiv(b, 0:2) # Calculate all measures of metacommunity diversity metadiv(meta, 0:2)
Negates the binary number x. Negation x -> -x or -x -> x
negate(x)
negate(x)
x |
The number to be negated. A binary vector is expected. |
An »unsigned« number will be returned as »signed« regardless of whether the value is negative. No floating point supported.
The negated number of x. Returns a binary vector with signed=TRUE
switchEndianess or fillUpToByte.
summary(rdiversity:::negate(as.binary(5, signed=TRUE))) summary(rdiversity:::negate(as.binary(-5, signed=TRUE))) summary(rdiversity:::negate(as.binary(5, signed=FALSE)))
summary(rdiversity:::negate(as.binary(5, signed=TRUE))) summary(rdiversity:::negate(as.binary(-5, signed=TRUE))) summary(rdiversity:::negate(as.binary(5, signed=FALSE)))
Calculates the low-level diversity component necessary for calculating normalised alpha diversity.
norm_alpha(meta)
norm_alpha(meta)
meta |
object of class |
Values generated from norm_alpha()
may be input into subdiv()
and metadiv()
to calculate normalised subcommunity and metacommunity
alpha diversity.
norm_alpha
returns an object of class powermean
R. Reeve, T. Leinster, C. Cobbold, J. Thompson, N. Brummitt, S. Mitchell, and L. Matthews. 2016. How to partition diversity. arXiv 1404.6520v3:1–9.
pop <- data.frame(a = c(1,3), b = c(1,1)) row.names(pop) <- paste0("sp", 1:2) pop <- pop/sum(pop) meta <- metacommunity(pop) # Calculate normalised alpha component a <- norm_alpha(meta) subdiv(a, 1) metadiv(a, 1)
pop <- data.frame(a = c(1,3), b = c(1,1)) row.names(pop) <- paste0("sp", 1:2) pop <- pop/sum(pop) meta <- metacommunity(pop) # Calculate normalised alpha component a <- norm_alpha(meta) subdiv(a, 1) metadiv(a, 1)
Calculates the low-level diversity component necessary for calculating normalised beta diversity.
norm_beta(meta)
norm_beta(meta)
meta |
object of class |
Values generated from norm_beta()
may be input into subdiv()
and
metadiv()
to calculate normalised subcommunity and metacommunity beta
diversity.
norm_beta
returns an object of class relativeentropy
R. Reeve, T. Leinster, C. Cobbold, J. Thompson, N. Brummitt, S. Mitchell, and L. Matthews. 2016. How to partition diversity. arXiv 1404.6520v3:1–9.
pop <- data.frame(a = c(1,3), b = c(1,1)) row.names(pop) <- paste0("sp", 1:2) pop <- pop/sum(pop) meta <- metacommunity(pop) # Calculate normalised beta component b <- norm_beta(meta) subdiv(b, 1) metadiv(b, 1)
pop <- data.frame(a = c(1,3), b = c(1,1)) row.names(pop) <- paste0("sp", 1:2) pop <- pop/sum(pop) meta <- metacommunity(pop) # Calculate normalised beta component b <- norm_beta(meta) subdiv(b, 1) metadiv(b, 1)
Calculates similarity-sensitive normalised metacommunity alpha diversity
(the average similarity-sensitive diversity of subcommunities). This
measure may be calculated for a series of orders, represented as a vector
of qs
.
norm_meta_alpha(meta, qs)
norm_meta_alpha(meta, qs)
meta |
object of class |
qs |
|
norm_meta_alpha
returns a standard output of class rdiv
R. Reeve, T. Leinster, C. Cobbold, J. Thompson, N. Brummitt, S. Mitchell, and L. Matthews. 2016. How to partition diversity. arXiv 1404.6520v3:1–9.
pop <- data.frame(a = c(1,3), b = c(1,1)) row.names(pop) <- paste0("sp", 1:2) pop <- pop/sum(pop) meta <- metacommunity(pop) # Calculate normalised metacommunity alpha diversity norm_meta_alpha(meta, 0:2)
pop <- data.frame(a = c(1,3), b = c(1,1)) row.names(pop) <- paste0("sp", 1:2) pop <- pop/sum(pop) meta <- metacommunity(pop) # Calculate normalised metacommunity alpha diversity norm_meta_alpha(meta, 0:2)
Calculates similarity-sensitive normalised metacommunity beta diversity
(the effective number of distinct subcommunities. This measure may be
calculated for a series of orders, represented as a vector of qs
.
norm_meta_beta(meta, qs)
norm_meta_beta(meta, qs)
meta |
object of class |
qs |
|
norm_meta_beta
returns a standard output of class rdiv
R. Reeve, T. Leinster, C. Cobbold, J. Thompson, N. Brummitt, S. Mitchell, and L. Matthews. 2016. How to partition diversity. arXiv 1404.6520v3:1–9.
pop <- data.frame(a = c(1,3), b = c(1,1)) row.names(pop) <- paste0("sp", 1:2) pop <- pop/sum(pop) meta <- metacommunity(pop) # Calculate normalised metacommunity beta diversity norm_meta_beta(meta, 0:2)
pop <- data.frame(a = c(1,3), b = c(1,1)) row.names(pop) <- paste0("sp", 1:2) pop <- pop/sum(pop) meta <- metacommunity(pop) # Calculate normalised metacommunity beta diversity norm_meta_beta(meta, 0:2)
Calculates similarity-sensitive normalised metacommunity rho diversity (the
average representativeness of subcommunities. This measure may be
calculated for a series of orders, represented as a vector of qs
.
norm_meta_rho(meta, qs)
norm_meta_rho(meta, qs)
meta |
object of class |
qs |
|
norm_meta_rho
returns a standard output of class rdiv
R. Reeve, T. Leinster, C. Cobbold, J. Thompson, N. Brummitt, S. Mitchell, and L. Matthews. 2016. How to partition diversity. arXiv 1404.6520v3:1–9.
pop <- data.frame(a = c(1,3), b = c(1,1)) row.names(pop) <- paste0("sp", 1:2) pop <- pop/sum(pop) meta <- metacommunity(pop) # Calculate normalised metacommunity rho diversity norm_meta_rho(meta, 0:2)
pop <- data.frame(a = c(1,3), b = c(1,1)) row.names(pop) <- paste0("sp", 1:2) pop <- pop/sum(pop) meta <- metacommunity(pop) # Calculate normalised metacommunity rho diversity norm_meta_rho(meta, 0:2)
Calculates the low-level diversity component necessary for calculating normalised rho diversity.
norm_rho(meta)
norm_rho(meta)
meta |
object of class |
Values generated from norm_rho()
may be input into subdiv()
and
metadiv()
to calculate normalised subcommunity and metacommunity rho
diversity.
norm_rho
returns an object of class powermean
R. Reeve, T. Leinster, C. Cobbold, J. Thompson, N. Brummitt, S. Mitchell, and L. Matthews. 2016. How to partition diversity. arXiv 1404.6520v3:1–9.
pop <- data.frame(a = c(1,3), b = c(1,1)) row.names(pop) <- paste0("sp", 1:2) pop <- pop/sum(pop) meta <- metacommunity(pop) # Calculate normalised rho component r <- norm_rho(meta) subdiv(r, 1) metadiv(r, 1)
pop <- data.frame(a = c(1,3), b = c(1,1)) row.names(pop) <- paste0("sp", 1:2) pop <- pop/sum(pop) meta <- metacommunity(pop) # Calculate normalised rho component r <- norm_rho(meta) subdiv(r, 1) metadiv(r, 1)
Calculates similarity-sensitive normalised subcommunity alpha diversity
(the diversity of subcommunity j in isolation. This measure may be
calculated for a series of orders, represented as a vector of qs
.
norm_sub_alpha(meta, qs)
norm_sub_alpha(meta, qs)
meta |
object of class |
qs |
|
norm_sub_alpha
returns a standard output of class rdiv
R. Reeve, T. Leinster, C. Cobbold, J. Thompson, N. Brummitt, S. Mitchell, and L. Matthews. 2016. How to partition diversity. arXiv 1404.6520v3:1–9.
pop <- data.frame(a = c(1,3), b = c(1,1)) row.names(pop) <- paste0("sp", 1:2) pop <- pop/sum(pop) meta <- metacommunity(pop) # Calculate normalised subcommunity alpha diversity norm_sub_alpha(meta, 0:2)
pop <- data.frame(a = c(1,3), b = c(1,1)) row.names(pop) <- paste0("sp", 1:2) pop <- pop/sum(pop) meta <- metacommunity(pop) # Calculate normalised subcommunity alpha diversity norm_sub_alpha(meta, 0:2)
Calculates similarity-sensitive normalised subcommunity beta diversity (an
estimate of the effective number of distinct subcommunities). This
measure may be calculated for a series of orders, represented as a vector
of qs
.
norm_sub_beta(meta, qs)
norm_sub_beta(meta, qs)
meta |
object of class |
qs |
|
norm_sub_beta
returns a standard output of class rdiv
R. Reeve, T. Leinster, C. Cobbold, J. Thompson, N. Brummitt, S. Mitchell, and L. Matthews. 2016. How to partition diversity. arXiv 1404.6520v3:1–9.
pop <- data.frame(a = c(1,3), b = c(1,1)) row.names(pop) <- paste0("sp", 1:2) pop <- pop/sum(pop) meta <- metacommunity(pop) # Calculate normalised subcommunity beta diversity norm_sub_beta(meta, 0:2)
pop <- data.frame(a = c(1,3), b = c(1,1)) row.names(pop) <- paste0("sp", 1:2) pop <- pop/sum(pop) meta <- metacommunity(pop) # Calculate normalised subcommunity beta diversity norm_sub_beta(meta, 0:2)
Calculates similarity-sensitive normalised subcommunity rho diversity (the
representativeness of subcommunity j). This measure may be calculated
for a series of orders, represented as a vector of qs
.
norm_sub_rho(meta, qs)
norm_sub_rho(meta, qs)
meta |
object of class |
qs |
|
norm_sub_rho
returns a standard output of class rdiv
R. Reeve, T. Leinster, C. Cobbold, J. Thompson, N. Brummitt, S. Mitchell, and L. Matthews. 2016. How to partition diversity. arXiv 1404.6520v3:1–9.
pop <- data.frame(a = c(1,3), b = c(1,1)) row.names(pop) <- paste0("sp", 1:2) pop <- pop/sum(pop) meta <- metacommunity(pop) # Calculate normalised subcommunity rho diversity norm_sub_rho(meta, 0:2)
pop <- data.frame(a = c(1,3), b = c(1,1)) row.names(pop) <- paste0("sp", 1:2) pop <- pop/sum(pop) meta <- metacommunity(pop) # Calculate normalised subcommunity rho diversity norm_sub_rho(meta, 0:2)
Group generic Ops operators
## S3 method for class 'binary' Ops(e1, e2)
## S3 method for class 'binary' Ops(e1, e2)
e1 |
e1 |
e2 |
e2 |
Calculates the relative abundance of historical species.
phy_abundance(partition, structure_matrix)
phy_abundance(partition, structure_matrix)
partition |
two-dimensional |
structure_matrix |
|
Converts an object into class phylo
into class phy_struct
.
phy_struct(tree, partition)
phy_struct(tree, partition)
tree |
object of class |
partition |
two-dimensional |
phy_struct()
returns a list
containing:
$structure |
- each row denotes historical species, columns denote terminal taxa, and elements contain 'branch lengths' |
$tbar - the average distance from root to tip for all terminal
taxa |
|
$parameters |
- information associated with each historical species |
$tree |
- object of class phylo |
Packages all inputs into an object of class similarity
.
phy2branch(tree, partition, depth = 1)
phy2branch(tree, partition, depth = 1)
tree |
object of class |
partition |
two-dimensional |
depth |
proportion of total tree height to be conserved (taken as a proportion from the highest tip). Describes how much evolutionary history should be retained, with 0 marking the date of the most recent tip, and 1 (the default) marking the most recent common ancestor. Numbers greater than 1 extend the root of the tree. |
phy2branch()
returns an object of class similarity
.
Converts any phylo
object to a matrix of pairwise tip-to-tip distances.
phy2dist(tree, precompute_dist = TRUE)
phy2dist(tree, precompute_dist = TRUE)
tree |
object of class |
precompute_dist |
object of class |
phy2sim(x)
returns an object of class distance
containing a matrix
of pairwise tip-to-tip distances.
power_mean()
calculates the power mean of a set of values.
power_mean(values, order = 1, weights = rep(1, length(values)))
power_mean(values, order = 1, weights = rep(1, length(values)))
values |
Values for which to calculate mean. |
order |
Order of power mean. |
weights |
Weights of elements, normalised to 1 inside function. |
Calculates the order-th power mean of a single set of non-negative values, weighted by weights; by default, weights are equal and order is 1, so this is just the arithmetic mean. Equal weights and a order of 0 gives the geometric mean, and an order of -1 gives the harmonic mean.
Weighted power mean
values <- sample(1:50, 5) power_mean(values)
values <- sample(1:50, 5) power_mean(values)
Container for class powermean
.
results
data.frame
containing rdiversity output
measure
object of class character
naming the diversity
measure being calculated
type_abundance
two-dimensional matrix
of mode numeric
with rows as types (species), columns as subcommunities, and each
element containing the relative abundance of types in each subcommunity
relative to the metacommunity as a whole. In the phylogenetic case, this
corresponds to the proportional abundance of historical species, which is
calculated from the proportional abundance of terminal taxa
ordinariness
two-dimensional matrix
of mode numeric
with rows as types, columns as subcommunities, and elements containing the
ordinariness of types within subcommunities
subcommunity_weights
vector
of mode numeric
containing
subcommunity weights
type_weights
two-dimensional matrix
of mode numeric
,
with rows as types, columns as subcommunities, and elements containing
weights of types within a subcommunity
dat_id
object of class character
describing the class of
distance / similarity being used, e.g. "naive", "taxonomic", and so on
similarity_components
list containing the components necessary to
calculate similarity. This list is empty when precompute_dist = TRUE
when calculating distance. When a pairwise distance matrix is too large and
precompute_dist = FALSE
, this list contains all the information
required to calculate pairwise distance between types
similarity_parameters
list containing parameters associated with
converting pairwise distances to similarities (the dist2sim()
arguments)
This method prints the binary number.
## S3 method for class 'binary' print(x, ...)
## S3 method for class 'binary' print(x, ...)
x |
any binary number. |
... |
further arguments. |
Output in ones and zeros (binary vector).
summary.binary provides some additional information.
Calculates the low-level diversity component necessary for calculating alpha diversity.
raw_alpha(meta)
raw_alpha(meta)
meta |
object of class |
Values generated from raw_alpha()
may be input into subdiv()
and
metadiv()
to calculate raw subcommunity and metacommunity alpha
diversity.
raw_alpha
returns an object of class powermean
R. Reeve, T. Leinster, C. Cobbold, J. Thompson, N. Brummitt, S. Mitchell, and L. Matthews. 2016. How to partition diversity. arXiv 1404.6520v3:1–9.
pop <- data.frame(a = c(1,3), b = c(1,1)) row.names(pop) <- paste0("sp", 1:2) pop <- pop/sum(pop) meta <- metacommunity(pop) # Calculate raw alpha component a <- raw_alpha(meta) subdiv(a, 1) metadiv(a, 1)
pop <- data.frame(a = c(1,3), b = c(1,1)) row.names(pop) <- paste0("sp", 1:2) pop <- pop/sum(pop) meta <- metacommunity(pop) # Calculate raw alpha component a <- raw_alpha(meta) subdiv(a, 1) metadiv(a, 1)
Calculates the low-level diversity component necessary for calculating raw beta diversity.
raw_beta(meta)
raw_beta(meta)
meta |
object of class |
Values generated from raw_beta()
may be input into subdiv()
and
metadiv()
to calculate raw subcommunity and metacommunity beta
diversity.
raw_beta
returns an object of class relativeentropy
R. Reeve, T. Leinster, C. Cobbold, J. Thompson, N. Brummitt, S. Mitchell, and L. Matthews. 2016. How to partition diversity. arXiv 1404.6520v3:1–9.
pop <- data.frame(a = c(1,3), b = c(1,1)) row.names(pop) <- paste0("sp", 1:2) pop <- pop/sum(pop) meta <- metacommunity(pop) # Calculate raw beta component b <- raw_beta(meta) subdiv(b, 1) metadiv(b, 1)
pop <- data.frame(a = c(1,3), b = c(1,1)) row.names(pop) <- paste0("sp", 1:2) pop <- pop/sum(pop) meta <- metacommunity(pop) # Calculate raw beta component b <- raw_beta(meta) subdiv(b, 1) metadiv(b, 1)
Calculates the low-level diversity component necessary for calculating gamma diversity.
raw_gamma(meta)
raw_gamma(meta)
meta |
object of class |
Values generated from raw_gamma()
may be input into subdiv()
and
metadiv()
to calculate subcommunity and metacommunity gamma diversity.
raw_gamma
returns an object of class powermean
R. Reeve, T. Leinster, C. Cobbold, J. Thompson, N. Brummitt, S. Mitchell, and L. Matthews. 2016. How to partition diversity. arXiv 1404.6520v3:1–9.
pop <- cbind.data.frame(A = c(1,1), B = c(2,0), C = c(3,1)) row.names(pop) <- paste0("sp", 1:2) pop <- pop/sum(pop) meta <- metacommunity(pop) # Calculate gamma component g <- raw_gamma(meta) subdiv(g, 1) metadiv(g, 1)
pop <- cbind.data.frame(A = c(1,1), B = c(2,0), C = c(3,1)) row.names(pop) <- paste0("sp", 1:2) pop <- pop/sum(pop) meta <- metacommunity(pop) # Calculate gamma component g <- raw_gamma(meta) subdiv(g, 1) metadiv(g, 1)
Calculates similarity-sensitive raw metacommunity alpha diversity (the
naive-community metacommunity diversity). This measure may be calculated
for a series of orders, represented as a vector of qs
.
raw_meta_alpha(meta, qs)
raw_meta_alpha(meta, qs)
meta |
object of class |
qs |
|
raw_meta_alpha
returns a standard output of class rdiv
R. Reeve, T. Leinster, C. Cobbold, J. Thompson, N. Brummitt, S. Mitchell, and L. Matthews. 2016. How to partition diversity. arXiv 1404.6520v3:1–9.
pop <- data.frame(a = c(1,3), b = c(1,1)) row.names(pop) <- paste0("sp", 1:2) pop <- pop/sum(pop) meta <- metacommunity(pop) # Calculate raw metacommunity alpha diversity raw_meta_alpha(meta, 0:2)
pop <- data.frame(a = c(1,3), b = c(1,1)) row.names(pop) <- paste0("sp", 1:2) pop <- pop/sum(pop) meta <- metacommunity(pop) # Calculate raw metacommunity alpha diversity raw_meta_alpha(meta, 0:2)
Calculates similarity-sensitive raw metacommunity beta diversity (the
average distinctiveness of subcommunities). This measure may be
calculated for a series of orders, represented as a vector of qs
.
raw_meta_beta(meta, qs)
raw_meta_beta(meta, qs)
meta |
object of class |
qs |
|
raw_meta_beta
returns a standard output of class rdiv
R. Reeve, T. Leinster, C. Cobbold, J. Thompson, N. Brummitt, S. Mitchell, and L. Matthews. 2016. How to partition diversity. arXiv 1404.6520v3:1–9.
pop <- data.frame(a = c(1,3), b = c(1,1)) row.names(pop) <- paste0("sp", 1:2) pop <- pop/sum(pop) meta <- metacommunity(pop) # Calculate raw metacommunity beta diversity raw_meta_beta(meta, 0:2)
pop <- data.frame(a = c(1,3), b = c(1,1)) row.names(pop) <- paste0("sp", 1:2) pop <- pop/sum(pop) meta <- metacommunity(pop) # Calculate raw metacommunity beta diversity raw_meta_beta(meta, 0:2)
Calculates similarity-sensitive raw metacommunity rho diversity (the
average redundancy of subcommunities. This measure may be calculated
for a series of orders, represented as a vector of qs
.
raw_meta_rho(meta, qs)
raw_meta_rho(meta, qs)
meta |
object of class |
qs |
|
raw_meta_rho
returns a standard output of class rdiv
R. Reeve, T. Leinster, C. Cobbold, J. Thompson, N. Brummitt, S. Mitchell, and L. Matthews. 2016. How to partition diversity. arXiv 1404.6520v3:1–9.
pop <- data.frame(a = c(1,3), b = c(1,1)) row.names(pop) <- paste0("sp", 1:2) pop <- pop/sum(pop) meta <- metacommunity(pop) # Calculate metacommunity rho diversity raw_meta_rho(meta, 0:2)
pop <- data.frame(a = c(1,3), b = c(1,1)) row.names(pop) <- paste0("sp", 1:2) pop <- pop/sum(pop) meta <- metacommunity(pop) # Calculate metacommunity rho diversity raw_meta_rho(meta, 0:2)
Calculates the low-level diversity component necessary for calculating raw rho diversity.
raw_rho(meta)
raw_rho(meta)
meta |
object of class |
Values generated from raw_rho()
may be input into subdiv()
and
metadiv()
to calculate raw subcommunity and metacommunity rho
diversity.
raw_rho
returns an object of class powermean
R. Reeve, T. Leinster, C. Cobbold, J. Thompson, N. Brummitt, S. Mitchell, and L. Matthews. 2016. How to partition diversity. arXiv 1404.6520v3:1–9.
pop <- data.frame(a = c(1,3), b = c(1,1)) row.names(pop) <- paste0("sp", 1:2) pop <- pop/sum(pop) meta <- metacommunity(pop) # Calculate raw rho component r <- raw_rho(meta) subdiv(r, 1) metadiv(r, 1)
pop <- data.frame(a = c(1,3), b = c(1,1)) row.names(pop) <- paste0("sp", 1:2) pop <- pop/sum(pop) meta <- metacommunity(pop) # Calculate raw rho component r <- raw_rho(meta) subdiv(r, 1) metadiv(r, 1)
Calculates similarity sensitive raw subcommunity alpha diversity (an
estimate of naive-community metacommunity diversity). This measure may be
calculated for a series of orders, represented as a vector of qs
.
raw_sub_alpha(meta, qs)
raw_sub_alpha(meta, qs)
meta |
object of class |
qs |
|
raw_sub_alpha
returns a standard output of class rdiv
R. Reeve, T. Leinster, C. Cobbold, J. Thompson, N. Brummitt, S. Mitchell, and L. Matthews. 2016. How to partition diversity. arXiv 1404.6520v3:1–9.
pop <- data.frame(a = c(1,3), b = c(1,1)) row.names(pop) <- paste0("sp", 1:2) pop <- pop/sum(pop) meta <- metacommunity(pop) # Calculate raw subcommunity alpha diversity raw_sub_alpha(meta, 0:2)
pop <- data.frame(a = c(1,3), b = c(1,1)) row.names(pop) <- paste0("sp", 1:2) pop <- pop/sum(pop) meta <- metacommunity(pop) # Calculate raw subcommunity alpha diversity raw_sub_alpha(meta, 0:2)
Calculates similarity-sensitive raw subcommunity beta diversity (the
distinctiveness of subcommunity j). This measure may be calculated
for a series of orders, represented as a vector of qs
.
raw_sub_beta(meta, qs)
raw_sub_beta(meta, qs)
meta |
object of class |
qs |
|
raw_sub_beta
returns a standard output of class rdiv
R. Reeve, T. Leinster, C. Cobbold, J. Thompson, N. Brummitt, S. Mitchell, and L. Matthews. 2016. How to partition diversity. arXiv 1404.6520v3:1–9.
pop <- data.frame(a = c(1,3), b = c(1,1)) row.names(pop) <- paste0("sp", 1:2) pop <- pop/sum(pop) meta <- metacommunity(pop) # Calculate raw subcommunity beta diversity raw_sub_beta(meta, 0:2)
pop <- data.frame(a = c(1,3), b = c(1,1)) row.names(pop) <- paste0("sp", 1:2) pop <- pop/sum(pop) meta <- metacommunity(pop) # Calculate raw subcommunity beta diversity raw_sub_beta(meta, 0:2)
Calculates similarity-sensitive raw subcommunity rho diversity (the
redundancy of subcommunity j. This measure may be calculated for
a series of orders, represented as a vector of qs
.
raw_sub_rho(meta, qs)
raw_sub_rho(meta, qs)
meta |
object of class |
qs |
|
raw_sub_rho
returns a standard output of class rdiv
R. Reeve, T. Leinster, C. Cobbold, J. Thompson, N. Brummitt, S. Mitchell, and L. Matthews. 2016. How to partition diversity. arXiv 1404.6520v3:1–9.
pop <- data.frame(a = c(1,3), b = c(1,1)) row.names(pop) <- paste0("sp", 1:2) pop <- pop/sum(pop) meta <- metacommunity(pop) # Calculate raw subcommunity rho diversity raw_sub_rho(meta, 0:2)
pop <- data.frame(a = c(1,3), b = c(1,1)) row.names(pop) <- paste0("sp", 1:2) pop <- pop/sum(pop) meta <- metacommunity(pop) # Calculate raw subcommunity rho diversity raw_sub_rho(meta, 0:2)
Container for class relativeentropy
.
results
data.frame
containing rdiversity output
measure
object of class character
naming the diversity
measure being calculated
type_abundance
two-dimensional matrix
of mode numeric
with rows as types (species), columns as subcommunities, and each
element containing the relative abundance of types in each subcommunity
relative to the metacommunity as a whole. In the phylogenetic case, this
corresponds to the proportional abundance of historical species, which is
calculated from the proportional abundance of terminal taxa
ordinariness
two-dimensional matrix
of mode numeric
with rows as types, columns as subcommunities, and elements containing the
ordinariness of types within subcommunities
subcommunity_weights
vector
of mode numeric
containing
subcommunity weights
type_weights
two-dimensional matrix
of mode numeric
,
with rows as types, columns as subcommunities, and elements containing
weights of types within a subcommunity
dat_id
object of class character
describing the class of
distance / similarity being used, e.g. "naive", "taxonomic", and so on
similarity_components
list containing the components necessary to
calculate similarity. This list is empty when precompute_dist = TRUE
when calculating distance. When a pairwise distance matrix is too large and
precompute_dist = FALSE
, this list contains all the information
required to calculate pairwise distance between types
similarity_parameters
list containing parameters associated with
converting pairwise distances to similarities (the dist2sim()
arguments)
Randomly reshuffles the relative abundance of types (e.g. species) in a metacommunity (whilst maintaining the relationship between the relative abundance of a particular species across subcommunities). In the case of a phylogenetic metacommunity, the relative abundance of terminal taxa are randomly reshuffled and the relative abundance of types (historical species) are calculated from the resulting partition.
repartition(meta, new_partition)
repartition(meta, new_partition)
meta |
object of class |
new_partition |
two-dimensional |
repartition()
returns an object of class metacommunity
Helper function save Attributes
saveAttributes(x)
saveAttributes(x)
x |
x |
Container for class similarity
.
similarity(similarity, dat_id) ## S4 method for signature 'matrix,character' similarity(similarity, dat_id) ## S4 method for signature 'matrix,missing' similarity(similarity, dat_id)
similarity(similarity, dat_id) ## S4 method for signature 'matrix,character' similarity(similarity, dat_id) ## S4 method for signature 'matrix,missing' similarity(similarity, dat_id)
similarity |
similarity matrix |
dat_id |
object of class |
similarity()
returns an object of class similarity
.
Container for class similarity
.
## S4 method for signature 'similarity' show(object)
## S4 method for signature 'similarity' show(object)
object |
object of class |
similarity
two-dimensional matrix
of mode numeric
with rows as types, columns as types, and elements containing the pairwise
similarity of types
dat_id
object of class character
describing the class of
distance / similarity being used, e.g. "naive", "taxonomic", and so on
components
list containing the components necessary to calculate
similarity. This list is empty when precompute_dist = TRUE
when
calculating distance. When a pairwise distance matrix is too large and
precompute_dist = FALSE
, this list contains all the information
required to calculate pairwise distance between types
parameters
list containing parameters associated with
converting pairwise distances to similarities (the dist2sim()
arguments)
Calculates similarity-sensitive subcommunity gamma diversity (the
contribution per individual toward metacommunity diversity). This
measure may be calculated for a series of orders, represented as a vector
of qs
.
sub_gamma(meta, qs)
sub_gamma(meta, qs)
meta |
object of class |
qs |
|
sub_gamma
returns a standard output of class rdiv
R. Reeve, T. Leinster, C. Cobbold, J. Thompson, N. Brummitt, S. Mitchell, and L. Matthews. 2016. How to partition diversity. arXiv 1404.6520v3:1–9.
pop <- data.frame(a = c(1,3), b = c(1,1)) row.names(pop) <- paste0("sp", 1:2) pop <- pop/sum(pop) meta <- metacommunity(pop) # Calculate subcommunity gamma diversity sub_gamma(meta, 0:2)
pop <- data.frame(a = c(1,3), b = c(1,1)) row.names(pop) <- paste0("sp", 1:2) pop <- pop/sum(pop) meta <- metacommunity(pop) # Calculate subcommunity gamma diversity sub_gamma(meta, 0:2)
Generic function for calculating subcommunity-level diversity.
subdiv(data, qs) ## S4 method for signature 'powermean' subdiv(data, qs) ## S4 method for signature 'relativeentropy' subdiv(data, qs) ## S4 method for signature 'metacommunity' subdiv(data, qs)
subdiv(data, qs) ## S4 method for signature 'powermean' subdiv(data, qs) ## S4 method for signature 'relativeentropy' subdiv(data, qs) ## S4 method for signature 'metacommunity' subdiv(data, qs)
data |
|
qs |
|
data
may be input as one of three different classes:
powermean
: raw or normalised metacommunity alpha, rho or gamma
diversity components; will calculate subcommunity-level raw or normalised
metacommunity alpha, rho or gamma diversity
relativeentropy
: raw or normalised metacommunity beta
diversity components; will calculate subcommunity-level raw or normalised
metacommunity beta diversity
metacommunity
: will calculate all subcommunity measures of
diversity
subdiv()
returns a standard output of class rdiv
Reeve, R., T. Leinster, C. Cobbold, J. Thompson, N. Brummitt, S. Mitchell, and L. Matthews. 2016. How to partition diversity. arXiv 1404.6520v3:1–9.
inddiv
for type-level diversity and
metadiv
for metacommunity-level diversity.
# Define metacommunity pop <- data.frame(a = c(1,3), b = c(1,1)) row.names(pop) <- paste0("sp", 1:2) pop <- pop/sum(pop) meta <- metacommunity(pop) # Calculate subcommunity gamma diversity (takes the power mean) g <- raw_gamma(meta) subdiv(g, 0:2) # Calculate subcommunity beta diversity (takes the relative entropy) b <- raw_beta(meta) subdiv(b, 0:2) # Calculate all measures of subcommunity diversity subdiv(meta, 0:2)
# Define metacommunity pop <- data.frame(a = c(1,3), b = c(1,1)) row.names(pop) <- paste0("sp", 1:2) pop <- pop/sum(pop) meta <- metacommunity(pop) # Calculate subcommunity gamma diversity (takes the power mean) g <- raw_gamma(meta) subdiv(g, 0:2) # Calculate subcommunity beta diversity (takes the relative entropy) b <- raw_beta(meta) subdiv(b, 0:2) # Calculate all measures of subcommunity diversity subdiv(meta, 0:2)
This method provides information about the attributes of the binary number.
## S3 method for class 'binary' summary(object, ...)
## S3 method for class 'binary' summary(object, ...)
object |
binary number. |
... |
further arguments. |
Contains the following information:
Signedness : unsigned or signed
Endianess : Big-Endian or Little-Endian
value<0 : negative or positve number
Size[bit] : Size in bit
Base10 : Decimal(Base10) number.
Switch little-endian to big-endian and vice versa.
switchEndianess(x, stickyBits=FALSE)
switchEndianess(x, stickyBits=FALSE)
x |
binary number. Any binary number. |
stickyBits |
Bits wont change if set TRUE. Only the attribute will be switched. |
switch little-endian to big-endian and vice versa.
x <- as.binary(c(1,1,0,0), logic=TRUE); print(x); summary(x); y <- rdiversity:::switchEndianess(x); print(y); summary(y); y <- rdiversity:::switchEndianess(x, stickyBits=TRUE); print(y); summary(y);
x <- as.binary(c(1,1,0,0), logic=TRUE); print(x); summary(x); y <- rdiversity:::switchEndianess(x); print(y); summary(y); y <- rdiversity:::switchEndianess(x, stickyBits=TRUE); print(y); summary(y);
Calculates taxonomic distances between species.
tax2dist(lookup, tax_distance, precompute_dist = TRUE)
tax2dist(lookup, tax_distance, precompute_dist = TRUE)
lookup |
|
tax_distance |
|
precompute_dist |
object of class |
tax2dist()
returns an object of class distance
containing a matrix
of pairwise taxonomic distances
Shimatani, K. 2001. On the measurement of species diversity incorporating species differences. Oikos 93:135–147.
# Create Lookup table Species <- c("tenuifolium", "asterolepis", "simplex var.grandiflora", "simplex var.ochnacea") Genus <- c("Protium", "Quararibea", "Swartzia", "Swartzia") Family <- c("Burseraceae", "Bombacaceae", "Fabaceae", "Fabaceae") Subclass <- c("Sapindales", "Malvales", "Fabales", "Fabales") lookup <- cbind.data.frame(Species, Genus, Family, Subclass) # Assign values for each level (Shimatani's taxonomic distance) tax_distance <- c(Species = 0, Genus = 1, Family = 2, Subclass = 3, Other = 4) # Generate pairwise distances distance <- tax2dist(lookup, tax_distance) similarity <- dist2sim(distance, "linear")
# Create Lookup table Species <- c("tenuifolium", "asterolepis", "simplex var.grandiflora", "simplex var.ochnacea") Genus <- c("Protium", "Quararibea", "Swartzia", "Swartzia") Family <- c("Burseraceae", "Bombacaceae", "Fabaceae", "Fabaceae") Subclass <- c("Sapindales", "Malvales", "Fabales", "Fabales") lookup <- cbind.data.frame(Species, Genus, Family, Subclass) # Assign values for each level (Shimatani's taxonomic distance) tax_distance <- c(Species = 0, Genus = 1, Family = 2, Subclass = 3, Other = 4) # Generate pairwise distances distance <- tax2dist(lookup, tax_distance) similarity <- dist2sim(distance, "linear")