title: Mean Square Error (MSE) function argument "poly"
body: <p>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. </p>
  
  <p>I'm following an example in Bivand, Pebesma and Gómez-Rubio (2013, pg. 186) with spatstat Redwood data set, that works fine: </p>
  
  <pre><code>library(spatstat)
  library(splancs)
  data(redwood)
  spred&lt;-as(redwood, "SpatialPoints")
  
  #this is the function that computes the Mean Squared Error of the points
  #distribution: mse2d(pts,poly,nsmse, range)
  mserwq &lt;- mse2d(as.points(coordinates(spred)), as.points(list(x = c(0,1, 1, 0), y = c(0, 0, 1, 1))), 100, 0.15)
  bwq &lt;- mserwq$h[which.min(mserwq$mse)]
  bwq
  </code></pre>
  
  <p>Ok. I reproduced this code using my data set. Here  is my code with a points subsample that returns the same error:</p>
  
  <pre><code>m23.Xs&lt;-c(17349,13212,11551,16659,9461,12062,12802,9638,9835,9803)
  m23.Ys&lt;-c(576,13600,6372,11763,11081,5462,15802,11667,11552,11121)
  # matrix of coordinates
  loc23&lt;-matrix(c(m23.Xs,m23.Ys),nrow=10,byrow=FALSE) 
  
  MSEm23&lt;-mse2d(as.points(coodinates(loc.m23),as.points(list(x=c(0,20000,20000,0),y=c(0,0,20000,20000))),100,0.15))
  </code></pre>
  
  <p><code>Error in storage.mode(poly) &lt;- "double" : argument "poly" missing, without pattern</code></p>
  
  <p>Actually, I translated the error message to english, don't know if it's exactly like this. </p>
  
  <p>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.</p>
  
  <p>I'd appreciate ANY comments or help.
  Thank you all in advance.</p>
  
  <p>Leila</p>