1

I understand the problem is that the function is trying to sum non-finite values and I think I can fix the issue by removing those values from the ppm object, however I'm having a hard time locating all the specific components the function is trying to use.

I've tried looking at the source code on the Github (and in R) to trace the logic backwards, and it looks like it might be a problem for the Kinhom function but I'm having trouble following it all the way back to the PPM object as there are a lot of big intermediary internal functions.

Can anybody point me to the specific component of the PPM object that is causing the error, and perhaps how to remove it? Any help would be greatly appreciated!

Edit: To clarify I know there are two points in the glmdata (4430, 4524) that have undefined covariate values and I suspect they are causing this problem. I added the str() command to show where I suspect the problem value is stored.

Kinhom function Spatstat page on Github https://github.com/spatstat/spatstat/blob/7ee141dc21d945fb35163868b813dbef6ad5dd90/R/Kinhom.R

PPM class object Spatstat page on Github https://github.com/spatstat/spatstat/blob/master/R/ppmclass.R

Here is my ppm model data:

https://www.dropbox.com/sh/ayyozo1dnhbqmvg/AACRqzAu617u0Sq_fk8RqUiJa?dl=0

Just a warning it's a pretty large ppm object (around 40MB)

Here is the code

library(spatstat)
load(file="SamplePPM.RData")
summary(ppm16.reduced2.offset.densavg) # info on the ppm object
Kres(ppm16.reduced2.offset.densavg)
# I suspect the problem value is somewhere in here
str(ppm16.reduced2.offset.densavg$internal$glmfit)

Here was the full error message:

Error in Kwtsum(dIJ[okI], bI[okI], wcIJ[okI], b[Z & USED], rep.int(1, : Weights in K-function were infinite or NA In addition: Warning message: Some infinite, NA or NaN increments were removed

And traceback command:

4: stop("Weights in K-function were infinite or NA") 3: Kwtsum(dIJ[okI], bI[okI], wcIJ[okI], b[Z & USED], rep.int(1, npts.used), breaks) 2: Kcom(object, ...) 1: Kres(ppm16.reduced2.offset.densavg)

Thanks ahead of time!

  • This does not look like a complete description of how to set up the conditions to run this code. – IRTFM Oct 13 '18 at 04:33

2 Answers2

0


I cannot open the downloaded file SamplePPM.RData. Did you try to run traceback() to see where the error originates? Also the actual error message would be useful. The commands and data to fit the model would also be helpful. I think I have recreated the problem with a built-in data example (see below), and if that is the case then you are right that it is caused by NA-values in the covariate. You have no way of fixing the missing covariate values?

library(spatstat)

X <- bei[square(50)]
Z <- bei.extra$elev[square(50)]
Z[square(c(25,50))] <- NA
plot(Z)
plot(X, add = TRUE)

fit <- ppm(X~Z)
#> Warning: Values of the covariate 'Z' were NA or undefined at 19% (202 out
#> of 1056) of the quadrature points. Occurred while executing: ppm.ppp(Q = X,
#> trend = ~Z, data = NULL, interaction = NULL)
Kres(fit)
#> Warning: Some infinite, NA or NaN increments were removed
#> Error in Kwtsum(dIJ[okI], bI[okI], wcIJ[okI], b[Z & USED], rep.int(1, : Weights in K-function were infinite or NA
Ege Rubak
  • 4,347
  • 1
  • 10
  • 18
  • Yes! This example looks like a good recreation of the problem. – Ryan Arellano Oct 16 '18 at 23:28
  • I was hoping I could remove just the two problem values without rerunning the whole ppm model, but I should be able to do that so long as I can correctly identify where the two missing covariates tiles are located. I've never used the traceback command, here is what it produced: > traceback() 4: stop("Weights in K-function were infinite or NA") 3: Kwtsum(dIJ[okI], bI[okI], wcIJ[okI], b[Z & USED], rep.int(1, npts.used), breaks) 2: Kcom(object, ...)
    1: Kres(ppm16.reduced2.offset.densavg)
    – Ryan Arellano Oct 16 '18 at 23:43
  • I updated the file link to a dropbox link. Also, I'm having a bit of trouble finding the problem pixels in my image covariate. The window I'm using is very irregular and the pixel image covariates are large (500x500) so it is difficult to find and precision edit the two problem pixels. Are there any spatstat functions that can remove specific quadrature points from the ppm model? Alternatively, is a way to map the quadrature points' exact locations back to the problem pixels? – Ryan Arellano Oct 17 '18 at 01:44
0

Thanks for drawing our attention to this problem. I will tweak the internal code so that it issues a warning rather than a fatal error.

Adrian Baddeley
  • 1,956
  • 1
  • 8
  • 7
  • And thank you for your contributions to the stats community! I love the work your team is doing. – Ryan Arellano Nov 08 '18 at 03:24
  • Oh and since I have you here I'll ask the question I asked Ege: Are there any spatstat functions that can cleanly remove specific quadrature points from the ppm model? Thanks again! – Ryan Arellano Nov 08 '18 at 03:28