I need to integrate the area under the curve for the O-ring statistic in Rstudio. However, the package spatialEco does not report the actual values of the O-ring statistic as you would see in the Ripley's K function from the package spatstat. Here is the code to get to the point where I am at.
library('spatstat')
library('ggplot2')
library('spatialEco')
set.seed(seed=24)
radiusCluster<-100
lambdaParent<-.02
lambdaDaughter<-30
hosts<-1000
randmod<-0
dim<-2000
numbparents<-rpois(1,lambdaParent*dim)
xxParent<-runif(numbparents,0+radiusCluster,dim-radiusCluster)
yyParent<-runif(numbparents,0+radiusCluster,dim-radiusCluster)
numbdaughter<-rpois(numbparents,(lambdaDaughter))
sumdaughter<-sum(numbdaughter)
thetaLandscape<-2*pi*runif(sumdaughter)
rho<-radiusCluster*sqrt(runif(sumdaughter))
xx0=rho*cos(thetaLandscape)
yy0=rho*sin(thetaLandscape)
xx<-rep(xxParent,numbdaughter)
yy<-rep(yyParent,numbdaughter)
xx<-xx+xx0
yy<-yy+yy0
cds<-data.frame(xx,yy)
is_outlier<-function(x){
x > dim| x < 0
}
cds<-cds[!(is_outlier(cds$xx)|is_outlier(cds$yy)),]
while (nrow(cds)<hosts){
dif<-hosts-nrow(cds)
extraparentxx<-sample(xxParent,dif,replace = TRUE)
extraparentyy<-sample(yyParent,dif,replace = TRUE)
extrathetaLandscape<-2*pi*runif(dif)
extrarho<-radiusCluster*sqrt(runif(dif))
newextracoodsxx<-extrarho*cos(extrathetaLandscape)
newextracoodsyy<-extrarho*sin(extrathetaLandscape)
extraxx<-extraparentxx+newextracoodsxx
extrayy<-extraparentyy+newextracoodsyy
cdsextra<-data.frame(xx=extraxx,yy=extrayy)
cds<-rbind(cds,cdsextra)
}
sampleselect<-sample(1:nrow(cds),hosts,replace=F)
cds<-cds%>%slice(sampleselect)
randfunction<-function(x){
x<-runif(length(x),0,dim)
}
randselect<-sample(1:nrow(cds),floor(hosts*randmod),replace=F)
cds[randselect,]<-apply(cds[randselect,],1,randfunction)
landscape<-ppp(x=cds$xx,y=cds$yy,window=owin(xrange=c(0,dim),yrange=c(0,dim)))
ggplot(data.frame(landscape))+geom_point(aes(x=x,y=y))+coord_equal()+theme_minimal()
ostat<-o.ring(landscape,inhomogenous=FALSE)
This produces the O-ring plot:
Is it possible to integrate this plot to estimate the area under this curve?