Spatial analysis in R: how to implement a polygon with splancs?

Asked

Viewed 321 times

4

I’m trying to calculate the intensity of a point pattern with "Smooth kernel" (sorry, I don’t know how to translate this). Before executing Smooth kernel code, you need to specify a histogram bandwidth for your data. Several different widths are possible, and a common guideline is to calculate the mean of the square errors ("Mean Squared Error", from now on MSE) of the distribution and use the lowest value at the beginning.

A function of the package splancs to calculate MSE is mse2d(), specified with four arguments:

mse2d(pts,poly,nsmse,range)

being pts the distribution of points, poly a polygon representing the area where the points are, nsmse is the number of histogram bands for which MSE is to be calculated, and range is the maximum bandwidth for MSE.

My problem is the argument poly. How to specify the script for this polygon? I couldn’t find any guidance in the splancs documentation.

In the book Applied Spatial Data Analysis with R, Bivand, Pebesma and Gómez-Rubio (2013), has an example with the data set Redwood of spatstats:

library(spatstat)
data(redwood)
spred<-as(redwood, "SpatialPoints")

library(splancs)
mserwq <- mse2d(as.points(coordinates(spred)), as.points(list(x = c(0,
        + 1, 1, 0), y = c(0, 0, 1, 1))), 100, 0.15)
bwq <- mserwq$h[which.min(mserwq$mse)]
bwq

This example works perfectly. But when I replicate this script with my data it returns an error. See:

#Melocactus data
m23.Xs<-c(17349,13212,11551,16659,9461,12062,12802,9638,9835,9803)
m23.Ys<-c(576,13600,6372,11763,11081,5462,15802,11667,11552,11121)
loc23<-matrix(c(m23.Xs,m23.Ys),nrow=10,byrow=FALSE)
MSEm23<-mse2d(as.points(coodinates(loc.m23),as.points
        +(list(x=c(0,20000,20000,0),y=c(0,0,20000,20000))),100,0.15))

Erro em storage.mode(poly) <- "double" : 
  argumento "poly" ausente, sem padrão

I cannot solve this error. I have tried to specify the polygon with a "owin" object and matrix, and the same error continues. Does anyone know how to specify a polygon in the splancs?

Any comment from you will be great. Thank you for anticipation.

Hugs, Leila

1 answer

2


Leila, I found three problems in your code:

  1. You defined the variable with the name loc23, but then calls his name loc.m23

  2. You called the function coordinates of coodinates, without the letter r.

  3. There’s a parenthesis error in your call of function mse2d(). See that the second as.points(...) is inside the first, because you only closed a parenthesis, of coordinates.

Solving these problems, the code ran and gave me a result similar to the example, which you must know if it is correct.

library(splancs)
m23.Xs<-c(17349,13212,11551,16659,9461,12062,12802,9638,9835,9803)
m23.Ys<-c(576,13600,6372,11763,11081,5462,15802,11667,11552,11121)
loc23<-matrix(c(m23.Xs,m23.Ys),nrow=10,byrow=FALSE)
MSEm23<-mse2d(as.points(coordinates(loc23)),as.points(list(x=c(0,20000,20000,0),y=c(0,0,20000,20000))),100,0.15)

bwq2 <- MSEm23$h[which.min(MSEm23$mse)]
bwq2
[1] 0.15

Browser other questions tagged

You are not signed in. Login or sign up in order to post.