[R-sig-Geo] how to limit an image or a funxy to an irregular polygonal window, instead of the whole enclosing rectangle?

Christopher W. Ryan cryan at binghamton.edu
Fri Dec 15 23:43:24 CET 2017


Thanks Rolf. I'm going to have to reflect more on my code and my data,
to understand better what is going on.

Obviously this won't help you much, without having access to all my data
and preceeding code, but the error message that is tripping me up is:

> rhohat(m12, pov.f)
Error:  the fitted intensity contains NA values

And yet,

table(is.na(fitted(m12)))
FALSE
  876

The predicted intensity, however, contains many NA values:

table(is.na(predict(m12)$v))
FALSE  TRUE
10379  6005

I try to force predictions only within my window by specifying locations
(which I think requires a binary mask window) but get the same result:

> table(is.na(predict(m12, locations = as.mask(sremsWindow))$v))
FALSE  TRUE
10379  6005

Does rhohat use fitted values (at quadrature points) or predicted values
(on a 128 x 128 pixel grid within the window)? Top of p. 415 in your
book Spatial Point Patterns: Methodology and Applications wtih R seems
to indicate the latter, while the error message from my rhohat command
above speaks of fitted values.  And how is a rectangular 128 x 128 grid
fit in an irregularly-shaped polygonal window?  Maybe that's how NA
predicted values arise--pixels outside an intra-window rectangular grid
but still inside the window?


And I can see now that no residuals from the model are missing:

> table(is.na(residuals(m12)$val))
FALSE
  876

All the NA's in my predicted values *around* my window, but inside the
bounding rectangle, led me down the garden path.

The origin of most of my predictors, such as pov.f, are shapefiles from
the US Census Bureau, with a discrete value of poverty level for each
census tract. So a tesselation of my window, really.  Through much
wrangling (possibly poorly-done) I was able to turn each predictor into
a funxy--therefore they are essentially step functions, constant across
a census tract and with abrupt changes at census tract boundaries.  I
notice that rhohat calls for a continuous covariate. Could that be an
issue?  Although, I have one predictor that is a continuous distfun, and
I get the same error message from rhohat with that.


Thanks.

--Chris Ryan

Rolf Turner wrote:
> set.seed(42)
> X <- runifpoint(20,win=test.window)
> xxx <- ppm(X ~ test.im)
> plot(residuals(xxx))
> # No sign of any missing values.



More information about the R-sig-Geo mailing list