I am attempting to normalize a spatial point pattern using a population density raster in r. My problem is that the function I am trying to run is recognizing the "white space" around the raster I am using as "NA", giving me the error message: Values of the covariate ‘Y’ were NA or undefined at 32% (19493 out of 60241) of the quadrature points. Occurred while executing: ppm.ppp(X, ~offset(log(Y)), covarariates = list(Y)).
Is there a way to create a window or data frame that traces the outline of my raster set? It should be noted that I am a grad student with very limited experience using r.
library(spatstat) library(maptools) library(raster) library(geostatsp) library(rgdal) X <- readShapePoints("~/Documents/Data/Cyber/US/CONTIG_US/CONUS02_FREQ") Y <- raster("~/Documents/Data/Cyber/US/US_POP1.tif") ##Set the extent e <- extent(-125,-67,25, 50) ## create a window for spatstat WIN <- as(e,"SpatialPoints") X.ppp <- as(X, "ppp") ## convert raster to an im object for spatstat Y <- asImRaster(Y) Y <- eval.im((Y)) Y <- as.im(Y) ## Unmark X for model: X<- unmark(X.ppp) Z <- ppm.ppp(X, ~offset(log(Y)), covarariates=list(Y))
The raster plot looks like this: