Home > database >  How to get the best polygon point pattern data in spatstat analysis in R
How to get the best polygon point pattern data in spatstat analysis in R

Time:11-02

I have a dataset of spatial locations original_data

Setting the data for point pattern data

point_pattern_data = ppp(original_data$row, original_data$col, c(0, 77), c(0, 116))
plot(point_pattern_data)
summary(point_pattern_data)

resulting in a plot that looks like this point_pattern

#The observed data has considerably wide white spaces, which I want to remove for a better analysis area. Therefore, I want to make the point pattern a polygon instead of a rectangle. The vertices for the polygon are the pairs of (x,y) below to avoid white space as much as possible.

x = c(3,1,1,0.5,0.5,1,2,2.5,5.5, 16,21,28,26,72,74,76,75,74,63,58,52,47,40)
y = c(116,106,82.5,64,40,35,25,17.5,5,5,5,10,8,116,100,50,30,24,17,10,15,15,8)

I find these vertices above manually by considering the plot below (with the grid lines)

plot(original_data$row,original_data$col)
grid(nx = 40, ny = 25,
 lty = 2,      # Grid line type
 col = "gray", # Grid line color
 lwd = 2)      # Grid line width

plot_grid

So I want to make the point pattern polygon. The code is

my_data_poly = owin(poly = list(x = c(3,1,1,0.5,0.5,1,2,2.5,5.5, 16,21,28,26,72,74,76,75,74,63,58,52,47,40), y = c(116,106,82.5,64,40,35,25,17.5,5,5,5,10,8,116,100,50,30,24,17,10,15,15,8)))
plot(my_data_poly)

but it results in an error. The error is

poly_error

I fix it by

my_data_poly = owin(poly = list(x = c(116,106,82.5,64,40,35,25,17.5,5,5,5,10,8,116,100,50,30,24,17,10,15,15,8), y = c(3,1,1,0.5,0.5,1,2,2.5,5.5, 16,21,28,26,72,74,76,75,74,63,58,52,47,40)))
plot(my_data_poly)

It results in a plot enter image description here

However, this is not what I want. How to get the observed area as a polygon in point pattern data analysis?

CodePudding user response:

This should be a reasonable solution to the problem.

require(sp)

poly = Polygon(
cbind(original_data$col,    
original_data$row)
    ))

This will create a polygon from your points. You can use this document to understand the sp package better

CodePudding user response:

We don’t have access to the point data you read in from file, but if you just want to fix the polygonal window that is not a problem.

You need to traverse the vertices of your polygon sequentially and anti-clockwise. The code connects the first point you give to the next etc. Your vertices are:

library(spatstat)
x = c(3,1,1,0.5,0.5,1,2,2.5,5.5, 16,21,28,26,72,74,76,75,74,63,58,52,47,40)
y = c(116,106,82.5,64,40,35,25,17.5,5,5,5,10,8,116,100,50,30,24,17,10,15,15,8)
vert <- ppp(x, y, window = owin(c(0,80),c(0,120)))
plot.ppp(vert, main = "", show.window = FALSE, chars = NA)
text(vert)

Point number 13 is towards the bottom left and 14 in the top right, which gives the funny crossing in the polygon. Moving the order around seems to help:

xnew <- c(x[1:11], x[13:12], x[23:14])
ynew <- c(y[1:11], y[13:12], y[23:14])
p <- owin(poly = cbind(xnew, ynew))
plot(p, main = "")

It is unclear from your provided plot of the data that you really should apply point pattern analysis. The main assumption underlying point process modelling as implemented in spatstat is that the locations of events (points) are random and the process that generated the random locations is of interest. Your points seem to be on a grid and maybe you need another tool for your analysis. Of course spatstat has a lot of functionality for simply handling and summarising data like this so you may still find useful tools in there.

  • Related