Read a level, and the region over which it is not distinguishable, off a profile
Source:R/resolution-profile.R
select_resolution.RdPicks the level a criterion prefers, together with the flat region:
every level whose criterion value is within tol of the optimum. On
the criteria this package computes the flat region is routinely wide: the
reliability curve is flat to within 2 percent over a factor of 3–6 in the
number of cells, and \(C_p\) on a smooth field descends to the support
ceiling. The region is the answer, and the argmin only a point in it.
When the optimum sits at an end of the levels the criterion was scored at,
the result says so and names the bound, because a bound is then doing the
choosing rather than the criterion (see
resolution_profile for what each criterion measures and how
it behaved on simulated fields).
Usage
select_resolution(
profile,
criterion = c("cp", "reliability", "elbow", "moran_z"),
tol = 0.02
)Arguments
- profile
A
resolution_profile.- criterion
Which column decides:
"cp"(minimised),"reliability"(maximised),"elbow"(maximised) or"moran_z"(\(|z|\) minimised).- tol
Width of the flat region. For
cpandreliabilityit is relative to the optimum's value (0.02keeps levels within 2 percent of it); forelbowandmoran_z, whose optimum can be zero, it is relative to the criterion's range over the ladder.
Value
A list of class resolution_selection with best (the
level), flat (the levels in the flat region, ascending; a set,
which can skip a rung), criterion, value (the optimum),
at_ceiling and at_floor (logical: the optimum is the last
or first of the levels this criterion was scored at, which for
moran_z starts above nine cells), edge (which bound that
is, in words: the support ceiling, the subsample's ceiling, the range
floor, the ladder's own end,
or the first or last level the criterion is computable at; NA for
an interior optimum), n_levels, values (the criterion
at every level, NA where it could not be computed) and
seeds (an sf POINT layer, with seed_id, of the centres of
the partition the profile scored at best, in the CRS it was
computed in; NULL for a profile that does not carry them). Their
Voronoi cells are the cells that were scored;
get_voronoi_seeds(method = "kmeans", n = <this>) and
voronoi_seeds_kmeans(k = <this>) return them.
Examples
if (requireNamespace("gstat", quietly = TRUE)) {
library(sf)
# An exponential field with range parameter 200 (true effective range
# 600 m) on a 1 km square, with a nugget of 0.6 on a unit sill: enough
# noise for Mallows' Cp to have an interior optimum rather than descend
# to the ceiling.
set.seed(4)
n <- 400
xy <- data.frame(x = 5e5 + runif(n, 0, 1000), y = 5e6 + runif(n, 0, 1000))
D <- as.matrix(dist(xy))
xy$z <- as.numeric(t(chol(exp(-D / 200) + diag(0.6, n))) %*% rnorm(n))
pts <- st_as_sf(xy, coords = c("x", "y"), crs = 32632)
prof <- resolution_profile(pts, response_var = "z", n_levels = 12)
sel <- select_resolution(prof, criterion = "cp")
print(sel) # the level, and the flat region around it
print(sel$flat) # every level within `tol` of the optimum
print(sel$edge) # NA here: the optimum is interior
# Reliability prefers coarse cells and here runs into the floor the
# autocorrelation range sets, which the result says in words.
rel <- select_resolution(prof, criterion = "reliability")
print(rel)
c(at_floor = rel$at_floor, edge = rel$edge)
}
#> Resolution by cp: 28 cells
#> flat region : 18, 28 to 35 (3 of 12 levels)
#> [1] 18 28 35
#> [1] NA
#> Resolution by reliability: 4 cells
#> flat region : 4 to 6 (3 of 12 levels)
#> note : the optimum is the range floor (area / range^2); the bound is
#> choosing, not the criterion. Fewer cells would be wider than
#> the range and average over more than one patch of the field.
#> at_floor edge
#> "TRUE" "the range floor (area / range^2)"