[R-sig-Geo] categorical values in im-objects (spatstat/ppm)

Silvia Cordero-Sancho corderos at umich.edu
Mon Mar 9 23:02:33 CET 2015


Hello,

I will like to fit a point process model (ppm) with several covariates. One
of them is a grid with 15 categorical variables (zones).

To recognized the values in my grid as categorical, I followed the code in
the following link:

http://stackoverflow.com/questions/26162955/r-package-spatstat-how-to-use-point-process-model-covariate-as-factor-when-pixe?answertab=active#tab-top




*zone1<-eval.im <http://eval.im>(as.factor(zone))*

*levels(zone1)<-c("A1","A2","A3","A4","B1","B2","B3","B4",*
*              "C1","C2","C3","C4","C5","C6","D")*

*unitname(zone1)<-c("meter","meters")*

But I am not sure if it really worked. If I run the function
*is.factor(zone1)*, the result is FALSE, but if I run the function
selecting any column or row (e.g. *is.factor(zone1[1,])* or
*is.factor(zone1[,200])*) the results show as TRUE.

However, the function *summary(zone1)* indicates that it is a factor value
pixel image:

factor-valued pixel image
2641 x 680 pixel array (ny, nx)
enclosing rectangle: [992380, 1012780] x [732491, 811721] meters
dimensions of each pixel: 30 x 30 meters
Image is defined on a subset of the rectangular grid
Subset area = 1577529000 square meters
* Pixel values (inside window):

 A1     A2     A3     A4     B1     B2     B3     B4     C1     C2     C3
  C4     C5     C6    D
116928   5670  16614   6823  27917   7547    197   9354 132658 405515
1016 136784 576913 113978 194896

* *The distribution of the number of cells per zone is the same than the
original file *

However, when I used the layer within the ppm function, not all the
categories are included in the analysis:

*m1<-ppm(ag4u,~Z, covariates=list(Z=zone1), AreaInter(200))*

*coef(summary(m1))*

               Estimate
(Intercept) -16.4787854
ZA3           2.6334407
ZA4           1.4900159
ZB1           0.6177496
ZB2           0.3502884
ZB4           1.4179890
ZC1          -2.0643563
ZC2          -0.6806136
ZC4          -0.1897898
ZC5          -2.8285278
ZC6           1.5300109
ZD            2.1210203
Interaction   2.4118998

The zones identified as A1, A2, B3, C3 are excluded from the analysis

Similarly, I get the same results when I used the following expression:

*m2<-ppm(ag4u,~factor(Z),covariates=list(Z=zone),  AreaInter(200)) *

And the following error when I tried to plot the residuals...

*qqplot.ppm(m1,nsim=100,verbose=F)*

Error in model.frame.default(Terms, newdata, na.action = na.action, xlev =
object$xlevels) :
  factor Z has new levels A2, C3

So, I think that the problem could be associated with functions I am
employing to assign the factor-values. Is this is the problem, i*s there an
alternative to define categorical values for im-objects? Or, it could be
other reason for the exclusion of categories?*

I will appreciate any advise.

Silvia Cordero

Only in case, here a link with the data
https://www.dropbox.com/sh/7t9ga3lmsx9ub0y/AACegUGCwXq6F7Gxn3elcBU9a?dl=0

	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list