EcoSimR - Null Model Analysis of Ecological Data

The following code demonstrates how to use the EcoSimR package to conduct a species co-occurrence analysis using null models. The results of this analysis reveal if there are statistically significant patterns of species aggregation or segregation in the dataset.

The following code uses associated species data collected from 19 survey patches across five serpentine outcrops in northern VT, which was collected as part of a maidenhair fern habitat study in the summer of 2016. The following code transforms the associated species data into a presence-absence matrix that is then used for the null model analysis.

Associated Species Data

1. Create presence-absence matrix from species list data

# read in associated species data 
sppDat <- read.table("AssociatedSppData_Serp.csv",header=TRUE,sep=",",stringsAsFactors = FALSE)
head(sppDat)
##   SitePatch           SpeciesName
## 1       5.1          Rubus idaeus
## 2       5.1  Deschampsia flexuosa
## 3       5.1 Athyrium filix-femina
## 4       5.1 Dryopteris marginalis
## 5       5.1 Dryopteris intermedia
## 6       5.1 Maianthemum canadense
# reshape data using dcast function in reshape2 package
library(reshape2)
PA <- dcast(sppDat,formula=SpeciesName~SitePatch)
head(PA)
##          SpeciesName 5.1 5.2 5.3 6.2 6.3 6.4 6.5 8.1 8.2 8.3 8.4 8.5 8.6
## 1     Abies balsamea   1   1   1   1   0   0   0   1   1   1   1   1   1
## 2 Acer pensylvanicum   0   0   0   0   0   1   0   1   0   0   1   0   0
## 3        Acer rubrum   1   1   1   1   1   1   0   0   1   1   1   1   1
## 4    Acer saccharum    0   0   0   0   0   1   0   0   0   0   1   0   0
## 5      Acer spicatum   0   0   0   1   0   1   0   0   0   0   0   0   0
## 6     Amelanchier sp   0   1   1   0   0   0   0   0   0   0   0   0   0
##   9.1 9.2 9.3 9.4 10.1 10.2
## 1   1   1   1   1    0    0
## 2   1   0   0   0    1    1
## 3   1   1   1   1    0    0
## 4   0   0   0   0    1    1
## 5   0   0   0   0    1    1
## 6   0   0   0   0    0    0
dim(PA)
## [1] 77 20

2. Conduct Species Co-occurrence Analysis using EcoSimR

SIM9 null model algorithm- row and column sums fixed

CHECKER index

library(EcoSimR)
library(MASS)
# Run null model with SIM9 algorithm & CHECKER index
adMod1 <- cooc_null_model(PA,
                    algo="sim9",
                    metric="checker",
                    nReps=1000,
                    suppressProg=T)

# Summary and plots
summary(adMod1)
## Time Stamp:  Tue Apr 25 15:04:37 2017 
## Reproducible:  
## Number of Replications:  
## Elapsed Time:  52 secs 
## Metric:  checker 
## Algorithm:  sim9 
## Observed Index:  1721 
## Mean Of Simulated Index:  1668.4 
## Variance Of Simulated Index:  97.138 
## Lower 95% (1-tail):  1650 
## Upper 95% (1-tail):  1682 
## Lower 95% (2-tail):  1648 
## Upper 95% (2-tail):  1684 
## Lower-tail P >  0.999 
## Upper-tail P <  0.001 
## Observed metric > 1000 simulated metrics 
## Observed metric < 0 simulated metrics 
## Observed metric = 0 simulated metrics 
## Standardized Effect Size (SES):  5.3363
mean(adMod1$Sim)
## [1] 1668.406
plot(adMod1,type="hist")

plot(adMod1,type="cooc")

plot(adMod1,type="burn_in")

C score index

## Run null model with SIM9 algorithm and C score index
adMod2 <- cooc_null_model(PA,
                          algo="sim9",
                          metric="c_score",
                          nReps=1000,
                          suppressProg = T)

# Summary and plots
summary(adMod2)
## Time Stamp:  Tue Apr 25 15:04:39 2017 
## Reproducible:  
## Number of Replications:  
## Elapsed Time:  0.97 secs 
## Metric:  c_score 
## Algorithm:  sim9 
## Observed Index:  5.6917 
## Mean Of Simulated Index:  5.117 
## Variance Of Simulated Index:  0.00073921 
## Lower 95% (1-tail):  5.0772 
## Upper 95% (1-tail):  5.1651 
## Lower 95% (2-tail):  5.0759 
## Upper 95% (2-tail):  5.1825 
## Lower-tail P >  0.999 
## Upper-tail P <  0.001 
## Observed metric > 1000 simulated metrics 
## Observed metric < 0 simulated metrics 
## Observed metric = 0 simulated metrics 
## Standardized Effect Size (SES):  21.137
plot(adMod2,type="hist")

plot(adMod2,type="cooc")

plot(adMod2,type="burn_in")

COMBO index

