Virginia Morera Pujol - 1 month ago 10

R Question

I am trying to fit a Geyer model to a point pattern, and I manage to do so without trouble. However, when I want to check the diagnostic plots, I encounter a problem. If I give value "all" to the argument "which" it plots the 4 panels without problem, but when I ask just for the smoothed residual measure (which = "smooth" I get the following error:

`Error in as.vector(rasterx.mask(W)) : `

error in evaluating the argument 'x' in selecting a method for function 'as.vector': Error in validate.mask(w) : w is not a binary mask

Reproducible code follows:

`library(spatstat)`

#generate a pattern

pattern <- rpoispp(300)

#generate a covariate

cov <- rnoise(rgen = rnorm, dimyx=32, mean=2, sd=1, w = pattern$window)

#fit the model

fit <- ppm(pattern ~ cov, Geyer(r = 0.01, s = 0.02))

#plot diagnostics

diag <- diagnose.ppm(fit, type = "pearson", which = "all") #this works

diag <- diagnose.ppm(fit, type = "pearson", which = "smooth") #this doesn't

I have tried with all the options allowed in

`type=`

Any ideas what I might be doing wrong? (I'll asume it's me) or how can I get that smoothed residual any other way?

Answer Source

This is probably a bug in `plot.diagppm`

. I'm currently on Holiday, so I won't take a lot of action right now. I will report the bug on https://github.com/spatstat/spatstat/issues and hopefully Adrian will fix it within too long.

A workaround for now:

```
library(spatstat)
#generate a pattern
pattern <- rpoispp(300)
#generate a covariate
cov <- rnoise(rgen = rnorm, dimyx=32, mean=2, sd=1, w = pattern$window)
#fit the model
fit <- ppm(pattern ~ cov, Geyer(r = 0.01, s = 0.02))
#plot diagnostics
diag <- diagnose.ppm(fit, type = "pearson", which = "smooth", plot.it = FALSE)
s <- diag$smooth$Z
plot(s)
```