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

4

I'm trying to calculate the intensity of a spot pattern with "kernel smooth" (sorry, I do not know how to translate this). Before running smooth kernel code, you must specify a histogram bandwidth for your data. Several different widths are possible, and a common guideline is to calculate the Mean Squared Error (MSE) of the distribution and use the lowest value at the beginning.

A function of the splancs package 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 you want to calculate MSE, and range is the maximum bandwidth size for the MSE.

My problem is the poly argument. How do I specify the script for this polygon? I did not find any guidance in the splancs documentation.

In the book Applied Spatial Data Analysis with R , by 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 am going to 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 can not resolve this error. I have already tried specifying the polygon with an "owin" and array object, and the same error continues. Does anyone know how to specify a polygon in splancs?

Any comment from you will be great. Thanks in advance.

Hugs, Leila

    
asked by anonymous 05.04.2015 / 16:25

1 answer

2

Leila, I encountered three problems in your code:

  • You have defined the variable named loc23 , but then called by name loc.m23

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

  • There is a parenthesis error in your call of the mse2d() function. Note that the second as.points(...) is inside the first, since you only closed a parenthesis, of coordinates .

  • Solving these problems, the code ran and gave me a result similar to the example, you should 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
    
        
    09.04.2015 / 04:27