# Run null model with SIM9 algorithm and COMBO index
adMod3 <- cooc_null_model(PA,
                          algo="sim9",
                          metric="species_combo",
                          nReps=1000,
                          suppressProg = T)

# Summary and plots
summary(adMod3)
plot(adMod3,type="hist")
plot(adMod3,type="cooc")

SIM2 null model algorithm- row sums fixed, columns equiprobable

CHECKER Index

# Run null model with SIM2 algorithm and C score index
adMod4 <- cooc_null_model(PA,
                          algo= "sim2",
                          metric="c_score",
                          nReps=1000,
                          suppressProg=T)

# Summary and plots
summary(adMod4)
## Time Stamp:  Tue Apr 25 15:04:43 2017 
## Reproducible:  FALSE 
## Number of Replications:  1000 
## Elapsed Time:  4 secs 
## Metric:  c_score 
## Algorithm:  sim2 
## Observed Index:  5.6917 
## Mean Of Simulated Index:  5.1553 
## Variance Of Simulated Index:  0.008174 
## Lower 95% (1-tail):  4.9985 
## Upper 95% (1-tail):  5.2919 
## Lower 95% (2-tail):  4.9555 
## Upper 95% (2-tail):  5.309 
## Lower-tail P >  0.999 
## Upper-tail P <  0.001 
## Observed metric > 1000 simulated metrics 
## Observed metric < 0 simulated metrics 
## Observed metric = 0 simulated metrics 
## Standardized Effect Size (SES):  5.9332
plot(adMod4,type="hist")

plot(adMod4,type="cooc")

C score Index

# Run null model with SIM2 algorithm and CHECKER index
adMod5 <- cooc_null_model(PA,
                          algo= "sim2",
                          metric="checker",
                          nReps=1000,
                          suppressProg=T)

# Summary and plots
summary(adMod5)
## Time Stamp:  Tue Apr 25 15:05:16 2017 
## Reproducible:  FALSE 
## Number of Replications:  1000 
## Elapsed Time:  32 secs 
## Metric:  checker 
## Algorithm:  sim2 
## Observed Index:  1721 
## Mean Of Simulated Index:  1671.1 
## Variance Of Simulated Index:  356.2 
## Lower 95% (1-tail):  1637 
## Upper 95% (1-tail):  1700 
## Lower 95% (2-tail):  1631 
## Upper 95% (2-tail):  1704 
## Lower-tail P =  0.999 
## Upper-tail P =  0.001 
## Observed metric > 999 simulated metrics 
## Observed metric < 1 simulated metrics 
## Observed metric = 0 simulated metrics 
## Standardized Effect Size (SES):  2.6438
plot(adMod5,type="hist")

plot(adMod5,type="cooc")

V ratio Index

# Run null model with SIM2 algorithm and V ratio index
adMod6 <- cooc_null_model(PA,
                          algo= "sim2",
                          metric="v_ratio",
                          nReps=1000,
                          suppressProg=T)

# Summary and plots
summary(adMod6)
## Time Stamp:  Tue Apr 25 15:05:19 2017 
## Reproducible:  FALSE 
## Number of Replications:  1000 
## Elapsed Time:  2.4 secs 
## Metric:  v_ratio 
## Algorithm:  sim2 
## Observed Index:  1.1394 
## Mean Of Simulated Index:  0.9972 
## Variance Of Simulated Index:  0.1092 
## Lower 95% (1-tail):  0.53168 
## Upper 95% (1-tail):  1.6101 
## Lower 95% (2-tail):  0.47435 
## Upper 95% (2-tail):  1.7474 
## Lower-tail P =  0.697 
## Upper-tail P =  0.313 
## Observed metric > 687 simulated metrics 
## Observed metric < 303 simulated metrics 
## Observed metric = 10 simulated metrics 
## Standardized Effect Size (SES):  0.43033
plot(adMod6,type="hist")

plot(adMod6,type="cooc")

COMBO Index

# Run null model with SIM2 algorithm and COMBO index
adMod7 <- cooc_null_model(PA,
                          algo="sim2",
                          metric="species_combo",
                          nReps=1000,
                          suppressProg=T)

# Summary and plots
summary(adMod7)
## Time Stamp:  Tue Apr 25 15:05:22 2017 
## Reproducible:  FALSE 
## Number of Replications:  1000 
## Elapsed Time:  2.6 secs 
## Metric:  species_combo 
## Algorithm:  sim2 
## Observed Index:  19 
## Mean Of Simulated Index:  19 
## Variance Of Simulated Index:  0 
## Lower 95% (1-tail):  19 
## Upper 95% (1-tail):  19 
## Lower 95% (2-tail):  19 
## Upper 95% (2-tail):  19 
## Lower-tail P =  1 
## Upper-tail P =  1 
## Observed metric > 0 simulated metrics 
## Observed metric < 0 simulated metrics 
## Observed metric = 1000 simulated metrics 
## Standardized Effect Size (SES):  NaN
plot(adMod7,type="hist")

plot(adMod7,type="cooc")