0

I am very new to R and am attempting to determine whether a shape file containing ~500k points is randomly distributed. and I keep getting the same error message no matter what I enter for the arguments.

Here is what I have from the start:

> library(spatstat)

spatstat 1.40-0       (nickname: ‘Do The Maths’) 
For an introduction to spatstat, type ‘beginner’
> as.ppp(area)
marked planar point pattern: 500000 points
Mark variables: 
[1] OBJECTID   Encoded_Ti Time_      Filter     Category   Severity      Action_    Hit_Count  Profile    Encoded_So Source_IP  Source_Por Encoded_De
[14] Dest_IP    Dest_Port  VLAN_Tag   Source_Cou Source_Reg Source_Cit     Source_Lat Source_Lon Dest_Count Dest_Regio Dest_City  Dest_Latit Dest_Longi
window: rectangle = [-159.964, 178.417] x [-46.4, 70.6349] units
Warning message:
some mark values are NA in the point pattern x 
> quadrat.test(area)
Error in UseMethod("quadrat.test") : 
no applicable method for 'quadrat.test' applied to an object of class          "c('SpatialPointsDataFrame', 'SpatialPoints', 'Spatial')"


<bytecode: 0x0000000024e7a660>
<environment: namespace:spatstat>

so my next attempt was:

> X <- ppp(x, y, c(-159.964, 178.417), c(-46.4, 70.6349))
Warning message:
In ppp(x, y, c(-159.964, 178.417), c(-46.4, 70.6349)) :
data contain duplicated points
> quadrat.test(X)
Error in rectquadrat.countEngine(X$x, X$y, tess$xgrid, tess$ygrid) : 
xbreaks do not span the actual range of x coordinates in data

and my final attempts:

> quadrat.test(X, nx = 20, ny = 20)
Error in rectquadrat.countEngine(X$x, X$y, tess$xgrid, tess$ygrid) : 
xbreaks do not span the actual range of x coordinates in data
> quadrat.test(X, nx = 20, ny = 20, xbreaks= NULL, ybreaks = NULL)
Error in rectquadrat.countEngine(X$x, X$y, tess$xgrid, tess$ygrid) : 
xbreaks do not span the actual range of x coordinates in data
> data(X)
Warning message:
In data(X) : data set ‘X’ not found
> quadrat.test(X)
Error in rectquadrat.countEngine(X$x, X$y, tess$xgrid, tess$ygrid) : 
xbreaks do not span the actual range of x coordinates in data
> quadrat.test(X, 10)
Error in rectquadrat.countEngine(X$x, X$y, tess$xgrid, tess$ygrid) : 
xbreaks do not span the actual range of x coordinates in data

Like I said, I am very new at this and have only amateur python experience, but I am a grad student who needs to use this function for a project. Any help would be greatly appreciated.

Cheers

1 Answers1

0

You should be aware that R (almost) never alters your input variable, so you need to assign an output to your commands and work from there. Specifically if area is a variable which can be converted to a ppp object by as.ppp you should give the result a name:

X <- as.ppp(area)

Then you can apply the quadratcount or quadrat.test function to the newly created ppp object:

quadratcount(X, nx=20, ny=20)
quadrat.test(X, nx=20, ny=20)

With ~500k points a 20 by 20 grid for quadrats may seem like a very large spatial scale for the quadrat counting, but that of course depends on your specific setting.

Since you haven't provided a reproducible example I can't say whether or not these commands will work with your setup, but they do work with appropriate data.

Ege Rubak
  • 4,347
  • 1
  • 10
  • 18