# [R] spatstat regression troubles

Gregory Ryslik rsaber at comcast.net
Sat Apr 16 16:17:20 CEST 2011

Hi Mr. Turner,

You are correct that I am confused a bit by the RCode. Basically, I have 3772 observations of data and only about 500 of them correspond to where "people" exist.  For the other observations, I just have the covariate values so I thought that this was appropriate.  Thus, where "people exist" is my spatial point pattern and everywhere else I just have covariate values.

Thank you for your help and suggestions on how to fit the data. I was able to get it to work using the data frame method but I seem to be having difficulty getting the image thing to work.

Basically, at the moment, I have two matrices for Z1 and Z2 which is in the form of (z, x, y) where z is the value, x is the x-coordinate and y-is the y coordinate. Thus the matrix dimension is 3772x3. I've tried converting this to an image but they do a index swap so I'm not quite sure what the correct  way to do it would be? Hopefully, I would get the fit using the image way and see that the fits are consistent.

Thank you again for your help!

Kind regards,
Greg

On Apr 16, 2011, at 4:46 AM, Rolf Turner wrote:

> On 16/04/11 15:50, Gregory Ryslik wrote:
>> Hi Everyone,
>>
>> I am trying to figure out the spatstat package for the first time and am having some trouble. Unfortunately, I can't post my data set but I'll hopefully post enough details for some help.
>>
>> I want to model the intensity of a spatial point process using 2 covariates from my data. After reading through the documentation, I have successfully created 2 "ppp" objects. The first ppp object is a list of coordinates where people exist and the second is where people do not exist as follows:
>>> people_exist
>>  planar point pattern: 944 points
>> window: rectangle = [73, 135] x [18, 54] units
>>> people_empty
>>  planar point pattern: 2828 points
>> window: rectangle = [73, 135] x [18, 54] units
>>
>> Now, I also have observed values for two covariates, Z1 and Z2 for both the 944 and 2828 points in dataframe form. Finally, following the documentation, I was able to create one quadrature Q, with 944 points and 2828 dummy points that correctly takes the points where we had an event (people_exist) and the points where we don't have an event (people_empty).
>> 944 data points,  2828 dummy points
>> Total weight  1098.64
>>
>> How do I use the Quadrature to model my intensity based off of those two covariates and an intercept term alpha? In mathematical terms, if \lambda is my intensity function, I want to estimate \lambda(s;b) = exp(alpha + b_1 * Z_1 + b_2 * Z_2).
>>
>> Thank you for your help! I really appreciate it.
>
> what you are actually doing.  To start with, one gets the impression that you have
> *two* point patterns ("people" and "no people").  But then, from your quadrature
> scheme it appears that you are treating the "no people" pattern as the dummy
> points for the quadrature scheme.
>
> *Are* they just dummy points, chosen by you in some more or less arbitrary
> manner?  Or are they points of an actual *observed* point pattern?
>
> Assuming that they are indeed dummy points (chosen in a reasonably sensible
> manner) what you need to do is create a data frame of covariate values at each
> of the points of your quadrature scheme.   You indicate that you have the covariate
> values available at each of these points, so that should be alright.
>
> (In respect of "sensible manner" --- 2828 dummy points may be somewhat too
> few.  The default quadrature scheme that ppm() would create would have 4904
> dummy points.)
>
> Anyhow, suppose that you have such a data frame, say "covDf" with two columns
> named "Z1" and "Z2" and with 3772 = 944 + 2828 rows, the i-th row corresponding
> to the i-th point in the quadrature scheme.
>
> You would then execute a command of the form
>
>    fit <- ppm(people_quadrature, ~ Z1 + Z2, covariates=covDf)
>
> See the help on ppm().
>
> Life would be much easier for you if you could build *images* providing the values of
> Z1 and Z2 for a fairly fine pixellation of the observation window.  See the help on im().
> If you have such images, say IZ1 and IZ2, then you can let ppm() take care of creating
> the dummy points and proceed as follows:
>
>    fit <- ppm(people_exist, ~ IZ1 + IZ2, covariates=list(IZ1=IZ1, IZ2=IZ2))
>
> I.e. you just need the real'' point pattern (presumably a point pattern of human
> habitations) and the covariates expressed as (pixellated) images.
>
>    cheers,
>
>        Rolf Turner
>
> P. S. The foregoing all assumes that the pattern of interest is a realization of
> an inhomogeneous ***Poisson*** process, with intensity depending (log linearly)
> upon the two covariates Z1 and Z2.  There could of course be *interaction* between
> the points and the dependence upon covariates could be more complicated than
> that proposed.
>
>        R. T.
>