User Tools

Site Tools


cs:data:simul-spatial:script

Skript pro vytvoření prostorově strukturovaných ekologických dat

# install.packages("packfor", repos="http://R-Forge.R-project.org") # install packfor from r-forge (only for the last version of R)
# install.packages(c('vegan', 'permute'))
install.packages ('neutral.vp', contriburl = 'http://www.davidzeleny.net/anadat-r/data-download') # install compiled neutral.vp library from this website (R version 2.15)
 
library (packfor)
library (neutral.vp)
library (ade4)
 
topo <- read.delim ('http://bit.ly/V9sGF1')  # reads topo data, which are the template for environmental characteristics
 
# NOTE: the simulation may be time demanding!
 
# the first model - dispersal rate is low (u = 0.2)
neut.topo <- neut.simulate(M = 100, K = 500, S = 50, m = 0.005, b = 0.505, d = 0.500, 
                      u = 0.2, sel = 990, time = 500, cycles = 3, 
                      habitat = topo, fitness = rep(1:10, length = 50))
 
# the second model - dispersal rate is high (u = 0.7)
neut.topo.disp <- neut.simulate(M = 100, K = 500, S = 50, m = 0.005, b = 0.505, d = 0.500, 
                      u = 0.7, sel = 990, time = 500, cycles = 3, 
                      habitat = topo, fitness = rep(1:10, length = 50))
 

O úspěšnosti simulace se můžeme přesvědčit tak, že na získaných druhových datech (po aplikaci Hellingerovi standardizace) provedeme PCA a skóre na první ose promítneme do obrázku krajiny:

par (mfrow = c (2,3))
index.cut <- sim.cut (neut.topo, fact = 1)
image (matrix (rda (decostand (census (neut.topo, snap = 2)[index.cut,], 'hell'))$CA$u[,1], ncol = 100), main = 'Low dispersal, cycle 2')
image (matrix (rda (decostand (census (neut.topo, snap = 3)[index.cut,], 'hell'))$CA$u[,1], ncol = 100), main = 'Low dispersal, cycle 3')
image (matrix (rda (decostand (census (neut.topo, snap = 4)[index.cut,], 'hell'))$CA$u[,1], ncol = 100), main = 'Low dispersal, cycle 4')
image (matrix (rda (decostand (census (neut.topo.disp, snap = 2)[index.cut,], 'hell'))$CA$u[,1], ncol = 100), main = 'High dispersal, cycle 2')
image (matrix (rda (decostand (census (neut.topo.disp, snap = 3)[index.cut,], 'hell'))$CA$u[,1], ncol = 100), main = 'High dispersal, cycle 3')
image (matrix (rda (decostand (census (neut.topo.disp, snap = 4)[index.cut,], 'hell'))$CA$u[,1], ncol = 100), main = 'High dispersal, cycle 4')

Následuje skript pro přípravu matic druhy x vzorky, prostorových koordinát a proměnné prostředí:

index.cut.8 <- sim.cut (neut.topo, fact = 8)
low.disp.spe <- census (neut.topo)[index.cut.8,]
high.disp.spe <- census (neut.topo.disp)[index.cut.8,]
 
env <- as.vector (as.matrix (topo))[index.cut.8]
coord <- neut.topo$coo[index.cut.8,c('X', 'Y')]
 
write.table (low.disp.spe, 'low-disp-spe.txt', sep = '\t')
write.table (high.disp.spe, 'high-disp-spe.txt', sep = '\t')
write.table (env, 'env-spatial-model.txt', sep = '\t')
write.table (coord, 'coord-spatial-model.txt', sep = '\t')

Ukázka použití - výpočet PCNM

# read data
low.disp.spe <- read.delim ('http://www.davidzeleny.net/anadat-r/lib/exe/fetch.php?media=data:low-disp-spe.txt')
high.disp.spe <- read.delim ('http://www.davidzeleny.net/anadat-r/lib/exe/fetch.php?media=data:high-disp-spe.txt')
env <- read.delim ('http://www.davidzeleny.net/anadat-r/lib/exe/fetch.php?media=data:env-spatial-model.txt')
coord <- read.delim ('http://www.davidzeleny.net/anadat-r/lib/exe/fetch.php?media=data:coord-spatial-model.txt')
 
 
#install.packages("PCNM", repos="http://R-Forge.R-project.org")  # works ONLY FOR THE LATEST R VERSION
library (PCNM)
neut.pcnm <- PCNM (dist (coord))
neut.pcnm_n <- neut.pcnm$vectors[, which(neut.pcnm$Moran_I$Positive)]
 
vp.low <- varpart (decostand (low.disp.spe, 'hell'), env, neut.pcnm_n)
vp.high <- varpart (decostand (high.disp.spe, 'hell'), env, neut.pcnm_n)
 
par (mfrow = c(1,2))
plot (vp.low)
title (main = 'Low dispersal')
plot (vp.high)
title (main = 'High dispersal')

cs/data/simul-spatial/script.txt · Last modified: 2017/10/11 20:36 (external edit)