Package 'Rarity'

Title: Calculation of Rarity Indices for Species and Assemblages of Species
Description: Allows calculation of rarity weights for species and indices of rarity for assemblages of species according to different methods (Leroy et al. 2012, Insect. Conserv. Divers. 5:159-168 <doi:10.1111/j.1752-4598.2011.00148.x>; Leroy et al. 2013, Divers. Distrib. 19:794-803 <doi:10.1111/ddi.12040>).
Authors: Boris Leroy
Maintainer: Boris Leroy <[email protected]>
License: GPL (>=2.0)
Version: 1.3-8
Built: 2024-11-22 05:21:58 UTC
Source: https://github.com/farewe/rarity

Help Index


A package to calculate rarity indices for species and assemblages of species for conservation studies

Description

This package allows calculation of rarity weights for species and indices of rarity for assemblages of species according to different methods (Leroy et al. 2012, In Press).

The methods developped in this package are based on occurrence (presence-absence) data. Species occurrence is transformed in rarity weights according to various methods. On the basis of the calculated rarity weights, the Index of Relative Rarity can be calculated for assemblages of species (see Leroy et al. 2012 and Leroy et al. in press)

Details

This package works with two important functions.

First, the function rWeights is designed to calculate rarity weights according to different weighting function. This package implements the flexible weighting function integrating the rarity cutoff point (Leroy et al. 2012, in press).

Second, the function Irr is designed to calculate the Index of Relative Rarity for assemblages of species. The Index of Relative Rarity is the average of rarity weights of species in an assemblage, normalized between 0 and 1 (Leroy et al. 2012, in press).

Author(s)

Boris Leroy

Maintainer: Boris Leroy <[email protected]>

References

Leroy B., Petillon J., Gallon R., Canard A., & Ysnel F. (2012) Improving occurrence-based rarity metrics in conservation studies by including multiple rarity cut-off points. Insect Conservation and Diversity, 5, 159-168.

Leroy B., Canard A., & Ysnel F. In Press. Integrating multiple scales in rarity assessments of invertebrate taxa. Diversity and Distributions, 19, 794-803.

Examples

# Example dataset: occurrences of spider species at two different scales
  data(spid.occ)
  head(spid.occ)
  
  # Calculation of rarity weights
  rarity.weights <- rWeights(occData = spid.occ, rCutoff = "Gaston")
  
  # Generation of a random assemblage matrix
  assemblages.matrix <- cbind(assemblage.1 = sample(c(0, 1), 50, replace = TRUE),
                              assemblage.2 = sample(c(0, 1), 50, replace = TRUE),
                              assemblage.3 = sample(c(0, 1), 50, replace = TRUE),
                              assemblage.4 = sample(c(0, 1), 50, replace = TRUE),
                              assemblage.5 = sample(c(0, 1), 50, replace = TRUE))
  # Random attribution of species names
  rownames(assemblages.matrix) <- sample(rownames(spid.occ), 50, replace = FALSE)
  head(assemblages.matrix)
  
  # Calculation of rarity indices of assemblages
  Irr(assemblages = assemblages.matrix, W = rarity.weights)

Correlation plots

Description

Produces a scatter plot with the distribution of points according to the tested variables in the lower left triangle and the correlation values in the upper left triangle.

Usage

corPlot(df, method = "spearman", digits = 2, na.action = "keep", ties.method = "average",
        title = "", xlab = "variable.name", ylab = "variable.name", ...)

Arguments

df

a matrix or a data.frame. The values of variables (e.g., indices) to be compared are in columns.

method

pearson, spearman or kendall. This is the method to be used to produce the plot, according to cor.test. See details.

digits

Number of digits to round the correlation values on the plot.

na.action

for controlling the treatment of NAs in spearman or kendall plots. If TRUE, missing values in the data are put last; if FALSE, they are put first; if NA, they are removed; if "keep" they are kept with rank NA. See rank.

ties.method

average, first, random, max, or min; a character string specifying how ties are treated in spearman or kendall plots. See rank for details.

title

Title of the plot.

xlab

a character string for labelling x axes. variable.name (default value) will produce automatic labelling according to column names of df. Otherwise, either a single string can be entered, or a vector of strings of length equal to the number of columns of df.

