reduce.space {dispRity} | R Documentation |
Reduce space
Description
Remove elements from a multidimensional space
Usage
reduce.space(
space,
type,
remove,
parameters,
tuning,
verbose = FALSE,
return.optim = FALSE
)
Arguments
space |
the trait space |
type |
how to reduce the space (either |
remove |
the proportion of elements to be removed (in probability) |
parameters |
the parameter(s) for removal selection (see details). If left empty, the |
tuning |
Optinal parameters for tuning the parameter estimations (if remove is required and parameters is missing) a list of three parameters: "max" for the maximum of operations, "tol" for the tuning (e.g. 0.1 close), "inc.steps" for the initial increment value during optimisation (default = 2 - the bigger the value, the slower the increment). |
verbose |
wether to be verbose or not |
return.optim |
logical, whether to also return the optimal value. |
Details
The type of reductions algorithms select the proportion of elements to remove (from the remove
parameter). The different algorithms are:
-
"random"
for randomly selecting a proportion of data points (usingsample(..., replace = FALSE)
). -
"size"
for selecting the proportion of data points closer to the centre. -
"density"
for selecting the proportion of data points with the lower nearest neigbhour distances. -
"evenness"
for randomly selecting the proportion of data points from the regions with most density.
The parameters for each reduction type algorithms are:
-
"size"
parameters: a list ofparameters$centre
, the centre from which to count the radius (if missing, is set to0
); andparameters$radius
, the radius for removal. -
"density"
parameters: a list ofparameters$what
"close" (default) for close neighbours or "distant" for distant ones;parameters$diameter
the diameter for considering closeness or distance;parameters$output
either "singles" or "pairs" to return the pairs of neighbours or one of them only (the first). -
"position"
parameters: a list ofparameters$value
, value the threshold value from which to remove elements. -
"evenness"
parameters: a list ofparameters$bw
, a bandwith selector function (bw.nrd0
by default); andparameters$power
a scaling factor for exaggerating the flatting/narrowing of the curve (the counts are set to this parameter exponent: default is1
).
See Guillerme et al. 2020 and https://github.com/TGuillerme/moms for details.
Value
A vector of logical
values of the rows to remove selected by the function. TRUE
corresponds to the following (and FALSE
to the opposite):
"random": the randomly selected points.
"size": the points closer to the centre of the space.
"density": the points closer to each other.
"position": the points on the "positive" side of the space (typically upper right corner in 2D).
"evenness": the randomly select points from the higher density regions.
Author(s)
Thomas Guillerme
References
Guillerme T, Puttick MN, Marcy AE, Weisbecker V. 2020 Shifting spaces: Which disparity or dissimilarity measurement best summarize occupancy in multidimensional spaces?. Ecol Evol. 2020;00:1-16. (doi:10.1002/ece3.6452)
See Also
Examples
set.seed(1)
## Creating a two dimensional space
space <- space.maker(100, 2, distribution = stats::rnorm)
## Generating the four types of reductions
random <- reduce.space(space, "random", remove = 0.5)
size <- reduce.space(space, "size", remove = 0.5)
density <- reduce.space(space, "density", remove = 0.5)
position <- reduce.space(space, "position", remove = 0.5)
evenness <- reduce.space(space, "evenness", remove = 0.5)
## Plotting the four different results
par(mfrow = c(3,2))
plot(space, pch = 19, col = c("grey", "black")[as.factor(random)],
main = "Random removal")
plot(space, pch = 19, col = c("grey", "black")[as.factor(size)],
main = "Size removal")
plot(space, pch = 19, col = c("grey", "black")[as.factor(density)],
main = "Density removal")
plot(space, pch = 19, col = c("grey", "black")[as.factor(position)],
main = "Position removal")
plot(space, pch = 19, col = c("grey", "black")[as.factor(evenness)],
main = "Evenness removal")
## The space reduction with specific parameters:
# Using the point with coordinates (2,2) as the centre
# Running over a maximum of 300 iterations
# With a tolerance of 0.05 (5%)
reduce.space(space, "size", remove = 0.2,
parameters = list("centre" = c(2,2)),
tuning = list("max" = 300, "tol" = 0.05))
## Remove a specific amount to match a specific parameter
reduce.space(space, type = "size", parameters = list("radius" = 1.206866))