Package 'spaa'

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.5.3
Built: 2024-10-31 16:33:06 UTC
Source: https://github.com/helixcn/spaa

Help Index


SPecies Association Analysis

Description

Miscellaneous functions for analysing species association and niche overlap.

Details

The DESCRIPTION file:

Package: spaa
Type: Package
Title: SPecies Association Analysis
Version: 0.5.3
Date: 2021-03-30
Authors@R: person("Jinlong", "Zhang", role = c("aut", "cre"), email = "[email protected]")
Author: Jinlong Zhang [aut, cre]
Maintainer: Jinlong Zhang <[email protected]>
Description: Miscellaneous functions for analysing species association and niche overlap.
License: GPL (>= 2)
LazyLoad: yes
Suggests: vegan, knitr, rmarkdown, reshape2
VignetteBuilder: knitr
URL: https://github.com/helixcn/spaa
NeedsCompilation: no
Repository: https://helixcn.r-universe.dev
RemoteUrl: https://github.com/helixcn/spaa
RemoteRef: HEAD
RemoteSha: 83ca99e292bad1fea423365313b10b8566d7faa3

Index of help topics:

data2mat                Convert field records to community matrix
datasample              A sample dataset for a community
freq.calc               Compute species' relative frequency
niche.overlap           Niche overlap between each pair of species
niche.overlap.boot      Boostrap niche overlap indices
niche.overlap.boot.pair
                        Boostrap the niche overlap indices
niche.overlap.pair      Compute niche overlap index between two species
niche.width             Niche width
plotlowertri            Generate a graphs showing correlation matrix
                        (lower semi matrix) (Deprecated)
plotnetwork             Plot correlation network (Deprecated)
sp.assoc                Analyzing species association
sp.pair                 Species association between each pair of
                        species
spaa-package            SPecies Association Analysis
splist                  A sample dataframe showing species taxonomic
                        information (Deprecated)
sub.sp.matrix           Subset species based on relative frequency
testdata                A sample dataset s

Author(s)

Jinlong Zhang [aut, cre]

Maintainer: Jinlong Zhang <[email protected]>

References

Zhang Jin-tun,(2004) Quantitative Ecology, Science Press, Beijing

Examples

library(vegan)
  data(BCI)
  ## select the top 30 species according to relative frequeny.
  sub <- sub.sp.matrix(BCI, common = 30)
  ## Set the digits to 1
  plotlowertri(cor(sub), size = TRUE, cex = 3, digits = 1)

  ## 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")

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: species, plots or sites, abundance.

Value

Return a community matrix ready for computing diversity indices.

Author(s)

Jinlong Zhang [email protected]

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

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 [email protected]

References

None

Examples

data(testdata)
spmatrix <- data2mat(testdata)
freq.calc(spmatrix)

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 [email protected]

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

niche.overlap.pair

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 [email protected]

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

niche.overlap.boot.pair

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 [email protected]

References

Zhang Jin-tun,(2004 ) Quantitative Ecology, Science Press, Beijing

See Also

niche.overlap.boot

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 [email protected]

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

niche.overlap

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 [email protected]

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")

Generate a graphs showing correlation matrix (lower semi matrix) (Deprecated)

Description

Generate graphs (lower semi matrix) showing lower semi matrix. These graphs are often used to show the structure of a correlation, similarity or dissimilarity matrix.

Usage

plotlowertri(input, valuename = "r",
pchlist = c(19, 17, 15, 1, 5, 2, 7), interval = 6,
cex = 1, ncex = 1, int =1.2, add.number = TRUE,
size = FALSE, add.text = FALSE, show.legend = TRUE,
digits = 2)

Arguments

input

The input, often a correlation or a distance matrix.

valuename

Name of the value that to show in the legend.

pchlist

A numberic vector specifying the shapes of points, see pch par().

interval

Types of point shapes to show

cex

A number specifying the text size in the legend

ncex

Size of the text shown above each column.

int

Space between lines within the legend

add.number

If the column number should be shown

size

Whether the size of points should change with the value

add.text

Logical, If the number should be shown in the grid.

show.legend

Logical, If the legend should be appear.

digits

Number of digits for the label of each interval.

Details

In the legend, space between lines could be adjusted by specifying int.

Value

lower matrix plot

Author(s)

Jinlong Zhang [email protected]

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

See Also

See Also plotnetwork

Examples