ylab

a character string for labelling y axes. variable.name (default value) will produce automatic labelling according to column names of df. Otherwise, either a single string can be entered, or a vector of strings of length equal to the number of columns of df.

...

Further arguments to be passed to the individual plots. See plot and par

Details

The lower half shows the scatter plots of values or ranks of variables. The upper half shows the corresponding correlation coefficients (significativity: 0 '***' 0.001 '**' 0.01 '*' 0.05 '-' 0.1 ' ' 1). The diagonal shows the considered variables and the number of individuals available for each.

If the chosen method is pearson, then the actual values of the variables will be plotted. If the chosen method is a rank-based method, spearman or kendall, then the ranks will be plotted.

Warning

A high number of variables will likely result in a slow generation of plots and a poor readability. Above 10 variables, the readability is greatly reduced.

Author(s)

Boris Leroy [email protected]

See Also

corrplot in package arm

Examples

# Comparisons of species occurrences estimated from 2 different scales
data(spid.occ)
corPlot(spid.occ, method = "pearson")

# Another example:
# Correlation between different variables measured on the same individuals
data(iris)
corPlot(iris[, 1:4], method = "pearson")
corPlot(iris[, 1:4], method = "spearman")

Index of Relative Rarity

Description

Calculates the Index of Relative Rarity for a single or a set of assemblages of species.

Usage

Irr(assemblages, W, abundance = F, Wmin = min(W), Wmax = max(W))

Arguments

assemblages

vector, matrix or data.frame. Data of the assemblage(s) of species for which the Index will be calculated. If matrix or data.frame, species are in rows and assemblages are in columns (see details).

W

vector, matrix or data.frame. Rarity weights of the species. If matrix or data.frame, species are in rows (see details).

abundance

logical. If TRUE, then abundance values in assemblages are taken into account to calculate the Index of Relative Rarity.

Wmin

decimal or vector. Minimum weight(s)

Wmax

decimal or vector. Maximum weight(s)

Details

assemblages can contain a single (vector) or several (matrix or data.frame) assemblages. If assemblages is a vector, values must be named with species names (e.g. with names(assemblages) <- sp.names). If assemblages is a matrix or a data.frame, then rows must be named with species names.

All the species of assemblages must be contained in W

W can contain a single vector of rarity weights, or a matrix or a data.frame of rarity weights (e.g. to calculate different Indices of Relative Rarity for different scales). If W is a vector, values must be named with species names. If W is a matrix or a data.frame, then species are in rows and each column contains rarity weights. Rows must be named with species names.

If the input of rWeights is directly entered, then columns Q (occurrence), R (rarity status) and cut.off (rarity cut-off points) will be dropped.

  • Occurrence-based Irr, normalised between 0 and 1:

    wiSwminwmaxwmin\frac{\frac{\sum w_i}{S} - w_{min}}{w_{max} - w_{min}}

    where wi is the weight of the ith species in the assemblage, S the assemblage species richness, wmin and wmax the minimum and maximum weights respectively.

  • Abundance-based Irr, normalised between 0 and 1:

    aiwiNwminwmaxwmin\frac{\frac{\sum a_i w_i}{N} - w_{min}}{w_{max} - w_{min}}

    where ai and wi are respectively the abundance and weight of the ith species in the assemblage, N the total number of individuals in the assemblage, and wmin and wmax the minimum and maximum weights respectively.

Species with NA weights are excluded when indices are computed (they are kept for richness).

Value

A data.frame containing the Indices of Relative Rarity and the species richness of the assemblage(s).

Warning

Column names of W with names like "Q", "R", "cut.off", "Q1" "Q2" "Q3" and so on, "R1", "R2" "R3" and so on, "cut.off1", "cut.off2", and so on will be ignored.

Author(s)

Boris Leroy [email protected]

References

Leroy B., Petillon J., Gallon R., Canard A., & Ysnel F. (2012) Improving occurrence-based rarity metrics in conservation studies by including multiple rarity cut-off points. Insect Conservation and Diversity, 5, 159-168.

Leroy B., Canard A., & Ysnel F. 2013. Integrating multiple scales in rarity assessments of invertebrate taxa. Diversity and Distributions, 19, 794-803.

