0

I am using spatstat to run Kcross: Multitype K Function (Cross-type). Here is my data set and here is the script plotting K Cross

df <- read.csv(file = "trees_rocks.csv")
df.test <- filter(df, Class %in% c("TREE", "ROCK"))

x.range <- range(df.test$coord_x)
y.range <- range(df.test$coord_y)

test.ppp <- ppp(
  df.test$coord_x, df.test$coord_y,
  x.range, y.range, marks = factor(df.test$Class))

plot(envelope(test.ppp, Kcross, nsim = 10), xlim = c(0, 100))

The graph nicely illustrates the degree of clustering. However, I would get more precise information from the graph. How can I get the area under the curve? More precisely, how can I calculate the area between the red dashed line and the black solid line?

I tried to figure out how to run auc() (LINK) but since I don't have any covariate, I don't know how to proceed.

Thank you all in advance!

Wolfgang
  • 55
  • 1
  • 6

1 Answers1

1

The area under the K-function curve is not an example of the AUC (which is the area under the Receiver Operating Characteristic curve ROC). It does not have a statistical interpretation that I can think of.

However, the result of Kcross is an object of class fv for which you can easily do calculations using with.fv. To get the area between the empirical isotropic estimate (black) and the theoretical value (red) you could do

K <- Kcross(........)
a <- with(K, sum(diff(r) * (abs(theo-iso)[-1])))

Objects of class envelope can also be used in the same way. You just need to identify the tag name of the relevant curves that you want, which you can do by just printing the fv or envelope object.

Adrian Baddeley
  • 2,534
  • 1
  • 5
  • 8
  • Sorry for my ignorance! I really don't understand what your description after your script! Would you mind clarifying? – Wolfgang Nov 17 '22 at 11:33
  • 1
    In my code example, the variable names `iso` and `theo` are names of columns in the `fv` object `K` which are plotted as curves when `K` is plotted. Simply by printing `K` (just type `K` and return) you will see a list of the column names and their meanings, and you can use this to select the columns (curves) that you want to compare. – Adrian Baddeley Nov 18 '22 at 00:41