data(testdata)
spmatrix <- data2mat(testdata)
result <- sp.pair(spmatrix)

## Check the legend for 0.00 to 0.33 (Unwanted label)
plotlowertri(result$Pearson, int = 0.5, cex=1.5)
title("Pearson Correlation Lower Matrix Plot")

## Change the size of points and reset the intervals.
## Warning: The lower matrix plot illustrating Pearson
## Correlation between each pair of species. Note the
## triangle didn't appeared in the plots, but have been
## added to the legend. This is due to the distribution
## of data. Be careful in selection of intervals.


plotlowertri(result$Pearson, int = 0.5, cex=1.5,
interval = 4, pchlist = c(19, 17, 15, 1, 5), size = TRUE)

title("Pearson Correlation Lower Matrix Plot")

## "Pure" dots, may have to add legend manually...
plotlowertri(result$Pearson, int = 0.5, cex=2.5,
interval = 4, pchlist = rep(19, 5), size = TRUE,
show.legend = FALSE)

title("Pearson Correlation Lower Matrix Plot")


## Using BCI data
library(vegan)
data(BCI)
## select the top 30 species according to relative frequency.
sub <- sub.sp.matrix(BCI, common = 30)
## Original
plotlowertri(cor(sub))

## Change size
plotlowertri(cor(sub), size = TRUE, cex = 3)

## Set the digits to 1
plotlowertri(cor(sub), size = TRUE, cex = 3, digits = 1,
ncex = 0.7)

Plot correlation network (Deprecated)

Description

Plotting correlation network showing the relationship between each pair of sites connected by segments. The points are arranged in a circle.

Usage

plotnetwork(datainput, n_levels = 6, xlim = c(-2.5, 5),
    ylim = c(-2.5, 2.5), node_size = 3, lwd.var = TRUE,
    lwd = 4, label_dist = 1.2,
    show.node = TRUE, show.text.label = TRUE,
    linecol = c("orange", "blue"),show.legend = TRUE,
    valuename = "r", legendx = 3,
    legendy = -2, legend_line_space = 1,
    legend_linelength = 0.3, adjust_legend_x = 0,
    adjust_legend_y = 0,digits = 2, ... )

Arguments

datainput

The correlation matrix, usually a lower matrix

n_levels

Number of types of segments to show the correlation, note interval should <12

xlim

horizontal range of the canvas

ylim

vertical range of the canvas

node_size

size of the nodes

lwd.var

logical, if the segments width should vary with the absolute value

lwd

width of the segments for connecting the sites, default 1

label_dist

Distance of text labels from each node.

show.node

Whether the nodes in the figure should be labeled

show.text.label

Whether the text label should be drawn.

linecol

Colours showing positve or negative correlation. The lines representing positive correlations use the first element

show.legend

If the legend should be shown

valuename

Name of the variable shown in the legend

legendx

the starting position of the legend x

legendy

the starting position of the legend y

legend_line_space

the space between the lines in the legend

legend_linelength

length of the segment in the legend

adjust_legend_x

adjusting the position of legend (x)

adjust_legend_y

adjusting the position of legend (y)

digits

Number of disgits shown in the legend, it will be used in generating the breaks as well

...

other parameters related with plot.default

Details

This function could be used to plot the pairwise connections between less than 20 sites ( above 20 is not recommended since there would be too many connections).

The lines will be in orange or blue, according the sign of the value.

Value

Correlation network plots.

Author(s)

Jinlong Zhang [email protected]

References

None

Examples

data(testdata)
spmatrix <- data2mat(testdata)
result <- sp.pair(spmatrix)
plotnetwork(result$Pearson)

plotnetwork(result$Pearson, linecol = c("red", "black"))

plotnetwork(result$Pearson, n_levels = 4,  node_size = 4,  
    lwd.var = FALSE, label_dist = 0.8, show.node = FALSE, 
    show.text.label = FALSE, linecol = c("red", "black"), 
    show.legend = TRUE, valuename = "r", legendx = 3, 
    legend_line_space = 0.5, legend_linelength = 0.5, 
    adjust_legend_x = -1)

title("Pearson Correlation Network")

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 [email protected]

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

V positive or negative association

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 [email protected]

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 to sp8

genera

a factor with levels gen1 to gen6

family

a factor with levels fam1 to fam5

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 [email protected]

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 to sp7.

abundance

a numeric vector indicating number of individuals appeared in each plot.

Examples

data(testdata)
testdata