See Also

rWeights, Isr

Examples

# Input rarity weights
data(spid.occ)

# Example of a single scale dataset
regional.occ <- spid.occ$occurMA
names(regional.occ) <- rownames(spid.occ)
head(regional.occ)

# Preparation of rarity weights
rarity.weights <- rWeights(regional.occ)

# Generation of an assemblage matrix
assemblages.matrix <- cbind(assemblage.1 = sample(c(0, 1), 50, replace = TRUE),
                            assemblage.2 = sample(c(0, 1), 50, replace = TRUE),
                            assemblage.3 = sample(c(0, 1), 50, replace = TRUE),
                            assemblage.4 = sample(c(0, 1), 50, replace = TRUE),
                            assemblage.5 = sample(c(0, 1), 50, replace = TRUE))
# Random attribution of names to the sampled species
rownames(assemblages.matrix) <- sample(names(regional.occ), 50, replace = FALSE)
head(assemblages.matrix)

# Calculation of Irr
Irr(assemblages.matrix, rarity.weights)


# Example of a multi scale dataset
rarity.weights <- rWeights(spid.occ, extended = TRUE)
head(rarity.weights)

# Generation of an assemblage matrix
assemblages.matrix <- cbind(assemblage.1 = sample(c(0, 1), 50, replace = TRUE),
                            assemblage.2 = sample(c(0, 1), 50, replace = TRUE),
                            assemblage.3 = sample(c(0, 1), 50, replace = TRUE),
                            assemblage.4 = sample(c(0, 1), 50, replace = TRUE),
                            assemblage.5 = sample(c(0, 1), 50, replace = TRUE))
rownames(assemblages.matrix) <- sample(names(regional.occ), 50, replace = FALSE)
head(assemblages.matrix)

# Calculation of Irr
Irr(assemblages.matrix, rarity.weights)

Index of Summed Rarity

Description

Calculates the Index of Relative Rarity for a single or a set of assemblages of species. The index of summed rarity consists in summing the rarity weights of species in the assemblage, with the possibility of normalising between 0 (the assemblage has only minimum-weight species) and 1 (value of the complete pool of species (see details)).

Usage

Isr(assemblages, W, abundance = FALSE, Wmin = min(W), normalise = FALSE)

Arguments

assemblages

vector, matrix or data.frame. Data of the assemblage(s) of species for which the Index will be calculated. If matrix or data.frame, species are in rows and assemblages are in columns (see details).

W

vector, matrix or data.frame. Rarity weights of the species. If matrix or data.frame, species are in rows (see details).

abundance

logical. If TRUE, then abundance values in assemblages are taken into account to calculate the Index of Relative Rarity.

Wmin

decimal or vector. Minimum weight(s)

normalise

logical. If TRUE, then the Isr will be rescaled between 0 and 1 (see formula in details). Cannot be used if abundance = TRUE.

Details

assemblages can contain a single (vector) or several (matrix or data.frame) assemblages. If assemblages is a vector, values must be named with species names (e.g. with names(assemblages) <- sp.names). If assemblages is a matrix or a data.frame, then rows must be named with species names.

All the species of assemblages must be contained in W

W can contain a single vector of rarity weights, or a matrix or a data.frame of rarity weights (e.g. to calculate different Indices of Summed Rarity for different scales). If W is a vector, values must be named with species names. If W is a matrix or a data.frame, then species are in rows and each column contains rarity weights. Rows must be named with species names.

If the input of rWeights is directly entered, then columns Q (occurrence), R (rarity status) and cut.off (rarity cut-off points) will be dropped.

Formula implemented in this function:

  • Occurrence-based Isr, not normalised between 0 and 1:

    wi\sum w_i

    where wi is the weight of the ith species in the assemblage

  • Abundance-based Isr, not normalised between 0 and 1:

    ai×wi\sum a_i \times w_i

    where ai and wi are respectively the abundance and weight of the ith species in the assemblage

  • Occurrence-based Isr, normalised between 0 and 1:

    (wiwmin)(Wjwmin)\frac{\sum(w_i - w_{min})}{\sum(W_j - w_{min})}

    where wi is the weight of the ith species in the assemblage, wmin the minimum weight and Wj the weight of the jth species in the total species pool (provided in W).

