# compute envelope for isar around sp_44
data(SF)
data(SFtraits)
data(SFphylotree)
# 1) Create a list with simulations of the focal species point pattern with simulador2()
# or by hand. # Beware that each simulated ppp should be marked (with the mark
# of the focal species)
# Example for simulations of an inomogenous PP
# Adjust an IPP:
sp_44.ipp<- density.ppp(unmark(SF[SF$marks$species=="sp_44"]))
# simulate 19 realizations of the adjusted IPP
# (BEWARE: in real tests you should use 199 or higher)
sp_44.ipp.sim <- vector(mode="list", le=19)
sp_44.ipp.sim <- lapply(sp_44.ipp.sim, function(x) x=rpoispp(sp_44.ipp))
# mark each simulated pattern
sp_44.ipp.sim.m <- lapply(sp_44.ipp.sim, function(x)
{marks(x) = factor(rep("sp_44", x$n)); return(x)})
# 2) compute.envelopes
# ISAR
isar.sp_44.ipp.env<- envelope4idar(mippp=SF, mippp.sp.sim= sp_44.ipp.sim.m,
mimark="sp_44", namesmark="species",r=1:30, buffer=0)
if (FALSE) {
# IFDAR
ifdar.sp_44.ipp.env<- envelope4idar(mippp=SF, mippp.sp.sim= sp_44.ipp.sim.m,
mimark="sp_44", namesmark="species", r=1:30, idar="ifdar", buffer=0,
traits=SFtraits, correct.trait.na=TRUE)
#IPSVAR
ipsvar.sp_44.ipp.env<- envelope4idar(mippp=SF, mippp.sp.sim= sp_44.ipp.sim.m,
mimark="sp_44", namesmark="species", r=1:30, idar="ipsvar", buffer=0,
tree=SFphylotree)
####################################
# Computing CROSS_IDAR
#--------------------------------------------------
# You need a focal pattern that its not part of the multivariate pattern which is "measured"
# to estimate diversity.
# For example, let's measure diversity of small trees around large trees of the focal species.
# First, obtain the pattern of large and small trees
# the pattern of small trees will be the "measured" one, i.e., the argument "mippp"
SFlarge<- SF[SF$marks$dbh>=10]
SFsmall <- SF[SF$marks$dbh<10]
# pattern of the focal species (this will be the argument "mippp.sp")
sp_44.large<- SFlarge[SFlarge$marks$species=="sp_44"]
# list of simulated patterns of the focal species (e.g., from an IPP)
sp_44.large.ipp<- density.ppp(sp_44.large)
sp_44.large.ipp.sim <- vector(mode="list", le=99)
sp_44.large.ipp.sim <- lapply(sp_44.large.ipp.sim, function(x) x=rpoispp(sp_44.large.ipp))
# COMPUTE envelopes for cross-ISAR(r)
isar.sp_44.large.cross.ipp.env<- envelope4idar(mippp=SFsmall, r=1:30, buffer=0,
mippp.sp.sim= sp_44.large.ipp.sim, mippp.sp=sp_44.large,
namesmark="species", cross.idar =TRUE)
# COMPUTE envelopes for cross-IFDAR(r)
ifdar.sp_44.large.cross.ipp.env<- envelope4idar(mippp=SFsmall, r=1:30, idar="ifdar",
buffer=0, mippp.sp.sim= sp_44.large.ipp.sim, mippp.sp=sp_44.large,
namesmark="species", traits=SFtraits, correct.trait.na=TRUE,
cross.idar =TRUE)
# COMPUTE envelopes for cross-IPSVAR(r)
ipsvar.sp_44.large.cross.ipp.env<- envelope4idar(mippp=SFsmall, r=1:30, idar="ipsvar",
buffer=0, mippp.sp.sim= sp_44.large.ipp.sim, mippp.sp=sp_44.large,
namesmark="species", tree=SFphylotree, cross.idar =TRUE)
####################################
# Comparing the performance of envelope() and envelope4idar()
#
#--------------------------------------------------
require(ecespa) # for the ipc.estK() function
data(SF)
SFsp<- unmark(SF)
marks(SFsp)<- SF$marks$species
sp_44.ppp<-unmark(SF[SF$marks$species=="sp_44"])
sp_44.pc<- ipc.estK(sp_44.ppp)
# use multifocalsimulator() to use the same simulations with both functions.
sp_44.pc.sim.mf0<-multifocalsimulator(pp=SFsp, mimark="sp_44",
simulate=expression(rIPCP(sp_44.pc)), nsim=99, nmin=sp_44.ppp$n)
# envelopes with function envelope()
gc()
t0<- Sys.time()
ifdar.sp_44.pc.env.e2<- envelope(SFsp, fun=ifdar, mimark="sp_44", traits=SFtraits,
correct.trait.na=TRUE, nsim=99, simulate=sp_44.pc.sim.mf0, r=1:30,
savefuns=TRUE, buffer=0)
Sys.time()-t0
# envelopes with function envelope4idar()
# Here you should input simulated patterns only for the focal species so, first,
# extract it fom the list of simulated multivariate ppp
sp_44.pc.sim.mf00<- lapply(sp_44.pc.sim.mf0, function(x) {x=x[x$marks=="sp_44"];return(x)})
gc()
t0<- Sys.time()
ifdar.sp_44.pc.env2<- envelope4idar(mippp=SF, mippp.sp.sim= sp_44.pc.sim.mf00, mimark="sp_44",
namesmark="species", r=1:30, idar="ifdar", buffer=0,
nsim=99, traits=SFtraits, correct.trait.na=TRUE)
Sys.time()-t0
}
Run the code above in your browser using DataLab