I am using the following Matlab code to estimate Ripley's K function.
a = 0;
b = 50;
C_x = a + (b-a).*rand(100,1);
C_y = a + (b-a).*rand(100,1);
locs = zeros(length(C_x),2);
locs(:,1) = C_x;
locs(:,2) = C_y;
dist = a:1:b;
K_t = RipleysK(locs, dist, [a, b, a, b]);
plot(dist,K_t);
title('$\hat{K}$ function','Interpreter','latex','FontSize',14);
xlabel('$r$','Interpreter','latex','FontSize',14);
ylabel('$\hat{K}(r)$','Interpreter','latex','FontSize',14);
csvwrite('test.csv',locs);
"RipleysK" function can be found at: http://www.colorado.edu/geography/class_homepages/geog_4023_s07/labs/lab10/RipleysK.m
In comparison, I am using the following R script.
mydata <- read.csv("test.csv",header=F)
mydata
w <- owin(xrange = c(0,50),yrange = c(0,50))
pp <- as.ppp(mydata,w)
K <- Kest(pp,correction = "none")
plot(K)
Matlab estimates K for specified values of r (i.e., dist) whereas R script does not (estimates till r = 12.5).
Can somebody comment please? Which one is correct? Can we specify r values in R script?
Thanks