I'm trying to estimate an initial bandwidth value for kernel smoothing my data, calculating the Mean Square Errors (function "mse2d"), but got stuck with an error in a polygon implementation code in function's argument.
I'm following an example in Bivand, Pebesma and Gómez-Rubio (2013, pg. 186) with spatstat Redwood data set, that works fine:
library(spatstat)
library(splancs)
data(redwood)
spred<-as(redwood, "SpatialPoints")
#this is the function that computes the Mean Squared Error of the points
#distribution: mse2d(pts,poly,nsmse, range)
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
Ok. I reproduced this code using my data set. Here is my code with a points subsample that returns the same error:
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)
# matrix of coordinates
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))
Error in storage.mode(poly) <- "double" : argument "poly" missing, without pattern
Actually, I translated the error message to english, don't know if it's exactly like this.
As you see, my code reproduced the structure in the book, but I keep getting errors with this "poly" argument. I tried to learn to construct polygons in splancs package, but couldn't figure out how and didn't find any documentation about this. After searching the net, I also tried to place "owin" objects and matrices instead of a list at the "poly" argument, but neither worked out.
I'd appreciate ANY comments or help. Thank you all in advance.
Leila