|||
前段时间,有个朋友,问我如何用R解决生态学的部分问题,主要是空间生态学的问题。这对我来说,已经跨行了,后来咨询一位生态学钟博士,他给了一点代码,在此基础上,我做了一些分析。关于spatstat包的中文帖子好像没有,于是,写点用法,供有需要的网友参考。
1 数据读取
library(spatstat) setwd("C:/Users/yzhlin/Desktop/LS") df<-readxl::read_excel("data1.xls", sheet=1,skip=1) df1<-df[,1:12]
2 径级结构
ggplot(df1s,aes(x=Dbh))+ geom_histogram(binwidth=3,color='black',fill='white')
3 空间分布格局
3.1 空间分布点图
sp<-ppp(df1s$Xcoor.60,df1s$Ycoor.60, range(df1s$Xcoor.60),range(df1s$Ycoor.60)) spxy<-data.frame(x=sp$x,y=sp$y) ggplot(spxy,aes(x,y))+geom_point()
3.2 点格局分析
k<-Kest(sp)#最基本的Ripley's K函数 plot(k)
L<-Lest(sp,correction=c( "Ripley","border")) plot(L)
df1sab<-dplyr::filter(df1,Specc %in% c("华润楠", "鹅掌柴")) df1sab$Specc<-as.factor(df1sab$Specc) spab<-ppp(df1sab$Xcoor.60,df1sab$Ycoor.60, range(df1sab$Xcoor.60),range(df1sab$Ycoor.60), marks=df1sab$Specc)
同样,可以使用L函数:
Lab <- Lcross(spab, "华润楠", "鹅掌柴",correction=c( "Ripley","border")) plot(Lab)
k<-Kest(sp) k.pcf <- pcf(k, spar=0.8, method="b") plot(k.pcf)
同样,可以使用L函数:
L<-Lest(sp,correction=c( "Ripley","border")) L.pcf <- pcf(L, spar=0.8, method="b") plot(L.pcf)
amaK <- alltypes(spab, "K") amap <- pcf(amaK, spar=1, method="b") plot(amap)
sp2<-ppp(df1s$Xcoor.60,df1s$Ycoor.60, range(df1s$Xcoor.60),range(df1s$Ycoor.60), marks=df1s$Dbh) mcf <- markcorr(sp2) plot(mcf)
fit0<-ppm(sp ~ 1) # fit the stationary Poisson process dclf.test(fit0, fun = Lest)# CSR model, 99 simulation
运行结果:
## ## Diggle-Cressie-Loosmore-Ford test of CSR ## Monte Carlo test based on 99 simulations ## Summary function: L(r) ## Reference function: theoretical ## Alternative: two.sided ## Interval of distance values: [0, 149.8] ## Test statistic: Integral of squared absolute deviation ## Deviation = observed minus theoretical ## ## data: fit0 ## u = 10107, rank = 1, p-value = 0.01
fit1<-ppm(sp ~ 1, Hardcore()) dclf.test(fit1, fun = Lest)
运行结果:
## ## Diggle-Cressie-Loosmore-Ford test of fitted Gibbs model ## Monte Carlo test based on 99 simulations ## Summary function: L(r) ## Reference function: sample mean ## Alternative: two.sided ## Interval of distance values: [0, 149.8] ## Test statistic: Integral of squared absolute deviation ## Deviation = leave-one-out ## ## data: fit ## u = 9147.1, rank = 1, p-value = 0.01
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2024-11-28 08:35
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社