Shawn Brar
Shawn Brar

Reputation: 1420

Create a tessalation object

In this dataset there is a data.frame called Emergencies and owin called Region. With these two objects, an object of class ppp can be created using the following code:-

data <- ppp(x = Emergencies$X, y = Emergencies$Y, window = Region)

What I wanted to do was to see if the intensity depended on the workload of the emergencies. The workload of the emergencies is in Emergencies$M column. For this I need to create a tess object and use the quadrat.test function to test this hypothesis.

But I am unable to create a tess object since it will only take objects of im, owin and tiles.

Can someone please help me in creating this tess object?

Thanks in advance.

Upvotes: 0

Views: 124

Answers (1)

Adrian Baddeley
Adrian Baddeley

Reputation: 1984

A tessellation is a division of space into pieces (tiles). There are many tools in the spatstat package to construct tessellations from other data (open the help for tess and follow the links under See Also). But .. it's unclear what tessellation you want, or what information you want to convert into a tessellation.

You say you want to use quadrat.test. Why? This performs a chi-squared test based on quadrat counting, so the null hypothesis is that the intensity of emergencies is constant in each tile - which doesn't make sense to me (whatever choice of tiles you make), because the points seem to be highly concentrated in the centre of the region.

Thank you for attaching your data. The data frame Emergencies gives spatial locations X, Y and the corresponding values of two other quantities M and T. I presume that each row of the data frame corresponds to one emergency (and not, for example, one hospital or one ambulance). From your description it is unclear whether the variable M represents (a) the workload associated with that emergency, or (b) the total workload of some system at the time of that emergency.

If it's (a), then what you are dealing with is a marked point pattern in which each point event location is augmented by extra information called a mark. This marked point pattern should be created by

Z <- ppp(Emergencies$X, Emergencies$Y, window=Region, marks=Emergencies[,c("M", "T")])

or more lazily

Z <- as.ppp(Emergencies, W=Region)

Then you want to know whether the intensity of this marked point pattern depends on the value of the mark M. Here is how I would do it. First, throw away the T column:

ZM <- subset(Z, select=M)  

Now divide the values of M into five bands (for example):

ZC <- cut(ZM, breaks=c(0, 100, 200, 500, 1000, Inf)) 

Look at them:

plot(ZC, cols=2:6)
plot(split(ZC))

The coordinates are large numbers. For numerical stability, let us rescale them to manageable values:

ZCS <- shift(rescale(ZC, 1000), origin="midpoint")

Now fit some models:

fit1 <- ppm(ZCS ~ marks * polynom(x,y,2))
fit0 <- ppm(ZCS ~ marks + polynom(x,y,2))

These two models state that the intensity is a log-quadratic function of the spatial coordinates. The full model fit1 allows the intensity to depend also on the M value, while the additive model fit0 says that the intensity does not depend on the M value apart from a constant term (which is needed to account for the different numbers of emergencies in each band). To see the fitted intensity functions, do plot(predict(fit1)) and so on.

Then we can simply perform a likelihood ratio test:

anova(fit0, fit1, test="Chi")

The output gives a highly significant test result, suggesting that the intensity function is different for different values of M.

This is not the quadrat counting chi-squared test that you wanted, but the likelihood ratio test is a more powerful test (in the technical sense).

Upvotes: 2

Related Questions