0

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

rawr
  • 20,481
  • 4
  • 44
  • 78
Leila
  • 1
  • Hi, rawr, I think they are lining up, yes. The first argument, "pts", is as.points(coodinates(loc.m23), the second argument, "poly", is as.points(list(x=c(0,20000,20000,0),y=c(0,0,20000,20000)). This is a list of coordinates for the polygon window, with exactly the same structure as the book example... – Leila Apr 05 '15 at 02:03
  • Thanks for your comment, anyway. Please point me if I'm mistaken. – Leila Apr 05 '15 at 02:06
  • A disclaimer: I just identified a spelling mistake in the code pasted in the message. It's written "coodinates" instead of "coordinates". But this isn't the problem: the error message regarding poly appears with the correct spelling. – Leila Apr 05 '15 at 02:12
  • ah must have copied it wrong, my mistake – rawr Apr 05 '15 at 02:12
  • Hello everyone, a coleague from another forum identified correctly the main problem: the first function as.points was not properly closed. Thanks here to @Molx. – Leila Apr 10 '15 at 03:46

0 Answers0