community_overlap: Community Overlap Calculation

View source: R/community_overlap.R

community_overlapR Documentation

Community Overlap Calculation


This function calculates the median or mean of pairwise overlaps between density estimates of trait distributions of all species within a community, which can be weighted by species abundances.


  discrete = FALSE,
  circular = FALSE,
  normal = TRUE,
  output = "median",
  weight_type = "hmean",
  randomize_weights = FALSE,
  unique_values = NULL,
  raw = FALSE,
  circular_args = list(),
  density_args = list(),
  hypervolume_set_args = list()



a vector of trait measurements in the univariate case, or a matrix in the multivariate case where each column is a trait.


a vector with length equal to length(traits) that indicates the taxon of each individual.


whether trait data may take continuous or discrete values. Defaults to FALSE (all traits continuous). A single logical value or a logical vector with length equal to the number of columns in traits.


whether trait data are circular (e.g., hours or angles). Defaults to FALSE (all traits non-circular). A single logical value or a logical vector with length equal to the number of columns in traits.


if TRUE, the area under all density functions is normalized to 1, if FALSE, the area under all density functions is proportional to the number of observations in that group.


specifies whether median or mean is calculated.


specifies weights to be used to calculate the median or mean.


If TRUE, randomize weights given to pairwise overlaps within a community. This can be used to generate null models.


Vector of all possible discrete values that traits can take. Only used if discrete = TRUE and circular = TRUE.


If TRUE, also return the raw individual pairwise overlaps used to calculate the community-level statistic. Default is FALSE.


optional list of additional arguments to pass to circular. Only used if circular = TRUE and discrete = FALSE.


list of additional arguments to be passed to density if univariate, or hypervolume if multivariate.


list of additional arguments to be passed to hypervolume_set. Used only in multivariate case.


The function evaluates weighted mean or median of overlaps of density estimates of all species in a community taking complete cases with species abundances greater than 1 from the dataset. The default calculates the median of pairwise overlaps for the whole community using the harmonic means of abundances of the species pairs as weights, which minimizes the effect of outliners and rare species.If the argument weight_type = "none", no weights are used for the calculation of mean/median. If weight_type = "mean", arithmetic means of abundances are used as weights. To change the output to mean, specify the argument output = "mean".


The function returns the O-statistic for the community as a numeric value. If raw = TRUE, instead a list is returned, where the first element value is the numeric value, and the second element raw is a data frame with all the raw pairwise overlaps.


Read, Q. D. et al. Among-species overlap in rodent body size distributions predicts species richness along a temperature gradient. Ecography 41, 1718-1727 (2018).


# Keep only the relevant part of small mammal data
dat <- small_mammal_data[small_mammal_data$siteID %in% c('HARV','JORN'), ]
dat <- dat[!$weight), ]
dat$log_weight <- log10(dat$weight)

# Calculate median of pairwise overlaps for the community,weighted by harmonic means
# of abundances
community_overlap(traits = as.matrix(dat$log_weight),
   sp = factor(dat$taxonID))

Ostats documentation built on Sept. 12, 2022, 5:05 p.m.