Species with NA weights are excluded when indices are computed (they are kept for richness).

Value

A data.frame containing the Indices of Relative Rarity and the species richness of the assemblage(s).

Warning

Column names of W with names like "Q", "R", "cut.off", "Q1" "Q2" "Q3" and so on, "R1", "R2" "R3" and so on, "cut.off1", "cut.off2", and so on will be ignored.

Author(s)

Boris Leroy [email protected]

References

Leroy B., Petillon J., Gallon R., Canard A., & Ysnel F. (2012) Improving occurrence-based rarity metrics in conservation studies by including multiple rarity cut-off points. Insect Conservation and Diversity, 5, 159-168.

Leroy B., Canard A., & Ysnel F. 2013. Integrating multiple scales in rarity assessments of invertebrate taxa. Diversity and Distributions, 19, 794-803.

See Also

rWeights, Irr

Examples

# Input rarity weights
data(spid.occ)

# Example of a single scale dataset
regional.occ <- spid.occ$occurMA
names(regional.occ) <- rownames(spid.occ)
head(regional.occ)

# Preparation of rarity weights
rarity.weights <- rWeights(regional.occ)

# Generation of an assemblage matrix
assemblages.matrix <- cbind(assemblage.1 = sample(c(0, 1), 50, replace = TRUE),
                            assemblage.2 = sample(c(0, 1), 50, replace = TRUE),
                            assemblage.3 = sample(c(0, 1), 50, replace = TRUE),
                            assemblage.4 = sample(c(0, 1), 50, replace = TRUE),
                            assemblage.5 = sample(c(0, 1), 50, replace = TRUE))
# Random attribution of names to the sampled species
rownames(assemblages.matrix) <- sample(names(regional.occ), 50, replace = FALSE)
head(assemblages.matrix)

# Calculation of Isr
Isr(assemblages.matrix, rarity.weights)
Isr(assemblages.matrix, rarity.weights, normalise = TRUE)


# Example of a multi scale dataset
rarity.weights <- rWeights(spid.occ, extended = TRUE)
head(rarity.weights)

# Generation of an assemblage matrix
assemblages.matrix <- cbind(assemblage.1 = sample(c(0, 1), 50, replace = TRUE),
                            assemblage.2 = sample(c(0, 1), 50, replace = TRUE),
                            assemblage.3 = sample(c(0, 1), 50, replace = TRUE),
                            assemblage.4 = sample(c(0, 1), 50, replace = TRUE),
                            assemblage.5 = sample(c(0, 1), 50, replace = TRUE))
rownames(assemblages.matrix) <- sample(names(regional.occ), 50, replace = FALSE)
head(assemblages.matrix)

# Calculation of Isr
Isr(assemblages.matrix, rarity.weights)
Isr(assemblages.matrix, rarity.weights, normalise = TRUE)

Calculation of rarity weights at a single or at multiple scales

Description

Calculate rarity weights for a single scale or for multiple scales on the basis of the selected weighting function(s).

Usage

rWeights(occData, Qmax = max(occData), Qmin = min(occData), 
         wMethods = "W", rCutoff = "Gaston", normalised = T, 
         assemblages, extended = F, rounding = 3)

Arguments

occData

vector, matrix or data.frame. Occurrence data for a single scale (vector) or several scales (matrix or data.frame).

Qmax

integer. Maximum occurrence (see details). By default, the maximum occurrence of the dataset is used (i.e., maximum occurrence among the provided set of species), however it can be changed to another value, e.g. to provide the number of possible sites.

Qmin

integer. Minimum occurrence (see details). By default, the minimum occurrence of the dataset is used (i.e., minimum occurrence among the provided set of species).

wMethods

W, invQ or oldW. Chosen function to weight species occurrence (see details)

rCutoff

a decimal or a vector of values between 0 and 1, or Gaston or Leroy. Indicates the rarity cutoff(s) or the method to use to calculate the rarity cutoff(s). The rarity cut-off is by default calculated as a percentage of the maximum occurrence (see details)

normalised

TRUE or FALSE. If TRUE, then weights are normalised between 0 and 1.

assemblages

matrix or data.frame. Set of assemblages of species to calculate the rarity cutoff point(s) with the Leroy method (optional)

