
Draw a systematic sample from a SpatialPoints*
object or a data.frame
.
SpatialPoints*
objects can represent point resources in 2-dimensional space, such as towns, event locations,
or grid cell centers.
sss.point(x, n)
A SpatialLines
, SpatialLinesDataFrame
, or data.frame
object.
Sample size. Number of points to draw from the set of all points
in x
. If n
exceeds the number of units (= number of rows in data.frame(x)
),
a census is taken (i.e., x
is returned).
If input x
inherits from a the SpatialPointsDataFrame
class, a
SpatialPointsDataFrame
object containing locations in the sample is returned.
If input x
is a data.frame
, a data.frame
is returned.
Attributes of the returned sample points are:
sampleID
: A unique identifier for every sample point.
sampleID
starts with 1 at the first point and
increments by one for each.
If x
inherits from SpatialPoints
,
returned points have attribute geometryID
-- the ID (= row.names(x)
) of
the sampled point.
Any attributes (columns) associated with the input points (rows).
Additional attributes of the output object are:
frame
: Name of the input sampling frame (i.e., x
).
frame.type
: Type of resource in sampling frame. (i.e., "point").
sample.type
: Type of sample drawn. (i.e., "SSS").
random.start
: The random start for the systematic sample.
Using these additional attributes, one could reconstruct the sample.
The points in x
are systematically sampled in the order
they appear. That is, the sampling frame (i.e., data.frame(x)
) is
not re-ordered prior to sampling. Each row in the frame represents
a point or sample unit, and rows are sampled systematically starting with row 1.
To draw a systematic sample across the range of an attribute, say attribute x
by sss.point( x[order(x$y),], n )
).
This routine draws fixed size systematic samples. Many systematic sampling procedure produce variable size samples. Conceptually, the sample procedure is:
Each sample unit (= row of sample frame) is associated with a line segment. Assuming there
are nrow(x)
), each line segment has length
Line segments are placed end-to-end, starting at 0, in the order in which their associated unit appears in the frame.
To start the systematic sample, the routine chooses a random number between 0 and 1.
Let this random number be
The sample units associated with the line segments containing the numbers
# NOT RUN {
# Draw systematic sample across range of population
WA.samp <- sss.point( WA.cities[order(WA.cities$POP_2010),], 100 )
plot( WA.cities )
points( WA.samp, col="red", pch=16 )
# Draw systematic sample from data frame
df <- data.frame( a=1:100, b=runif(100) )
samp <- sss.point( df, 5 )
# Equivalent to simple random sample: randomly sort frame.
samp <- sss.point( df[order(df$b),], 5 )
# }
Run the code above in your browser using DataLab