test.metric {dispRity} | R Documentation |
Test disparity metric
Description
Test whether a metric captures changes trait space size, density and position.
Usage
test.metric(
data,
metric,
...,
shifts,
shift.options,
model,
replicates = 3,
steps = 10,
dimensions,
verbose = FALSE,
save.steps = FALSE
)
Arguments
data |
A matrix or a |
metric |
A vector containing one to three functions. At least of must be a dimension-level 1 or 2 function (see details). If |
... |
Optional arguments to be passed to the metric. |
shifts |
The types of shits to test, can be |
shift.options |
Optional, a |
model |
Optional, which model to fit for testing the metric. See details. |
replicates |
A |
steps |
The number of steps in the space reduction to output between 10% and 100%. By default |
dimensions |
Optional, a |
verbose |
A |
save.steps |
A |
Details
For the three non-random shifts: "size"
, "density"
, "evenness"
and "position"
, the function returns both of shifts as:
-
"size.inner"
and"size.outer"
removing data from the edges or the centre respectively (contracting the size and "hollowing" it respectively). -
"density.higher"
and"density.lower"
removing data to increase or decrease density respectively (increasing/decreasing nearest neighbour distance). -
"evenness.flattened"
and"evenness.compacted"
removing data to from the centre of the distribution or from the edges to resepectively "flatten" or "condense" the distribution. -
"position.top"
and"position.bottom"
removing data from one side or the other of the space (the sides are selected from the point with lowest/highest scores on each dimensions respectively).
See figure 2 in Guillerme et al. 2020 for more details.
The default model
is a linear model using the following function:
model = function(data) lm(disparity ~ reduction, data)
You can provide your own as long as it is a single function with data
as a single argument. The two terms from data should be called reduction
for the variable on the x axis and disparity
for the variable on the y axis. For example:
model = function(data) nls(disparity ~ a*reduction/(b+reduction), data)
Note that models (like this example) should be specific to the dataset. Any type of model can be fitted but only the ones with an associated summary
function will be correctly displayed by summary.dispRity
.
To not run any model, use model = NULL
.
Value
This function outputs a dispRity
object containing a list of simulated reductions in trait space. The results can be accessed through the usual S3 methods (print
, summary
, plot
) or accessed directly through x$<name_of_the_shift>
(e.g. x$random
for the random shift results).
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
reduce.space
dispRity
plot.dispRity
Examples
## Creating a 2D uniform space
space <- space.maker(300, 2, runif)
## A simple test with only 1 replicate for two shifts (random and size):
simple_test <- test.metric(space, metric = c(prod, ranges),
replicates = 1, shifts = c("random", "size"))
## Summarising the tests
summary(simple_test)
## Visualising the test
plot(simple_test)
## Applying the test directly on a disparity object
data(disparity)
median_centroid_test <- test.metric(disparity, shifts = "size")
## Summarising the tests
summary(median_centroid_test)
## Visualising the test
plot(median_centroid_test)
## Not run:
## Note that the tests can take several minutes to run.
## Testing the sum of variance on all shifts
sum_var_test <- test.metric(space, metric = c(sum, variances),
shifts = c("random", "size", "density", "position"))
## Summarising the tests
summary(sum_var_test)
## Visualising the test
plot(sum_var_test)
## Creating a 2D uniform space
space <- space.maker(300, 2, runif)
## Re-running the test on two shifts with data saving for visualisation
median_centroid_test <- test.metric(space,
metric = c(median, centroids),
shifts = c("random", "size"),
save.steps = TRUE)
## Visualising the tests results and display the shifts visualisation
plot(median_centroid_test)
## End(Not run)