[R-sig-Geo] Problem using trend covariates in predict.ppm (spatstat)

Rolf Turner r.turner at auckland.ac.nz
Wed Mar 25 23:14:54 CET 2015


On 26/03/15 05:32, Rawlins, Barry G. wrote:
> Dear list
>

> I have been successfully forming spatial point pattern models using
the function ppm and a series of covariates stored as im objects:
>
> Example here in which I have a spatial point pattern object
"CI_pipe_40_spp" and a covariate "cov_CI_len"
>
> mod2<-ppm(CI_pipe40_spp, trend=~cov_CI_len,
covariates=list(cov_CI_len)) # this works fine giving me a ppm model
> summary(mod2)
>
> Point process model Fitting method: maximum likelihood (Berman-Turner
> approximation) Model was fitted using glm() Algorithm converged
> Call: ppm.ppp(Q = CI_pipe40_spp, trend = ~cov_CI_len, covariates =
list(cov_CI_len))
> Edge correction: "border" [border correction distance r = 0 ]
>
> I then want to use the predict function I next write in the same
workspace:
> preds=predict.ppm(mod2,type="trend", window=mask40,ngrid=c(402,402),
> covariates=list(cov_CI_len))
>
> But I get the following error: Error in
> mpl.get.covariates(covariates, list(x = xpredict, y =
ypredict), :
> Each entry in the list 'covariates' should be an image, a function,
> a
window, a tessellation or a single number
>
> But if I check the class of "cov_CI_len": class(cov_CI_len) [1] "im"
>
>
> Which shows that this object is an image. Can someone suggest what
> is
wrong here? The
>
> The help says "If covariates is a list of images, then the names of
the entries should correspond to the names of covariates in the model
formula trend."
> I think I have the code correct - can anyone help with this?

I think that the problem is that you do not *name* the covariate in the 
list that you supply to predict.  The error message is less informative 
than it might be, I guess.

I believe that

     preds=predict.ppm(mod2,type="trend", window=mask40,ngrid=c(402,402),
                   covariates=list(cov_CI_len=cov_CI_len))

should work.

BTW, what version of spatstat are you using?  The syntax of your calls 
is unnecessarily cumbersome, and many aspects of it could be simplified 
considerably, particularly with recent versions of spatstat:

     mmm <- ppm(CI_pipe_40_spp ~ cov_CI_len)
     prd <- predict(mmm,window=mask40,ngrid=402)

I.e. there is no longer any need to specify "covariates" (the newer 
usage is "data" rather than "covariates", although the older usage still 
works) if the covariate in question is in your global environment/workspace.

Also there is no need to to type "predict.ppm"; the *generic* predict() 
automatically dispatches to the *method* predict.ppm().

Also there is no need to specify 'type="trend"' for a Poisson model.

Also ngrid=c(402,402) is equivalent to ngrid=402.

HTH

cheers,

Rolf Turner

-- 
Rolf Turner
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276
Home phone: +64-9-480-4619



More information about the R-sig-Geo mailing list