SpatialMedian.ppp {spatstat.explore} | R Documentation |
Spatially Weighted Median of Values at Points
Description
Given a spatial point pattern with numeric marks, compute a weighted median of the mark values, with spatially-varying weights that depend on distance to the data points.
Usage
## S3 method for class 'ppp'
SpatialMedian(X, sigma = NULL, ...,
type = 4, at = c("pixels", "points"), leaveoneout = TRUE,
weights = NULL, edge = TRUE, diggle = FALSE, verbose = FALSE)
Arguments
X |
A spatial point pattern (object of class |
sigma |
Smoothing bandwidth, passed to |
... |
Further arguments passed to |
type |
Integer specifying the type of median
(using the convention of |
at |
Character string indicating whether to compute the median
at every pixel of a pixel image ( |
leaveoneout |
Logical value indicating whether to compute a leave-one-out
estimator. Applicable only when |
weights |
Optional vector of numeric weights attached to the points of |
edge , diggle |
Arguments passed to |
verbose |
Logical value specifying whether to print progress reports during the calculation. |
Details
The argument X
should be a spatial point pattern
(object of class "ppp"
) with numeric marks.
The algorithm computes the weighted median of the mark values at each desired spatial location, using spatially-varying weights which depend on distance to the data points.
Suppose the data points are at spatial locations
x_1,\ldots,x_n
and have mark values
y_1,\ldots,y_n
.
For a query location u
, the smoothed median is defined
as the weighted median of the mark values
y_1,\ldots,y_n
with weights
w_1,\ldots,w_n
,
where
w_i = \frac{k(u,x_i)}{\sum_{j=1}^n k(u,x_j)}
where k(u,v)
is the smoothing kernel with bandwidth sigma
If at="points"
and leaveoneout=TRUE
, then
a leave-one-out calculation is performed, which means that
when the query location is a data point x_i
,
the value at the data point is ignored, and
the weighted median is computed from the values y_j
for all j
not equal to i
.
Value
If X
has a single column of marks:
-
If
at="pixels"
(the default), the result is a pixel image (object of class"im"
). -
If
at="points"
, the result is a numeric vector of length equal to the number of points inX
.
If X
has a data frame of marks:
-
If
at="pixels"
(the default), the result is a named list of pixel images (object of class"im"
). There is one image for each column of marks. This list also belongs to the class"solist"
, for which there is a plot method. -
If
at="points"
, the result is a data frame with one row for each point ofX
, and one column for each column of marks. Entries are values of the interpolated function at the points ofX
.
The return value has attributes
"sigma"
and "varcov"
which report the smoothing
bandwidth that was used.
The calculation of the median value depends on the argument
type
which is interpreted in the same way as for
quantile.default
. Currently, only types 1 and 4
are implemented.
If type=1
, the median is always
one of the mark values (one of the values in marks(x)
).
If type=4
(the default),
the median value is obtained by linearly interpolating
between mark values.
Note that the default values of type
in SpatialMedian.ppp
and SpatialQuantile.ppp
are different.
Author(s)
Adrian Baddeley Adrian.Baddeley@curtin.edu.au.
See Also
Generic function SpatialMedian
.
SpatialQuantile
and SpatialQuantile.ppp
for other quantiles.
Smooth.ppp
for the spatially weighted average.
Examples
X <- longleaf
if(!interactive()) {
## mark values rounded to nearest multiple of 10 to reduce check time
marks(X) <- round(marks(X), -1)
}
Z <- SpatialMedian(X, sigma=30)
ZX <- SpatialMedian(X, sigma=30, at="points")