1
votes

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!

2
This does not look like a complete description of how to set up the conditions to run this code. - IRTFM

2 Answers

0
votes


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
0
votes

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.