| Title: | SPecies Association Analysis |
|---|---|
| Description: | Miscellaneous functions for analysing species association and niche overlap. |
| Authors: | Jinlong Zhang [aut, cre] |
| Maintainer: | Jinlong Zhang <[email protected]> |
| License: | GPL-2 |
| Version: | 0.2.5 |
| Built: | 2026-05-15 07:15:49 UTC |
| Source: | https://github.com/cran/spaa |
Miscellaneous functions for analysis of species association and niche overlap.
| Package: | spaa |
| Type: | Package |
| Version: | 0.2.5 |
| Date: | 2024-12-23 |
| License: | GPL-2 |
| LazyLoad: | yes |
Author: Jinlong Zhang [email protected]
Maintainer: Jinlong Zhang [email protected]
data(testdata) testdata data(splist) splist ### data tranformation (spmatrix <- data2mat(testdata)) #Species association sp.assoc(spmatrix) # Species association between each pair of species (result <- sp.pair(spmatrix)) #### Niche width and niche overlap data(datasample) niche.overlap.boot(datasample[,1:3], method = "levins") niche.overlap(datasample, method = "levins") niche.width(datasample[,1:3], method = "shannon") ##example turnover() plotlab1 <- XYname(4,6) xxx <- 1:240 dim(xxx) <- c(24, 10) rownames(xxx) <- plotlab1 ### Distance between each pair of plots ddd <- dist(xxx) ### label matrix labmat1 <- lab.mat(plotlab1) yyy <- turnover(labmat1, ddd) ## geodist() example ## Paris L1 = deg2dec(-2,20,14) phi1 = deg2dec(48, 50, 11) ## Washington DC L2 = deg2dec(77,03,56) phi2 = deg2dec(38,55,17) ##High precision Great Circle distance geodist(L1, phi1, L2, phi2)data(testdata) testdata data(splist) splist ### data tranformation (spmatrix <- data2mat(testdata)) #Species association sp.assoc(spmatrix) # Species association between each pair of species (result <- sp.pair(spmatrix)) #### Niche width and niche overlap data(datasample) niche.overlap.boot(datasample[,1:3], method = "levins") niche.overlap(datasample, method = "levins") niche.width(datasample[,1:3], method = "shannon") ##example turnover() plotlab1 <- XYname(4,6) xxx <- 1:240 dim(xxx) <- c(24, 10) rownames(xxx) <- plotlab1 ### Distance between each pair of plots ddd <- dist(xxx) ### label matrix labmat1 <- lab.mat(plotlab1) yyy <- turnover(labmat1, ddd) ## geodist() example ## Paris L1 = deg2dec(-2,20,14) phi1 = deg2dec(48, 50, 11) ## Washington DC L2 = deg2dec(77,03,56) phi2 = deg2dec(38,55,17) ##High precision Great Circle distance geodist(L1, phi1, L2, phi2)
Convert field records to community matrix
data2mat(data = data)data2mat(data = data)
data |
A dataframe with the the following columns: |
Return a community matrix ready for computing diversity indices.
Jinlong Zhang [email protected]
None
data(testdata) spmatrix <- data2mat(testdata)data(testdata) spmatrix <- data2mat(testdata)
A sample community matrix containing 8 plots and 14 species, from Gutianshan, Zhejiang, China.
data(datasample)data(datasample)
Values are the importance value for each species.
Hu Zheng-hua, Qian Hai-Yuan, Yu Ming-jian. 2009. The niche of dominant species populations in Castanopsis eyrei forest in Gutian Mountain National Natural Reserve. Acta Ecologica Sinica. Vol.29, 3670-3677
data(datasample) datasampledata(datasample) datasample
Convert latitude or longitude from degree to decimal format
deg2dec(h, m, s)deg2dec(h, m, s)
h |
Degree |
m |
Minute |
s |
Second |
Convert latitude or longitude from degree to decimal format.
Degree of decimal format
Places with eastern hemisphere should have longitude and southern hemisphere less than zero.
Jinlong Zhang [email protected]
## deg2dec() example ##Paris L1 = deg2dec(-2,20,14) phi1 = deg2dec(48, 50, 11) ##Washington DC L2 = deg2dec(77,03,56) phi2 = deg2dec(38,55,17)## deg2dec() example ##Paris L1 = deg2dec(-2,20,14) phi1 = deg2dec(48, 50, 11) ##Washington DC L2 = deg2dec(77,03,56) phi2 = deg2dec(38,55,17)
Convert distance matrix to pairwised list
dist2list(dist)dist2list(dist)
dist |
distance matrix |
Pairwise list with first column indicates the rows of the original distance matrix, second column indicates the columns indicates the rows of the original distance matrix, and the third indicats the values.
Dataframe with three columns.
Jinlong Zhang [email protected]
Tuomisto, H. (2003). "Dispersal, Environment, and Floristic Variation of Western Amazonian Forests." Science 299(5604): 241-244.
##dist2list() example x <- matrix(rnorm(100), nrow=5) sampledata <- dist(x) ddd <- dist2list(sampledata)##dist2list() example x <- matrix(rnorm(100), nrow=5) sampledata <- dist(x) ddd <- dist2list(sampledata)
Computing species' relative frequency as defined by the numbers of plots having a species divided by the total number of plots.
freq.calc(matr)freq.calc(matr)
matr |
A community matrix |
The input should be a standard community matrix with rows representing sites and columns representing species.
A vector containing relative frequency for each species
Jinlong Zhang [email protected]
None
data(testdata) spmatrix <- data2mat(testdata) freq.calc(spmatrix)data(testdata) spmatrix <- data2mat(testdata) freq.calc(spmatrix)
Hight precision Great circle distance between two places assuming the earth is elliptic sphere.
geodist(L1, phi1, L2, phi2)geodist(L1, phi1, L2, phi2)
L1 |
Longitude of first place in decimal format. |
phi1 |
Latitude of first place in decimal format. |
L2 |
Longitude of second place in decimal format. |
phi2 |
Latitude of second place in decimal format. |
Hight precision great circle distance between two places assuming the earth is elliptic sphere.
Hight precision great circle distance.
Jinlong Zhang [email protected]
Jean Meeus 1991 Astronomical Algorithms Willmann-Bell 80-83
## geodist() example ## Paris L1 = deg2dec(-2,20,14) phi1 = deg2dec(48, 50, 11) ## Washington DC L2 = deg2dec(77,03,56) phi2 = deg2dec(38,55,17) ##High precision Great Circle distance geodist(L1, phi1, L2, phi2)## geodist() example ## Paris L1 = deg2dec(-2,20,14) phi1 = deg2dec(48, 50, 11) ## Washington DC L2 = deg2dec(77,03,56) phi2 = deg2dec(38,55,17) ##High precision Great Circle distance geodist(L1, phi1, L2, phi2)
Convert vector of XY labels to label matrix
lab.mat(plotlab)lab.mat(plotlab)
plotlab |
Vector of XY labels |
XY label matrix
Jinlong Zhang [email protected]
### lab.mat() example plotlab1 <- XYname(4,6) labmat <- lab.mat(plotlab1)### lab.mat() example plotlab1 <- XYname(4,6) labmat <- lab.mat(plotlab1)
Calculating Great circle distance between two places assuming that the earth is sphere.
lgeodist(L1, phi1, L2, phi2)lgeodist(L1, phi1, L2, phi2)
L1 |
Longitude of first place in decimal format. |
phi1 |
Latitude of first place in decimal format. |
L2 |
Longitude of second place in decimal format. |
phi2 |
Latitude of second place in decimal format. |
Low precision great circle distance between two places.
This function assuming that the earth is sphere.
Jinlong Zhang [email protected]
Jean Meeus 1991 Astronomical Algorithms Willmann-Bell 80-81
#lgeodist() example ##Paris L1 = deg2dec(-2,20,14) phi1 = deg2dec(48, 50, 11) ##Washington DC L2 = deg2dec(77,03,56) phi2 = deg2dec(38,55,17) #Great circle distance lgeodist(L1, phi1, L2, phi2)#lgeodist() example ##Paris L1 = deg2dec(-2,20,14) phi1 = deg2dec(48, 50, 11) ##Washington DC L2 = deg2dec(77,03,56) phi2 = deg2dec(38,55,17) #Great circle distance lgeodist(L1, phi1, L2, phi2)
Convert pairwise list to distance matrix
list2dist(dat)list2dist(dat)
dat |
dataframe with three columns |
Dataframe with first column as the column names in the distance matrix, second column as the rownames in the distance matrix, third column the values.
distance matrix
Jinlong Zhang [email protected]
Tuomisto, H. (2003). "Dispersal, Environment, and Floristic Variation of Western Amazonian Forests." Science 299(5604): 241-244.
##list2dist() example x <- matrix(rnorm(100), nrow=5) sampledata <- dist(x) ddd <- dist2list(sampledata) list2dist(ddd)##list2dist() example x <- matrix(rnorm(100), nrow=5) sampledata <- dist(x) ddd <- dist2list(sampledata) list2dist(ddd)
Compute niche overlap between each pair of species.
niche.overlap(mat, method = c("levins", "schoener", "petraitis", "pianka", "czech", "morisita"))niche.overlap(mat, method = c("levins", "schoener", "petraitis", "pianka", "czech", "morisita"))
mat |
A community matrix with columns representing species, and rows representing plots. |
method |
A string specifying the name of the index. |
To add.
A distance matrix contains niche overlap index between each pair of species.
Jinlong Zhang [email protected]
Zhang Jin-tun,(2004 ) Quantitative Ecology, Science Press, Beijing
Nicholas J. Gotelli. 2000. Null model analysis of species co-occurrence patterns. Ecology 81:2606-2621. http://esapubs.org/archive/ecol/E081/022/EcoSim
data(datasample) niche.overlap(datasample, method = "levins")data(datasample) niche.overlap(datasample, method = "levins")
Bootstrap niche overlap indices
niche.overlap.boot(mat, method = c("pianka", "schoener", "petraitis", "czech", "morisita", "levins"), times = 1000, quant = c(0.025, 0.975))niche.overlap.boot(mat, method = c("pianka", "schoener", "petraitis", "czech", "morisita", "levins"), times = 1000, quant = c(0.025, 0.975))
mat |
standard community matrix. |
method |
character string specifying the index. |
times |
Interger, representing the number of bootstrap samples to generate. |
quant |
Quantile of the bootstrap values. |
This function bootstraps the following niche overlap indices between each pair of species: \
schoener: Schoener's niche overlap index\
petraitis: Petraitis' niche overlap index\
czech: Czechanowski index \
morisita: Morisita's overlap index\
levins: Levin's overlap index\
see more information from Gotelli, N(2009).\
a data frame with each row for each pair of species
the columns are "Observed", "Boot mean", "Boot std", "Boot CI1", "Boot CI2", "times"
Jinlong Zhang [email protected]
Zhang Jin-tun,(2004 ) Quantitative Ecology, Science Press, Beijing\
Nicholas J. Gotelli. 2000. Null model analysis of species co-occurrence patterns. Ecology 81:2606-2621. http://esapubs.org/archive/ecol/E081/022/EcoSim
data(datasample) niche.overlap.boot(datasample[,1:4], method = "pianka") niche.overlap.boot(datasample[,1:4], method = "schoener") niche.overlap.boot(datasample[,1:4], method = "czech") niche.overlap.boot(datasample[,1:4], method = "levins")data(datasample) niche.overlap.boot(datasample[,1:4], method = "pianka") niche.overlap.boot(datasample[,1:4], method = "schoener") niche.overlap.boot(datasample[,1:4], method = "czech") niche.overlap.boot(datasample[,1:4], method = "levins")
bootstrap the niche overlap indices between a pair of species. This is an internal function used by niche.overlap.boot, use niche.overlap.boot instead.
niche.overlap.boot.pair(vectorA, vectorB, method = c("levins", "schoener", "petraitis", "pianka", "czech", "morisita"), times = 1000, quant = c(0.025, 0.975))niche.overlap.boot.pair(vectorA, vectorB, method = c("levins", "schoener", "petraitis", "pianka", "czech", "morisita"), times = 1000, quant = c(0.025, 0.975))
vectorA |
A numeric vector containing species A's abundance or importance value. |
vectorB |
A numeric vector containing species B's abundance or importance value. |
method |
Name of the index to use. |
times |
Number of bootstraps |
quant |
Confidence intervals of the bootstrap results. |
This function will return a vector containing:\
"Observed", \
"Boot mean", \
"Boot std", \
"Boot CI1", \
"Boot CI2", \
"times" \
This is an internal function, please use niche.overlap.boot.
Jinlong Zhang [email protected]
Zhang Jin-tun,(2004 ) Quantitative Ecology, Science Press, Beijing
data(datasample) niche.overlap.boot.pair(datasample[,1], datasample[,2], method = "levins")data(datasample) niche.overlap.boot.pair(datasample[,1], datasample[,2], method = "levins")
Compute niche overlap index between two species. This is an internal function, used niche.overlap instead.
niche.overlap.pair(vectA, vectB, method = c("pianka", "schoener","petraitis","czech","morisita", "levins"))niche.overlap.pair(vectA, vectB, method = c("pianka", "schoener","petraitis","czech","morisita", "levins"))
vectA |
A numeric vector containing species A's abundance or importance value |
vectB |
A numeric vector containing species B's abundance or importance value |
method |
Niche overlap index |
None
The niche overlap index
Jinlong Zhang [email protected]
Zhang Jin-tun,(2004 ) Quantitative Ecology, Science Press, Beijing
Nicholas J. Gotelli. 2000. Null model analysis of species co-occurrence patterns. Ecology 81:2606-2621. http://esapubs.org/archive/ecol/E081/022/EcoSim
data(datasample) niche.overlap.pair(datasample[,1],datasample[,2], method = "levins")data(datasample) niche.overlap.pair(datasample[,1],datasample[,2], method = "levins")
Compute niche width for all the species in a community.
niche.width(mat, method = c("shannon", "levins"))niche.width(mat, method = c("shannon", "levins"))
mat |
A community matrix with columns representing species, and rows representing plots. |
method |
Character string showing the name of the index. |
A vetor containing niche width for all the species in the community.
Jinlong Zhang [email protected]
Zhang Jin-tun,(2004 ) Quantitative Ecology, Science Press, Beijing
niche.overlap for niche overlap
data(datasample) niche.width(datasample, method = "levins") niche.width(datasample, method = "shannon")data(datasample) niche.width(datasample, method = "levins") niche.width(datasample, method = "shannon")
Analyzing species association
sp.assoc(matr)sp.assoc(matr)
matr |
standard community matrix , with rows representing sites and columns representing species. |
Computations are based on the following formula.
If, N: Number of plots.
S: Number of species.
n: Number of plots occupied by certain species.
Tj: total number of species for each plot.
s
t: mean species number for all the plots.
Then:
Variance of species relative frequency is: sigma^{2}{T}= sum{i}=1^{s}P{i}(1-P{i}).
Variance of species number is: S^{2}{T}=({1}{N})sum{j=1}^{N}(T{j}-t)^{2} .
Species relative frequency: P{i}={n{i}}{N}.
Variance ratio:
If VR > 1 Positively associated,
If VR < 1 Negative associated
VR = {S{T}^{2}}/{sigma{T}^{2}}
W: used in comparison with chi square with n degrees of freedom.
W = VR * N
Variance ratio, W, Chisq, etc, see details
pi |
Species frequency |
N |
Number of plots |
S |
Number of species |
Tj |
Total number of species for each plot |
Numspmean |
Mean number of species |
sigmaTsq |
Variance of species relative frequency |
STsq |
Variance of species number |
var.ratio |
Variance ratio |
W |
W statiscit value: used in comparison with chi square.(n) |
Jinlong Zhang [email protected]
Zhang Qiaoying, Peng Shaolin, Zhang Sumei, Zhang Yunchun, Hou Yuping. (2008) Association of dormintant species in Guia hill Municipal Park of Macao. Ecology and Environment. 17:1541-1547
GUO zhongling, MA yuandan, ZHENG Jiping, LIU Wande , JIN Zefeng.(2004) Biodiversity of tree species,their populations'spatial distribution pattern and interspecific association in mixed deciduous broadleaved forest in Changbai Mountains. Chinese Journal of Applied Ecology. 15:2013-2018
Shi Zuomin, Liu Shirong, Cheng Ruimei, Jiang Youxu.(2001) Interspecific association of plant populations in deciduous broad leaved forest in Baotianman. Scientia Silvae Sinicae. 37:30-35
See also sp.pair for association between each pair of species.
data(testdata) spmatrix <- data2mat(testdata) sp.assoc(spmatrix)data(testdata) spmatrix <- data2mat(testdata) sp.assoc(spmatrix)
Compute species association between each pair of species.
sp.pair(matr)sp.pair(matr)
matr |
Standard community matrix, with rows representing sites and columns representing species. |
If a, b, c, d denote the co-occurrence the two species A and B, where:
a = number of plots occupied both by A and B.
b = number of plots only have A.
c = number of plots only have B.
d = number of plots without A or B.
N = a+b+c+d
Then, it is possible to compute:
Chi square (Yate's correction): chi^{2}=((((a*d-b*c)-0.5*N)^2)*N)/(a+b)*(a+c)*(b+d)*(c+d)
V ratio: V = ((a+d)-(b+c))/(a + b + c + d)
Jaccard index: Jaccard =a/(a + b + c)
Ochiai index: Ochiai = a/sqrt((a+b)*(a+c))
Dice index: Dice = 2*a/(2*a + b + c)
The Association Coefficient(AC):
if a*d >= b*c:
AC = (a*d - b*c)/((a+b)*(b+d))
if a*d < b*c and a <= d:
AC = (a*d - b*c)/((a+b)*(a+c))
if a*d < b*c and a > d:
AC = (a*d - b*c)/((b+d)*(c+d))
Point correlation coefficient
(PCC):
PCC = {a*d-b*c}/{(a+b)*(a+c)*(c+d)*(b+d)}
chisq |
Chi Square matrix |
V |
|
Ochiai |
Ochiai's index |
Dice |
Dice's index |
Jaccard |
Jaccard's index |
Pearson |
Pearson's correlation coefficient |
Spearman |
Spearman's rank correlation coefficient |
PCC |
Point correlation coefficient |
AC |
Association coefficient |
Jinlong Zhang [email protected]
HURLBERT, S. H. (1969). A coefficient of interspecific association. Ecology, 50(1), 1-9.
WANG, B. S., & PENG S. L. (1985). Studies on the Measuring Techniques of Interspecific Association of Lower-Subtropical Evergreen-Broadleaved Forests. I. The Exploration and the Revision on the Measuring Formulas of Interspecific Association. Chinese Journal of Plant Ecology, 9(4), 274-285.
JIAN, M. F., LIU, Q. J., ZHU, D., & YOU, H. (2009). Inter-specific correlations among dominant populations of tree layer species in evergreen broad-leaved forest in Jiulianshan Mountain of subtropical China. Chinese Journal of Plant Ecology, 33(4), 672-680.
ZHOU, X. Y., WANG, B. S., LI, M. G., & ZAN, Q. J. (2000). An analysis of interspecific associations in secondary succession forest communities in Heishiding Natural Reserve, Guangdong Province. Chinese Journal of Plant Ecology, 24(3), 332-339
See Also as sp.assoc for computing association for all the species.
data(testdata) spmatrix <- data2mat(testdata) result <- sp.pair(spmatrix)data(testdata) spmatrix <- data2mat(testdata) result <- sp.pair(spmatrix)
A sample dataframe containing the checklist of species used in add.col()
data(splist)data(splist)
A data frame with 9 observations on the following 3 variables.
speciesa factor with levels sp1 to sp8
generaa factor with levels gen1 to gen6
familya factor with levels fam1 to fam5
None
data(splist) data(testdata)data(splist) data(testdata)
Subset species based on relative frequency.
sub.sp.matrix(spmatrix, freq = 0.5, common = NULL)sub.sp.matrix(spmatrix, freq = 0.5, common = NULL)
spmatrix |
a standard community matrix with rows representing sites and columns representing species. |
freq |
The relative frequency, species with higher relative frequency will be kept in the output. |
common |
The number of most common species to keep. |
sub.sp.matrix will select the species whose relative frequency above 0.5 (default), or select certain number of species based on relative frequency.
A subset matrix of species with high relative frequency.
Jinlong Zhang [email protected]
None
See Also subset
library(vegan) data(BCI) ## Select the species whose relative frequency ## more than 0.5, from BCI data sub <- sub.sp.matrix(BCI, freq = 0.5) ## Select the top 30 species according to relative frequency sub <- sub.sp.matrix(BCI, common = 30)library(vegan) data(BCI) ## Select the species whose relative frequency ## more than 0.5, from BCI data sub <- sub.sp.matrix(BCI, freq = 0.5) ## Select the top 30 species according to relative frequency sub <- sub.sp.matrix(BCI, common = 30)
A sample dataset
data(testdata)data(testdata)
A dataframe with 11 observations on the following 3 variables.
plotnamea factor with levels plot1, plot2, plot3.
speciesa factor with levels sp1 to sp7.
abundancea numeric vector indicating number of individuals appeared in each plot.
data(testdata) testdatadata(testdata) testdata
Calculating species turnover based on the mean value between focus quadrat and their neighbours.
turnover(lab.mat, dist.mat, type = c("quart", "octal"))turnover(lab.mat, dist.mat, type = c("quart", "octal"))
lab.mat |
matrix of quadrat labels. |
dist.mat |
distance matrix between each pair of quadrats |
type |
"quart" indicates four neighbouring quadrats, "octal" indicate eight neighbouring quadrats. |
species turnover based on the mean value between centred quadrat and its neighbours.
matrix with species turnover.
Jinlong Zhang [email protected]
Lennon J. 2001 The geographical structure of British bird distributions - diversity, spatial turnover and scale Journal of Animal Ecology 70,966-979
##example turnover() plotlab1 <- XYname(4,6) xxx <- 1:240 dim(xxx) <- c(24, 10) rownames(xxx) <- plotlab1 ### Distance between each pair of plots ddd <- dist(xxx) ### label matrix labmat1 <- lab.mat(plotlab1) yyy <- turnover(labmat1, ddd)##example turnover() plotlab1 <- XYname(4,6) xxx <- 1:240 dim(xxx) <- c(24, 10) rownames(xxx) <- plotlab1 ### Distance between each pair of plots ddd <- dist(xxx) ### label matrix labmat1 <- lab.mat(plotlab1) yyy <- turnover(labmat1, ddd)
Generating vector of XY labels by providing number of rows and columns
XYname(x, y)XYname(x, y)
x |
Number of X labels |
y |
Number of Y labels |
Vector of XY labels
Jinlong Zhang [email protected]
None
lab.mat for converting the vector to matrix of XY labels.
## XYname() example XYname(4,6)## XYname() example XYname(4,6)