[R] Warning messages in Splancs package :: no non-missing arguments to min; returning Inf

Barry Rowlingson b.rowlingson at lancaster.ac.uk
Mon Mar 30 09:43:25 CEST 2009


On Mon, Mar 30, 2009 at 7:12 AM, D <eloquence2 at gmail.com> wrote:
> Hi,
>
> I would need some help with the splans package in R.
>
> I am using a Shapefile (downloadable at)
> http://rapidshare.com/files/215206891/Redlands_Crime.zip
>
> and the following execution code
>
>
> setwd("C:\\Documents and
> Settings\\Dejan\\Desktop\\GIS\\assignment6\\DataSet_Redlands_Crime\\Redlands_Crime")
> library(foreign)
> library(splancs)
> auto_xy<-read.dbf("Auto_theft_98.dbf")
> rob_xy<-read.dbf("Robbery_98.dbf")
> auto.spp<-as.points(auto_xy$x/1000, auto_xy$y/1000)
> rob.spp<-as.points(rob_xy$x/1000, rob_xy$y/1000)
> image(kernel2d(auto.spp, bbox(auto.spp), h0=4, nx=100, ny=100),
> col=terrain.colors(10))
> pointmap(auto.spp, col="red", add=TRUE)
>
> I would need to analyze the relationship betweeb the two Shapefiles,
> but I am receiving the following warning message and a blank output
>
>
> Xrange is  1827.026 6796.202
> Yrange is  1853.896 6832.343
> Doing quartic kernel
> Warning messages:
> 1: In min(x) : no non-missing arguments to min; returning Inf
> 2: In max(x) : no non-missing arguments to max; returning -Inf
>
>
> Can someone help me with what am I doing wrong in the execution code?
> I am getting a blank graph.

Well, do some investigation. Does the error come from the kernel2d
function, or from the image function? Does it do that for any data
points? Have you read the help for kernel2d? Have you tried the
example in the help(kernel2d) text? Have you ever had it work? What
version of R are you using and so on. Please read the posting guide.

 The manual for kernel2d says that the second argument has to be "A
splancs polygon data set". But you've given it bbox(auto.spp). But
bbox returns a matrix which is the wrong structure - the columns are
min and max and the rows are X and Y. Plus it only has the corner
points, not all four points of the box which splancs says it needs.
There's also a clue in your output:

 Xrange is  1827.026 6796.202
 Yrange is  1853.896 6832.343

 - but if you plot the points (which you should always do, to make
sure you've read them in properly) you should see that the X range
should be 6796 to 6832 and the Y range should be 1827 to 1853.

 Solution: use the splancs bboxx() function that converts an sp-style
bounding box to a splancs-style bounding box:

 k = kernel2d(auto.spp, bboxx(bbox(auto.spp)), h0=4, nx=100, ny=100)
 image(k)

 Barry




More information about the R-help mailing list