Type: | Package |
Title: | SPecies Association Analysis |
Version: | 0.2.5 |
Date: | 2024-12-23 |
Author: | Jinlong Zhang [aut, cre] |
Maintainer: | Jinlong Zhang <jinlongzhang01@gmail.com> |
Description: | Miscellaneous functions for analysing species association and niche overlap. |
License: | GPL-2 |
LazyLoad: | yes |
Suggests: | vegan |
URL: | https://github.com/helixcn/spaa |
NeedsCompilation: | no |
Packaged: | 2024-12-23 07:18:38 UTC; jlzhang |
Repository: | CRAN |
Date/Publication: | 2025-01-08 07:30:02 UTC |
SPecies Association Analysis
Description
Miscellaneous functions for analysis of species association and niche overlap.
Details
Package: | spaa |
Type: | Package |
Version: | 0.2.5 |
Date: | 2024-12-23 |
License: | GPL-2 |
LazyLoad: | yes |
Author(s)
Author: Jinlong Zhang jinlongzhang01@gmail.com
Maintainer: Jinlong Zhang jinlongzhang01@gmail.com
Examples
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)
Generating vector of XY labels
Description
Generating vector of XY labels by providing number of rows and columns
Usage
XYname(x, y)
Arguments
x |
Number of X labels |
y |
Number of Y labels |
Value
Vector of XY labels
Author(s)
Jinlong Zhang jinlongzhang01@gmail.com
References
None
See Also
lab.mat
for converting the vector to matrix of XY labels.
Examples
## XYname() example
XYname(4,6)
Convert field records to community matrix
Description
Convert field records to community matrix
Usage
data2mat(data = data)
Arguments
data |
A dataframe with the the following columns: |
Value
Return a community matrix ready for computing diversity indices.
Author(s)
Jinlong Zhang jinlongzhang01@gmail.com
References
None
Examples
data(testdata)
spmatrix <- data2mat(testdata)
A sample dataset for a community
Description
A sample community matrix containing 8 plots and 14 species, from Gutianshan, Zhejiang, China.
Usage
data(datasample)
Details
Values are the importance value for each species.
Source
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
Examples
data(datasample)
datasample
Degree to decimal
Description
Convert latitude or longitude from degree to decimal format
Usage
deg2dec(h, m, s)
Arguments
h |
Degree |
m |
Minute |
s |
Second |
Details
Convert latitude or longitude from degree to decimal format.
Value
Degree of decimal format
Note
Places with eastern hemisphere should have longitude and southern hemisphere less than zero.
Author(s)
Jinlong Zhang jinlongzhang01@gmail.com
Examples
## 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
Description
Convert distance matrix to pairwised list
Usage
dist2list(dist)
Arguments
dist |
distance matrix |
Details
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.
Value
Dataframe with three columns.
Author(s)
Jinlong Zhang jinlongzhang01@gmail.com
References
Tuomisto, H. (2003). "Dispersal, Environment, and Floristic Variation of Western Amazonian Forests." Science 299(5604): 241-244.
See Also
Examples
##dist2list() example
x <- matrix(rnorm(100), nrow=5)
sampledata <- dist(x)
ddd <- dist2list(sampledata)
Compute species' relative frequency
Description
Computing species' relative frequency as defined by the numbers of plots having a species divided by the total number of plots.
Usage
freq.calc(matr)
Arguments
matr |
A community matrix |
Details
The input should be a standard community matrix with rows representing sites and columns representing species.
Value
A vector containing relative frequency for each species
Author(s)
Jinlong Zhang jinlongzhang01@gmail.com
References
None
Examples
data(testdata)
spmatrix <- data2mat(testdata)
freq.calc(spmatrix)
Hight precision Great circle distance between two places
Description
Hight precision Great circle distance between two places assuming the earth is elliptic sphere.
Usage
geodist(L1, phi1, L2, phi2)
Arguments
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. |
Details
Hight precision great circle distance between two places assuming the earth is elliptic sphere.
Value
Hight precision great circle distance.
Author(s)
Jinlong Zhang jinlongzhang01@gmail.com
References
Jean Meeus 1991 Astronomical Algorithms Willmann-Bell 80-83
See Also
Examples
## 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
Description
Convert vector of XY labels to label matrix
Usage
lab.mat(plotlab)
Arguments
plotlab |
Vector of XY labels |
Value
XY label matrix
Author(s)
Jinlong Zhang jinlongzhang01@gmail.com
See Also
Examples
### lab.mat() example
plotlab1 <- XYname(4,6)
labmat <- lab.mat(plotlab1)
Low precision Great circle distance between two places
Description
Calculating Great circle distance between two places assuming that the earth is sphere.
Usage
lgeodist(L1, phi1, L2, phi2)
Arguments
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. |
Value
Low precision great circle distance between two places.
Note
This function assuming that the earth is sphere.
Author(s)
Jinlong Zhang jinlongzhang01@gmail.com
References
Jean Meeus 1991 Astronomical Algorithms Willmann-Bell 80-81
See Also
Examples
#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
Description
Convert pairwise list to distance matrix
Usage
list2dist(dat)
Arguments
dat |
dataframe with three columns |
Details
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.
Value
distance matrix
Author(s)
Jinlong Zhang jinlongzhang01@gmail.com
References
Tuomisto, H. (2003). "Dispersal, Environment, and Floristic Variation of Western Amazonian Forests." Science 299(5604): 241-244.
See Also
Examples
##list2dist() example
x <- matrix(rnorm(100), nrow=5)
sampledata <- dist(x)
ddd <- dist2list(sampledata)
list2dist(ddd)
Niche overlap between each pair of species
Description
Compute niche overlap between each pair of species.
Usage
niche.overlap(mat, method = c("levins", "schoener",
"petraitis", "pianka", "czech", "morisita"))
Arguments
mat |
A community matrix with columns representing species, and rows representing plots. |
method |
A string specifying the name of the index. |
Details
To add.
Value
A distance matrix contains niche overlap index between each pair of species.
Author(s)
Jinlong Zhang jinlongzhang01@gmail.com
References
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
See Also
Examples
data(datasample)
niche.overlap(datasample, method = "levins")
Boostrap niche overlap indices
Description
Bootstrap niche overlap indices
Usage
niche.overlap.boot(mat, method = c("pianka", "schoener", "petraitis",
"czech", "morisita", "levins"), times = 1000, quant = c(0.025, 0.975))
Arguments
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. |
Details
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).\
Value
a data frame with each row for each pair of species
the columns are "Observed", "Boot mean", "Boot std", "Boot CI1", "Boot CI2", "times"
Author(s)
Jinlong Zhang jinlongzhang01@gmail.com
References
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
See Also
Examples
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")
Boostrap the niche overlap indices
Description
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.
Usage
niche.overlap.boot.pair(vectorA, vectorB, method = c("levins",
"schoener", "petraitis", "pianka", "czech", "morisita"),
times = 1000, quant = c(0.025, 0.975))
Arguments
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. |
Value
This function will return a vector containing:\
"Observed", \
"Boot mean", \
"Boot std", \
"Boot CI1", \
"Boot CI2", \
"times"
\
Note
This is an internal function, please use niche.overlap.boot
.
Author(s)
Jinlong Zhang jinlongzhang01@gmail.com
References
Zhang Jin-tun,(2004 ) Quantitative Ecology, Science Press, Beijing
See Also
Examples
data(datasample)
niche.overlap.boot.pair(datasample[,1], datasample[,2], method = "levins")
Compute niche overlap index between two species
Description
Compute niche overlap index between two species. This is an internal function, used niche.overlap
instead.
Usage
niche.overlap.pair(vectA, vectB, method = c("pianka",
"schoener","petraitis","czech","morisita", "levins"))
Arguments
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 |
Details
None
Value
The niche overlap index
Author(s)
Jinlong Zhang jinlongzhang01@gmail.com
References
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
See Also
Examples
data(datasample)
niche.overlap.pair(datasample[,1],datasample[,2], method = "levins")
Niche width
Description
Compute niche width for all the species in a community.
Usage
niche.width(mat, method = c("shannon", "levins"))
Arguments
mat |
A community matrix with columns representing species, and rows representing plots. |
method |
Character string showing the name of the index. |
Value
A vetor containing niche width for all the species in the community.
Author(s)
Jinlong Zhang jinlongzhang01@gmail.com
References
Zhang Jin-tun,(2004 ) Quantitative Ecology, Science Press, Beijing
See Also
niche.overlap
for niche overlap
Examples
data(datasample)
niche.width(datasample, method = "levins")
niche.width(datasample, method = "shannon")
Analyzing species association
Description
Analyzing species association
Usage
sp.assoc(matr)
Arguments
matr |
standard community matrix , with rows representing sites and columns representing species. |
Details
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
Value
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) |
Author(s)
Jinlong Zhang jinlongzhang01@gmail.com
References
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
See also sp.pair
for association between each pair of species.
Examples
data(testdata)
spmatrix <- data2mat(testdata)
sp.assoc(spmatrix)
Species association between each pair of species
Description
Compute species association between each pair of species.
Usage
sp.pair(matr)
Arguments
matr |
Standard community matrix, with rows representing sites and columns representing species. |
Details
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)}
Value
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 |
Author(s)
Jinlong Zhang jinlongzhang01@gmail.com
References
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
See Also as sp.assoc
for computing association for all the species.
Examples
data(testdata)
spmatrix <- data2mat(testdata)
result <- sp.pair(spmatrix)
A sample dataframe showing species taxonomic information (Deprecated)
Description
A sample dataframe containing the checklist of species used in add.col()
Usage
data(splist)
Format
A data frame with 9 observations on the following 3 variables.
species
a factor with levels
sp1
tosp8
genera
a factor with levels
gen1
togen6
family
a factor with levels
fam1
tofam5
References
None
Examples
data(splist)
data(testdata)
Subset species based on relative frequency
Description
Subset species based on relative frequency.
Usage
sub.sp.matrix(spmatrix, freq = 0.5, common = NULL)
Arguments
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. |
Details
sub.sp.matrix will select the species whose relative frequency above 0.5 (default), or select certain number of species based on relative frequency.
Value
A subset matrix of species with high relative frequency.
Author(s)
Jinlong Zhang jinlongzhang01@gmail.com
References
None
See Also
See Also subset
Examples
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 s
Description
A sample dataset
Usage
data(testdata)
Format
A dataframe with 11 observations on the following 3 variables.
plotname
a factor with levels
plot1
,plot2
,plot3
.species
a factor with levels
sp1
tosp7
.abundance
a numeric vector indicating number of individuals appeared in each plot.
Examples
data(testdata)
testdata
Calculating species turnover
Description
Calculating species turnover based on the mean value between focus quadrat and their neighbours.
Usage
turnover(lab.mat, dist.mat, type = c("quart", "octal"))
Arguments
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. |
Details
species turnover based on the mean value between centred quadrat and its neighbours.
Value
matrix with species turnover.
Author(s)
Jinlong Zhang jinlongzhang01@gmail.com
References
Lennon J. 2001 The geographical structure of British bird distributions - diversity, spatial turnover and scale Journal of Animal Ecology 70,966-979
See Also
Examples
##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)