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