extended

TRUE or FALSE. Useful in case of multiple scales only. If TRUE, then weights will be given for every input scale in addition to multiscale weights. If FALSE, then only multiscale weights will be provided.

rounding

An integer or FALSE. If an integer is provided, then the values of weights will be rounded according to this value. If FALSE, weights will not be rounded.

Details

To calculate single-scale weights, simply provide a vector with species occurrences. To calculate multiscale rarity weights, provide either a matrix or a data.frame where species are in rows, and each column provides occurrence for a particular scale.

The minimum and maximum weights can be set manually, or automatically calculated with the default parameters. Defaults parameters : if occData is a vector, Qmin = min(Q) and Qmax = max(Q). If occData is a matrix or a data.frame, Qmin = apply(occData, 2, min) and Qmax = apply(occData, 2, max)

Three weighting methods are available (more will become available later):

  1. W: This is the method described in Leroy et al. (2013). We recommend using this method for both single and multiscale weight calculations.

    exp((QiQminrj×QmaxQmin×0.97+1.05)2)\exp(-(\frac{Q_{i} - Q_{min}}{r_j \times Q_{max} - Q_{min}}\times0.97 + 1.05)^2)

    where Qi is the occurrence of species i, Qmin and Qmax are respectively the minimum and maximum occurrences in the species pool and r is the choosen rarity cut-off point (as a percentage of occurrence).

  2. invQ: This is the inverse of occurrence

    1Qi\frac{1}{Q_i}

    where Qi is the occurrence of the ith species. The inverse of the occurrence should be avoided as a weighting procedure because it cannot be adjusted to the considered species pool, and it does not attribute 0 weights to common species (see discussion in Leroy et al. (2012)).

  3. oldW: This is the original method described in Leroy et al. (2012). As this method was improved in Leroy et al. (2013), we recommend to rather use W. Formula:

    exp((QiQminn+1)2)\exp(-(\frac{Q_i}{Q_{min}} n + 1)^2)

    where Qi is the occurrence of species i, Qmin is the minimum occurrence in the species pool, and n is and adjustment coefficient numerically approximated to fit the choosen rarity cut-off point.

For methods W and oldW, a rarity cutoff point is required. The rarity cutoff point can either be entered manually (a single value for a single scale, a vector of values for multiple scales), or the methods of Gaston or Leroy can be used (see references):

- Gaston method: the rarity cutoff point is the first quartile of species occurrences, i.e. rare species are the 25 percent species with the lowest occurrence.

- Leroy method: the rarity cutoff point is the occurrence at which the average proportion of rare species in local assemblages is 25 percent. This method requires assemblages to calculate the average proportion of rare species in assemblages.

NA are properly handled by the function.

Value

A data.frame containing the results : species occurrences, rarity statuses, rarity weights and the used rarity cut-offs.

- If occData is a vector (single scale weights): A data.frame with 4 columns : Q (species occurrence), R (species rarity status), W, (species rarity weights), cut.off (rarity cut-off used for weight calculation)

- If occData is matrix or a data.frame (multiscale rarity weights): A data.frame with n columns Q (species occurrences), n columns R (species rarity statuses), one (if extended = F) or n + 1 (if extended = T) columns W (species rarity weights) where n is the number of scales (number of columns of occData), n columns cut.off (rarity cut-offs used for weight calculation).

By default, weights are rounded to 3 digits, which should be sufficient in most cases. Another number of digits can also be chosen; or simply changing rounding to FALSE will remove the rounding.

Author(s)

Boris Leroy [email protected]

References

Leroy B., Petillon J., Gallon R., Canard A., & Ysnel F. (2012) Improving occurrence-based rarity metrics in conservation studies by including multiple rarity cut-off points. Insect Conservation and Diversity, 5, 159-168.

Leroy B., Canard A., & Ysnel F. 2013. Integrating multiple scales in rarity assessments of invertebrate taxa. Diversity and Distributions, 19, 794-803.

See Also

Irr, Isr

Examples

# 1. Single scale rarity weights
data(spid.occ)
head(spid.occ)

regional.occ <- spid.occ$occurMA
names(regional.occ) <- rownames(spid.occ)
head(regional.occ)

