humboldt.niche.overlap: Measure niche similarity

humboldt.niche.overlapR Documentation

Measure niche similarity

Description

Measure niche similarity

Usage

humboldt.niche.overlap(z1, z2, correct.env = F, nae = "NO",
  thresh.espace.z = 0.001)

Arguments

z1

a grid of the density of a species occurrence in environmental space output from humboldt.grid.espace

z2

a grid of the density of a second species occurrence in environmental space output from humboldt.grid.espace that you wish to compared to z1

correct.env

if correct.env=T, the analysis corrects occurrence densities of each species by the prevalence of the environments in their range. If correct.env=F, the overlap measure does not correct occurrence densities of each species by the prevalence of the environments in their range

nae

do you include non-analogous environments in the niche similarity measurement? If nae="NO" (use capital letters), then non-analogous environments will be removed from both input environments during overlap measurement and only environments present in both will be used to measure overlap. If nae="YES" then no change will be made to input z1 and z2.

Note: this is separate from trimming non-analogous environments from your input dataset (as done by humboldt.g2 specified by parameter non.analogous.environments). The latter parameter physically removes non-analogous environments from datasets pre-niche similarity measurement. Technically the removal of non-analogous environments via either way should result in similar overlap measurements (though they may not be identical). This because removing non-analogous environmental from the dataset prior to gridding environments will resulting only non-analogous environments to be gridded (and typically finer grain applied to each grid cell). Whereas removing them only via this parameter (nae), which only removes non-analogous in the gridded environmental space for use in overlap measurements,— all the input environmental space is gridded (likely increasing the environmental space per gridded cell).

A second cause of differences in values can result from rescaling of espace values during niche-overlap measurements so that the sum of the landscape equals one. If occupied, non-analogous environments are numerous in one of the datasets, this can theoretically cause overlap values to decrease in analogous environments (vs. non-analogous environments) because differences in gridded niches are rescaled to 1 in both scenarios. The rescaling among fewer cells increases the values applied to highly suitable areas and, if not equivalently scaled in both datasets, differences among niches could increase, resulting a smaller overlap in non-analogous environments (again values should be similar). If you remove non-analogous environments in humboldt.g2e, I also suggest that you use this function (as it can remove any slight anomalies caused by gridding environments in humboldt.grid.clim due to the binning of values in the RxR grid).

thresh.espace.z

this parameter is an experimental parameter and controls the level at which values below the kernel density z values are removed for creating areas of analogous environmental space. Higher values will increase value from which the low-density areas are removed from the environmental space of z1 and z2. Basically values above this are retained and values below are removed. Default=0.001

Value

Compares two z1 and z2 created by humboldt.grid.espace by calculating the overlap metrics: Schoener's D (herein called 'D') and a measure derived from Hellinger called 'I'(herein called 'I'; see Warren et al. 2008 & Broennimann et al. 2012). Both measures are based on two species occurrence density grids z1 and z2 created by humboldt.grid.espace

Output are six items: $D= Schoener's D value, $I= Hellinger's I value, $remaining.espace.per= the remaining espace remaining after removal of non-analogous espace, $num.cells.analog.espace= the number of cells of analogous espace, $num.cells.total.espace= the total number of cells of espace present(both analogous and non-analogus espace)

See Also

humboldt.sample.spp,humboldt.g2e, humboldt.equivalency.test, humboldt.background.test, humboldt.plot.niche, humboldt.doitall which use or depend on outputs of this function

Examples

#######################################################################################
###################################    EXAMPLE 1    ###################################
#######################################################################################
library(humboldt)

##load environmental variables for all sites of the study area 1 (env1). Column names should be x,y,X1,X2,...,Xn)
env1<-read.delim("env1.txt",h=T,sep="\t")

## load environmental variables for all sites of the study area 2 (env2). Column names should be x,y,X1,X2,...,Xn)
env2<-read.delim("env2.txt",h=T,sep="\t") 

## remove NAs and make sure all variables are imported as numbers
env1<-humboldt.scrub.env(env1)
env2<-humboldt.scrub.env(env2)

##load occurrence sites for the species at study area 1 (env1). Column names should be 'sp', 'x','y'
occ.sp1<-na.exclude(read.delim("sp1.txt",h=T,sep="\t"))

##load occurrence sites for the species at study area 2 (env2). Column names should be 'sp', 'x','y'. 
occ.sp2<-na.exclude(read.delim("sp2.txt",h=T,sep="\t"))

##convert geographic space to espace
zz<-humboldt.g2e(env1=env1, env2=env2, sp1=occ.sp1, sp2=occ.sp2, reduce.env = 2, reductype = "PCA", non.analogous.environments = "NO", env.trim= T, e.var=c(3:21),  col.env = e.var, trim.buffer.sp1 = 200, trim.buffer.sp2 = 200, env.pca = T, rarefy.dist = 50, rarefy.units="km", env.reso=0.41666669, kern.smooth = 1, PROJ = F,  R = 100, run.silent = F)

