I need to calculate the integral of the O ring statistic, and I do not see any available package to use in Rstudio that can provide me with this value.
For example, here is the O ring statistic plot for a given landscape.
To calculate this I first generate a landscape, and then use spatialEco package to generate the graph. I also include the Ripley's K plot below.
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)
plot1<-Kest(landscape)
plot(plot1)
I do not know of a method in which I can calculate the area under this curve (this was made using the "spatialEco" package).
However, I understand that the O ring statistic is $\frac{dK(r)}{dr}\frac{1}{2 \pi r}\lambda$ With r representing distance from a point, lambda being the intensity of the pattern and K representing the Ripley's K function.
My background is not in mathematics, so my mathematics is probably wrong, but the integral of the O ring statistic would be $K(r)\frac{ln(r)}{2\pi}\lambda r$
So for example, using a different package, spatstat, I can calculate the Ripley's K function for the same landscape.
I assume that the Ripley's K function part of the above equation is the difference between the edge corrected Ripley's K (such as the Isotropic line). In spatstat, it is possible to isolate the values given in the Ripley's K plot. So for example, if we use the value of Ripley's K iso at r =500, which is 968128.9, and the theoretical distribution which is 785398.2, then their difference is 182730.2.
So the integral of the O-ring statistic between 0 and 500 would be:
$182730.2 \frac{ln(500)}{2\pi}500\lambda$
I do not know how to calculate the intensity of the pattern, but is this a correct assumption? If not, what is the correct assumption and would you know how to calculate the integral of the O-ring statistic?
Many thanks for taking the time to read my question, and even more so if you have any suggestions. It is greatly appreciated.