# Calculation of rarity weights at a single scale:
rWeights(regional.occ, rCutoff = "Gaston")
rWeights(regional.occ, rCutoff = 0.1)
rWeights(regional.occ, wMethods = "invQ")
rWeights(regional.occ, wMethods = c("W", "invQ"))

# Calculation of rarity weights with the method of Leroy
# Creating a fictive assemblage matrix of 5 assemblages
# Warning: this is to provide an example of how the function works!
# The correct use of this method requires a matrix of actually sampled species.
assemblages.matrix <- cbind(assemblage.1 = sample(c(0, 1), 708, replace = TRUE),
                            assemblage.2 = sample(c(0, 1), 708, replace = TRUE),
                            assemblage.3 = sample(c(0, 1), 708, replace = TRUE),
                            assemblage.4 = sample(c(0, 1), 708, replace = TRUE),
                            assemblage.5 = sample(c(0, 1), 708, replace = TRUE))
rownames(assemblages.matrix) <- names(regional.occ) # Rownames of assemblages.matrix must 
                                                 # correspond to rownames in occurrences
head(assemblages.matrix)
                                          
rWeights(regional.occ, wMethods = "W", rCutoff = "Leroy", assemblages = assemblages.matrix)

# 2. Multiscale rarity weights
data(spid.occ)
head(spid.occ)

rWeights(spid.occ, wMethods = "W", rCutoff = "Gaston")
rWeights(spid.occ, wMethods = "W", rCutoff = "Gaston", extended = TRUE)
rWeights(spid.occ, wMethods = c("W", "invQ"), rCutoff = "Gaston", extended = TRUE)
rWeights(spid.occ, wMethods = c("W", "invQ"), rCutoff = "Leroy", 
         assemblages = assemblages.matrix, extended = TRUE) # Provided that you have 
                                             # created "assemblages.matrix" as above

Occurrences of spiders of Western France at two different scales.

Description

spid.occ is a data.frame providing the occurrences of the 708 spider species of Western France at 2 different scales.

Usage

data(spid.occ)

Format

A data frame with 708 rows (species) and 2 columns.

occurMA

a numeric vector. Occurrence of spider species at the regional scale (Western France).

occurWP

a numeric vector. Occurrence of spider species at the western Palearctic scale.

Details

The regional occurrence is obtained from our spider database of Western France. It was defined as the number of grid cells (16 x 16 cells grid, approximately 683 km^2 per cell) in which the species were found. The western Palearctic occurrence of species was defined as the number of "biogeopolitical" units in which species were found (Canard, 2005; taxonomy and occurrence of species updated in 2011). This estimation comes from the catalogue Islands/groups of islands were separated from continental countries for this estimation. See Leroy et al. (2013 - refs below) for a detailed description of this dataset. Note that the regional occurrence of species may have very slightly changed since the publication of the article because of small additions or modifications to our regional database.

Source

Leroy B., Canard A. & Ysnel F. 2013. Integrating multiple scales in rarity assessments of invertebrate taxa. Diversity and Distributions, 19, 794-803.

References

Canard, A. (2005) Catalogue of spider species from Europe and the Mediterranean basin. Revue Arachnologique, 15, 1-408.

Petillon, J., Courtial, C., Canard, A. & Ysnel, F. (2007a) First assessment of spider rarity in Western France. Revista iberica de aracnologia, 15, 105-113.

Ysnel, F., Petillon, J., Gerard, E. & Canard, A. (2008) Assessing the conservation value of the spider fauna across the West Palearctic area. Journal of Arachnology, 36, 457-463.

Leroy B., Canard A., & Ysnel F. 2013. Integrating multiple scales in rarity assessments of invertebrate taxa. Diversity and Distributions, 19, 794-803.

Examples

data(spid.occ)
head(spid.occ)
# Congruency between regional and western Palearctic occurrences
corPlot(spid.occ, method = "pearson", xlab = "Regional occurrence", 
        ylab = "Western Palearctic occurrence") # Shows the moderate congruency between regional and
                                                # biogeographic estimations of occurrence
# Calculation of multi-scale rarity weights      
rarity.weights <- rWeights(spid.occ, extended = TRUE)
head(rarity.weights)