[R-sig-Geo] Coercing character to image

adrian at maths.uwa.edu.au adrian at maths.uwa.edu.au
Thu Jun 26 04:25:15 CEST 2008


Honey Giroday <girodayh at unbc.ca> writes:

> xxx04 <- ppp(x=mpb04$Easting, y=mpb04$Northing, window=tpi1.win)
> dens2004<-density(xxx04)
> save(dens2004, file="dens2003.Rdata")
> dens2004.load<-load("dens2004.Rdata")
> dens2004.im<-as.im(dens2004.load, W=tpi1.win)
>
> fm <- ppm(xxx04, ~x + y + density, Poisson(),
> covariates=list(dens2004.load)

Two problems here.

First, a problem with the use of R. The 'load' command causes a dataset to
be loaded, but it returns only the NAME of the dataset that was loaded. So

> dens2004.load<-load("dens2004.Rdata")

just assigns dens2004.load to have the value 'dens2004'.
Just replace this line by

    load("dens2004.Rdata")

Second, a problem with using the package 'spatstat'.

> fm <- ppm(xxx04, ~x + y + density, Poisson(),
                covariates=list(dens2004.load))

For the model-fitting function 'ppm', the argument 'covariates' should be
a NAMED list, with names that correspond to variables in the model
formula. Your model formula includes the variable name 'density', so the
appropriate command is

fm <- ppm(xxx04, ~x + y + density, Poisson(),
                covariates=list(density=dens2004))

where 'dens2004' is your pixel image.

See the workshop notes available at www.spatstat.org for further examples.

Adrian Baddeley




More information about the R-sig-Geo mailing list