reduce.space | R Documentation |
Remove elements from a multidimensional space
reduce.space(
space,
type,
remove,
parameters,
tuning,
verbose = FALSE,
return.optim = FALSE
)
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. |
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 (using sample(..., 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 of parameters$centre
, the centre from which to count the radius (if missing, is set to 0
); and parameters$radius
, the radius for removal.
"density"
parameters: a list of parameters$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 of parameters$value
, value the threshold value from which to remove elements.
"evenness"
parameters: a list of parameters$bw
, a bandwith selector function (bw.nrd0
by default); and parameters$power
a scaling factor for exaggerating the flatting/narrowing of the curve (the counts are set to this parameter exponent: default is 1
).
See Guillerme et al. 2020 and https://github.com/TGuillerme/moms for details.
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.
Thomas Guillerme
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)
test.metric
dispRity
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))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.