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.
# S3 method for ppp
SpatialMedian(X, sigma = NULL, ...,
type = 4, at = c("pixels", "points"), leaveoneout = TRUE,
weights = NULL, edge = TRUE, diggle = FALSE, verbose = FALSE)
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 in X
.
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 of X
,
and one column for each column of marks.
Entries are values of the interpolated function at the points of X
.
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.
A spatial point pattern (object of class "ppp"
)
with numeric marks.
Smoothing bandwidth, passed to density.ppp
.
Further arguments passed to density.ppp
controlling the
spatial smoothing.
Integer specifying the type of median
(using the convention of quantile.default
;
see Details).
Only types 1 and 4 are currently implemented.
Character string indicating whether to compute the median
at every pixel of a pixel image (at="pixels"
, the default)
or at every data point of X
(at="points"
).
Logical value indicating whether to compute a leave-one-out
estimator. Applicable only when at="points"
.
Optional vector of numeric weights attached to the points of X
.
Arguments passed to density.ppp
to
determine the edge correction.
Logical value specifying whether to print progress reports during the calculation.
Adrian Baddeley Adrian.Baddeley@curtin.edu.au.
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\).
Generic function SpatialMedian
.
SpatialQuantile
and SpatialQuantile.ppp
for other quantiles.
Smooth.ppp
for the spatially weighted average.
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")
Run the code above in your browser using DataLab