[R-sig-Geo] Using an image, produced via the predict.ppm() command, as a covariate in a ppm

Honey-Marie de la Giroday honeydelagiroday at gmail.com
Tue Mar 31 19:37:12 CEST 2009


Hi UseRs

I'm an R neophyte working on a Windows XP platform (R v. 2.8.1 and
spatstat v. 1.15-0).  I have created an image using the predict.ppm()
command and a ppp object.  While trying to use that image as a
covariate in another ppm() model fit, I got the following error (Error
in allcovar || want.trend : invalid 'y' type in 'x || y').  The image
produced using the predict() command contains NA values (although I'm
not sure why) and so I thought this might be affecting the
calculation.  However,  I replaced NA values with zeros to see if that
would allow be to fit the final model; however, this did not work.
Has anyone seen this error message before and can they explain what it
might mean.  Please feel free to let me know if I need to provide more
clarification about the problem, data, or produced image.  Thank you
for your time.  Please see the code below.

#Load packages I need
library(spatstat)
library(shapefiles)
library(maptools)
library(foreign)

#Read in point file that will be the response variable (i.e.
susceptible habitat)
haz54321 <- readShapePoints("haz_54321_pt")

#Read in point files that will be used to produce covariate image
surface (i.e. location of monkey infestations)
mpb04 <- readShapePoints("2004")
mpb05 <- readShapePoints("2005")
mpb06 <- readShapePoints("2006")

#Extract X and Y coordinates from ShapePoints
Xhaz <- haz54321$easting
Yhaz <- haz54321$northing

X04 <- mpb04$Easting
Y04 <- mpb04$Northing

X05 <- mpb05$Easting
Y05 <- mpb05$Northing

#Create object window from research area boundary
landform1 <- readAsciiGrid("tpi_utm_sus1.txt", as.image=TRUE)#Canyons
tpi1 <- as.im(landform1)

#Create object window for analysis from one of the susceptibility
datasets (these have been clipped by tpi raster in Arcview but are
slightly smaller that tpi boundary in some areas)
tpi1.win <- as.owin(tpi1)

#Convert ShapePoints to point pattern manually
haz54321 <- ppp(x=haz54321$easting, y=haz54321$northing, window=tpi1.win)
xxx04 <- ppp(x=mpb04$Easting, y=mpb04$Northing, window=tpi1.win)
xxx05 <- ppp(x=mpb05$Easting, y=mpb05$Northing, window=tpi1.win)
xxx06 <- ppp(x=mpb06$Easting, y=mpb06$Northing, window=tpi1.win)

#Read in distance from western edge of dataset
distance <- readAsciiGrid("dist138.txt", as.image=TRUE)

##Fit wave propagation models
fm.wave2004 <- ppm(xxx04, ~ distance + I(distance^2), Poisson(),
covariates=list(distance=distance))
fm.wave2005 <- ppm(xxx05, ~ distance + I(distance^2), Poisson(),
covariates=list(distance=distance))
fm.wave2006 <- ppm(xxx06, ~ distance + I(distance^2), Poisson(),
covariates=list(distance=distance))

#Create image covariate from fit models
wave2004 <- predict.ppm(fm.wave2004)
wave2005 <- predict.ppm(fm.wave2005)
wave2006 <- predict.ppm(fm.wave2006)

#See if habitat also fits a wave-like pattern
fm2 <- ppm(haz54321, ~ wave2004, Poisson(), covariate=c(wave2004=wave2004))
fm3 <- ppm(haz54321, ~ wave2005, Poisson(), covariate=c(wave2005=wave2005))
fm4 <- ppm(haz54321, ~ wave2006, Poisson(), covariate=c(wave2006=wave2006))

#Resulting error message
"Error in allcovar || want.trend : invalid 'y' type in 'x || y'"


 --
 Sincerely,





Honey-Marie de la Giroday



More information about the R-sig-Geo mailing list