dsimcom {adiv}R Documentation

Functional or Phylogenetic Similarity between Species and Communities

Description

The R function dsimcom calculates Pavoine and Ricotta (2014) coefficients SSokal-Sneath, SJaccard, SSorensen, SOchiai, and Sbeta of similarities among communities or their complements (1-S, dissimilarities).

Function SQ calculates Pavoine and Ricotta (2014) index S_Q (similarities between communities) and its complements 1-S_Q (dissimilarities between communities).

The functions dsimTax and dsimTree calculate pair-wise taxonomic and phylogenetic (dis)similarities between species, respectively. dsimTree can also be used to calculate pair-wise functional (dis)similarities between species if a functional dendrogram is used to describe species.

Function dsimFun calculates pair-wise functional (dis)similaties between species.

Usage

dsimcom(comm, Sigma = NULL, method = 1:5, 
option = c("relative", "absolute"), 
type = c("similarity", "dissimilarity"))

SQ(comm, Sigma = NULL, type = c("similarity", "dissimilarity"))

dsimTaxo(tax, method = c(1, 2, 3, 4, 5), 
type = c("similarity", "dissimilarity"))

dsimTree(phyl, method = c(1, 2, 3, 4, 5), rootedge = NULL, 
type = c("similarity", "dissimilarity"))

dsimFun(df, vartype = c("Q", "N", "M", "P"), method = 1:5, 
type = c("similarity", "dissimilarity"))

Arguments

comm

a data frame or matrix with communities as rows, species as columns and non-negative values as entries.

Sigma

matrix of similarities among species (species as rows and columns in the same order as in comm; values in Sigma are bounded between 0 and 1). The matrix must be nonnegative definite, i.e. all its eigenvalues are nonnegative. Functions dsimTaxo, dsimTree and dsimFun can be used to obtain Sigma as these functions lead to nonnegative definite matrices.

method

an integer (1, 2, 3, 4, 5) indicating which basic coefficient should be used: Sokal-Sneath, Jaccard, Sorensen, Ochiai, beta, respectively.

option

a string. If option = "relative", the rows of comm are standardized into proportions that sum to 1. If option = "absolute", raw values are retained in comm.

tax

an object of class taxo (of package ade4).

type

a string. If type = "similarity", the functions dsimcom and SQ calculates similarities (S) between communities and the functions dsimTaxo, dsimTree and dsimFun calculates similarities between species. If type = "dissimilarity", the functions dsimcom and SQ calculates dissimilarities (1-S) between communities and the functions dsimTaxo, dsimTree and dsimFun calculates dissimilarities between species.

phyl

an object inheriting the class phylo (see package ape), phylo4 (see package phylobase), or hclust.

rootedge

a numeric equal to the length of the branch at the nearest common ancestor of all species (here referred to as the root node). This branch is thus anterior to the root. It is ignored if rootedge is NULL.

df

either a data frame, a matrix or an object of class ktab of package ade4. If class ktab is used, each data frame must contain a single type of traits (see argument vartype).

vartype

a vector of characters indicating the type of traits used in each data frame of df: "Q" for quantitative; "N" for nominal; "M" for multichoice; "P" for traits that can be expressed as proportions. Values in type must be in the same order as data frames in df (one value per table).

Details

Formulas for the indices are given in Pavoine and Ricotta (2014) main text and appendixes.

Value

If type = "similarities", a matrix of similarities between communities. If type = "dissimilarities", an object of class dist with the dissimilarities between communities.

Author(s)

Sandrine Pavoine sandrine.pavoine@mnhn.fr

References

Pavoine, S., Ricotta, C. (2014) Functional and phylogenetic similarity among communities. Methods in Ecology and Evolution, 5, 666–675.

Examples

## Not run: 
if(require(ade4)){
data(macroloire, package="ade4") 

Ssokalsneath <- dsimcom(t(macroloire$fau), method=1, option=c("relative"))
Sjaccard <- dsimcom(t(macroloire$fau), method=2, option=c("relative"))
Ssorensen <- dsimcom(t(macroloire$fau), method=3, option=c("relative"))
Sochiai <- dsimcom(t(macroloire$fau), method=4, option=c("relative"))
Sbeta <- dsimcom(t(macroloire$fau), method=5, option=c("relative"))

SQUNIF <- SQ(t(macroloire$fau))

# The taxonomy is contained in macroloire$taxo

s_species_sokalsneath_taxo <- dsimTaxo(macroloire$taxo, method=1) # Using formula a/(a+2b+2c) 
# (see notations below)
s_species_jaccard_taxo <- dsimTaxo(macroloire$taxo, method=2) # Using formula a/(a+b+c) 
s_species_sorensen_taxo <- dsimTaxo(macroloire$taxo, method=3) # Using formula 2a/(2a+b+c) 
s_species_ochiai_taxo <- dsimTaxo(macroloire$taxo, method=4) # Using a/sqrt((a+b)(a+c)) 
s_species_beta_taxo <- dsimTaxo(macroloire$taxo, method=5) # Using 4a/(4a+b+c)


# To check that these matrices of taxonomic similarities 
# among species are positive semidefinite (p.s.d.)
# we have to verify that their eigenvalues are all nonnegative:
all(eigen(s_species_sokalsneath_taxo)$val>-(1e-8))
all(eigen(s_species_jaccard_taxo)$val>-(1e-8))
all(eigen(s_species_sorensen_taxo)$val>-(1e-8))
all(eigen(s_species_ochiai_taxo)$val>-(1e-8))
all(eigen(s_species_beta_taxo)$val>-(1e-8))

# Compositions of the communities
m <- t(macroloire$fau[rownames(s_species_sokalsneath_taxo), ])
# Taxomonic similarities among species
s <- s_species_sokalsneath_taxo

Ssokalsneath_taxo <- dsimcom(m, s, method = 1)
SQwith_species_sokalsneath_taxo <- SQ(m, s)

# Compositions of the communities
m <- t(macroloire$fau[rownames(s_species_jaccard_taxo), ])
# Taxonomic similarities among species
s <- s_species_jaccard_taxo  
Sjaccard_taxo <- dsimcom(m, s, method = 2)
SQwith_species_jaccard_taxo <- SQ(m, s)

# Compositions of the communities
m <- t(macroloire$fau[rownames(s_species_sorensen_taxo), ])
# Taxonomic similarities among species
s <- s_species_sorensen_taxo  

Ssorensen_taxo <- dsimcom(m, s, method = 3)
SQwith_species_sorensen_taxo <- SQ(m, s)

# Compositions of the communities
m <- t(macroloire$fau[rownames(s_species_ochiai_taxo), ])
# Taxonomic similarities among species
s <- s_species_ochiai_taxo  

Sochiai_taxo <- dsimcom(m, s, method = 4)
SQwith_species_ochiai_taxo <- SQ(m, s)


# Compositions of the communities
m <- t(macroloire$fau[rownames(s_species_beta_taxo), ])
# Taxonomic similarities among species
s <- s_species_beta_taxo  

Sbeta_taxo <- dsimcom(m, s, method = 5)
SQwith_species_beta_taxo <- SQ(m, s)

# The matrix named feed below contains feeding attributes as rows,
# species as columns, and affinities (proportions) as entries.
feed <- macroloire$traits[ ,-(1:4)]

# Feeding habits comprise seven categories: engulfers, shredders, scrapers,
# deposit-feeders, active filter-feeders, passive filter-feeders and piercers, in this order.

# Functional similarities among species are computed as indicated in the main text
s_species_sokalsneath_feed <- dsimFun(feed, vartype = "P", method=1)
s_species_jaccard_feed <- dsimFun(feed, vartype = "P", method=2)
s_species_sorensen_feed <- dsimFun(feed, vartype = "P", method=3)
s_species_ochiai_feed <- dsimFun(feed, vartype = "P", method=4)
s_species_beta_feed <- dsimFun(feed, vartype = "P", method=5)

all(eigen(s_species_sokalsneath_feed)$val>-(1e-8))
all(eigen(s_species_jaccard_feed)$val>-(1e-8))
all(eigen(s_species_sorensen_feed)$val>-(1e-8))
all(eigen(s_species_ochiai_feed)$val>-(1e-8))
all(eigen(s_species_beta_feed)$val>-(1e-8))

Ssokalsneath_feed <- dsimcom(t(macroloire$fau), s_species_sokalsneath_feed, method=1)
SQwith_species_sokalsneath_feed <- SQ(t(macroloire$fau), s_species_sokalsneath_feed)

Sjaccard_feed <- dsimcom(t(macroloire$fau), s_species_jaccard_feed, method=2)
SQwith_species_jaccard_feed <- SQ(t(macroloire$fau), s_species_jaccard_feed)

Ssorensen_feed <- dsimcom(t(macroloire$fau), s_species_sorensen_feed, method=3)
SQwith_species_sorensen_feed <- SQ(t(macroloire$fau), s_species_sorensen_feed)

Sochiai_feed <- dsimcom(t(macroloire$fau), s_species_ochiai_feed, method=4)
SQwith_species_ochiai_feed <- SQ(t(macroloire$fau), s_species_ochiai_feed)

Sbeta_feed <- dsimcom(t(macroloire$fau), s_species_sorensen_feed, method=5)


all(eigen(Ssokalsneath_feed)$val>-(1e-8))
all(eigen(Sjaccard_feed)$val>-(1e-8))
all(eigen(Ssorensen_feed)$val>-(1e-8))
all(eigen(Sochiai_feed)$val>-(1e-8))
all(eigen(Sbeta_feed)$val>-(1e-8))


par(mfrow=c(3, 5))
plot(SQUNIF, Ssokalsneath, xlim=c(0,1), ylim=c(0,1), asp=1)
segments(0, 0, 1,1)
plot(SQUNIF, Sjaccard, xlim=c(0,1), ylim=c(0,1) , asp=1)
segments(0, 0, 1,1)
plot(SQUNIF, Ssorensen, xlim=c(0,1), ylim=c(0,1) , asp=1)
segments(0, 0, 1,1)
plot(SQUNIF, Sochiai, xlim=c(0,1), ylim=c(0,1) , asp=1)
segments(0, 0, 1,1)
plot(SQUNIF, Sbeta, xlim=c(0,1), ylim=c(0,1) , asp=1)
segments(0, 0, 1,1)

plot(SQwith_species_sokalsneath_taxo, Ssokalsneath_taxo, xlim=c(0,1), ylim=c(0,1), asp=1)
segments(0, 0, 1,1)
plot(SQwith_species_jaccard_taxo, Sjaccard_taxo, xlim=c(0,1), ylim=c(0,1) , asp=1)
segments(0, 0, 1,1)
plot(SQwith_species_sorensen_taxo, Ssorensen_taxo, xlim=c(0,1), ylim=c(0,1) , asp=1)
segments(0, 0, 1,1)
plot(SQwith_species_ochiai_taxo, Sochiai_taxo, xlim=c(0,1), ylim=c(0,1) , asp=1)
segments(0, 0, 1,1)
plot(SQwith_species_beta_taxo, Sbeta_taxo, xlim=c(0,1), ylim=c(0,1) , asp=1)
segments(0, 0, 1,1)

plot(SQwith_species_sokalsneath_feed, Ssokalsneath_feed, xlim=c(0,1), ylim=c(0,1), asp=1)
segments(0, 0, 1,1)
plot(SQwith_species_jaccard_feed, Sjaccard_feed, xlim=c(0,1), ylim=c(0,1) , asp=1)
segments(0, 0, 1,1)
plot(SQwith_species_sorensen_feed, Ssorensen_feed, xlim=c(0,1), ylim=c(0,1) , asp=1)
segments(0, 0, 1,1)
plot(SQwith_species_ochiai_feed, Sochiai_feed, xlim=c(0,1), ylim=c(0,1) , asp=1)
segments(0, 0, 1,1)
plot(SQwith_species_sorensen_feed, Sbeta_feed, xlim=c(0,1), ylim=c(0,1) , asp=1)
segments(0, 0, 1,1)

par(mfrow=c(1,1))
}

## End(Not run)

[Package adiv version 2.2.1 Index]