0

I have 30 datasets that are conbined in a data list. I wanted to analyze spatial point pattern by L function along with randomisation test. Codes are following. The first code works well for a single dataset (data1) but once it is applied to a list of dataset with lapply() function as shown in 2nd code, it gives me a very long error like so,

"Error in Kcross(X, i, j, ...) : No points have mark i = Acoraceae Error in envelopeEngine(X = X, fun = fun, simul = simrecipe, nsim = nsim, : Exceeded maximum number of errors"

Can anybody tell me what is wrong with 2nd code?

 grp <- factor(data1$species)               
 window <- ripras(data1$utmX, data1$utmY)      
 pp.grp <- ppp(data1$utmX, data1$utmY, window=window, marks=grp) 
 L.grp  <- alltypes(pp.grp, Lest, correlation = "Ripley")
 LE.grp <- alltypes(pp.grp, Lcross, nsim = 100, envelope = TRUE)  
 plot(L.grp)
 plot(LE.grp)


 L.LE.sp <- lapply(data.list, function(x) { 
   grp <- factor(x$species)               
   window <- ripras(x$utmX, x$utmY)
   pp.grp <- ppp(x$utmX, x$utmY, window = window, marks = grp)  
   L.grp  <- alltypes(pp.grp, Lest, correlation = "Ripley")
   LE.grp <- alltypes(pp.grp, Lcross, envelope = TRUE)  
   result <- list(L.grp=L.grp, LE.grp=LE.grp)
   return(result)
 })
 plot(L.LE.sp$LE.grp[1])
R starter
  • 197
  • 12
  • It could be one or more data sets inside your list have data issues affecting your process. Try wrapping in the `function` in [`tryCatch`](https://stackoverflow.com/questions/12193779/how-to-write-trycatch-in-r). If you manually run first code with every data frame, does it work without error? – Parfait Mar 16 '19 at 21:16
  • yes, it works for every single data frame. Actually I applied another many functions to this data list successfully. But when I add last function (with envelope) to this lappy() function, this error comes out. So I guess there is something wrong with last function of the code – R starter Mar 17 '19 at 08:53
  • In first code block you use `q1$utmY` for `ripras` but not in `lapply`. – Parfait Mar 17 '19 at 14:59
  • sorry actually q1 is data1. in my original code i named q1. here I converted that name into data1 just to be more clear. – R starter Mar 17 '19 at 16:04
  • In first code you use the arg `nsim = 100` in second call of `alltypes` but not in `lapply`. – Parfait Mar 17 '19 at 17:53

1 Answers1

0

This question is about the R package spatstat.

It would help if you could add a minimal working example including data which demonstrate this problem.

If that is not available, please generate the error on your computer, then type traceback() and capture the output and post it here. This will trace the location of the error.

Without this information, my best guess is the following: The error message says No points have mark i=Acoraceae. That means that the code is expecting a point pattern to include points of type Acoraceae but found that there were none. This can happen because in alltypes(... envelope=TRUE) the code generates random point patterns according to complete spatial randomness. In the simulated patterns, the number of points of type Acoraceae (say) will be random according to a Poisson distribution with a mean equal to the number of points of type Acoraceae in the observed data. If the number of Acoraceae in the actual data is small then there is a reasonable chance that the simulated pattern will contain no Acoraceae at all. This is probably what is causing the error message No points have mark i=Acoraceae.

If this interpretation is correct then you should be able to suppress the error by including the argument fix.marks=TRUE, that is,

alltypes(pp.grp, Lcross, envelope=TRUE, fix.marks=TRUE, nsim=99)

I'm not suggesting this is necessarily appropriate for your application, but this should remove the error message if my guess is correct.

In the latest development version of spatstat, available on github, the code for envelope has been tweaked to detect this error.

Adrian Baddeley
  • 2,534
  • 1
  • 5
  • 8
  • @ Adrian. I wanna make sure what do you mean by "I'm not suggesting this is necessarily appropriate for your application". Should I check CSR by another test? What method do you think appropriate for this? thank you! – R starter Mar 19 '19 at 19:26
  • @ Adrian Baddeley. this error message has been solved but another error "There were 50 or more warnings (use warnings() to see the first 50)" appears – R starter Mar 19 '19 at 20:19