##store espace scores for sp1 and environments 1,2 and both environments combined output from humboldt.g2e
scores.env1<-zz$scores.env1[1:2]
scores.env2<-zz$scores.env2[1:2]
scores.env12<- rbind(zz$scores.env1[1:2],zz$scores.env2[1:2])
scores.sp1<-zz$scores.sp1[1:2]
scores.sp2<-zz$scores.sp2[1:2]

## run create a grid of Environmental Space Function
z1<- humboldt.grid.espace(scores.env12,scores.env1,scores.sp1,kern.smooth=1,R=100)
z2<- humboldt.grid.espace(scores.env12,scores.env2,scores.sp2,kern.smooth=1,R=100)

## mesure niche similarity
humboldt.niche.overlap(z1,z2,correct.env=F)

#######################################################################################
###################################    EXAMPLE 2    ###################################
#######################################################################################
library(humboldt)

##load environmental variables for all sites of the study area 1 (env1). Column names should be x,y,X1,X2,...,Xn)
env1<-read.delim("env1.txt",h=T,sep="\t")

## load environmental variables for all sites of the study area 2 (env2). Column names should be x,y,X1,X2,...,Xn)
env2<-read.delim("env2.txt",h=T,sep="\t") 

## remove NAs and make sure all variables are imported as numbers
env1<-humboldt.scrub.env(env1)
env2<-humboldt.scrub.env(env2)

##merge environment files
env12<-rbind(env1,env2)

##load occurrence sites for the species at study area 1. Column names should be 'sp', 'x','y'
occ.sp1<-na.exclude(read.delim("sp1.txt",h=T,sep="\t"))

##load occurrence sites for the species at study area 2. Column names should be 'sp', 'x','y'
occ.sp2<-na.exclude(read.delim("sp2.txt",h=T,sep="\t"))

##remove occurrences closer than a minimum distance to each other (remove aggregation). Setting min.dist=0 will remove no occurrence.
occ.sp1<-humboldt.occ.rarefy(in.pts=occ.sp1,colxy=2:3, rarefy.dist=40,rarefy.units="km")
occ.sp2<-humboldt.occ.rarefy(in.pts=occ.sp2,colxy=2:3, rarefy.dist=40,rarefy.units="km")

##sample environment using humboldt.sample.spp() function
## env.reso should be the resolution of the environmental data grid
occ.sp1<-na.exclude(humboldt.sample.spp(dfsp=occ.sp1,colspxy=2:3,colspkept=NULL,dfvar=env1,colvarxy=1:2,colvar="all",resolution=0.16667))
occ.sp2<-na.exclude(humboldt.sample.spp(dfsp=occ.sp2,colspxy=2:3,colspkept=NULL,dfvar=env2,colvarxy=1:2,colvar="all",resolution=0.16667))

##row weighting of environment density for PCA
row.w.1.env<-1-(nrow(env1)/nrow(env12))  # prevalence of env1
row.w.2.env<-1-(nrow(env2)/nrow(env12))  # prevalence of env2
row.w.env <-c(rep(row.w.1.env, nrow(env1)),rep(row.w.2.env, nrow(env2)),rep(0, nrow(occ.sp1)),rep(0, nrow(occ.sp2)))

##create a global dataset with all environments and species, include environmental variables e.var[x1-xN]
e.var<-c(3:21)
data.env.occ<-rbind(env1,env2,occ.sp1,occ.sp2)[e.var]

##perform PCA of environment and species 1 data which is weighted by density of environment types in both environment 1 and environment 2
pca.cal <-dudi.pca(data.env.occ,row.w = row.w.env, center = T, scale = T, scannf = F, nf = 2)

##store PCA scores for sp1 andenvironments 1,2 and both environments combined
## specific exact locations of environment and sp. data in PCA for storage
row.env1<-1:nrow(env1)
row.env2<-(nrow(env1)+1):(nrow(env1)+nrow(env2))
row.env12<-1:(nrow(env1)+nrow(env2))
row.sp1<-(nrow(env1)+nrow(env2)+1):(nrow(env1)+nrow(env2)+nrow(occ.sp1))
row.sp2<-(nrow(env1)+nrow(env2)+nrow(occ.sp1)+1):(nrow(env1)+nrow(env2)+nrow(occ.sp1)+nrow(occ.sp2))
##glob: global background dataset for the whole study area 
glob<- pca.cal$li[row.env12,]
##glob1: background for sp1
glob1<- pca.cal$li[row.env1,]
##glob2: background for sp2
glob2<- pca.cal$li[row.env2,]
##sp1: occurrence dataset
sp1<- pca.cal$li[row.sp1,]
##sp2: occurrence dataset
sp2<- pca.cal$li[row.sp2,]

## run Create a grid of Environmental Space Function
z1<- humboldt.grid.espace(glob,glob1,sp1,R=100,kern.smooth=1)
z2<- humboldt.grid.espace(glob,glob2,sp2,R=100,kern.smooth=1)
humboldt.niche.overlap(z1,z2,correct.env=F)

jasonleebrown/humboldt documentation built on Jan. 4, 2024, 7:46 a.m.