View source: R/randtest.dispRity.R
| randtest.dispRity | R Documentation |
Performs a random test (aka permutation test) on a matrix or a dispRity object.
## S3 method for class 'dispRity'
randtest(
xtest,
subsets,
metric,
replicates = 100,
resample = TRUE,
alter = "two-sided",
...
)
xtest |
The |
subsets |
A |
metric |
A |
replicates |
A |
resample |
|
alter |
The alternative hypothesis. Can be |
... |
optional arguments to be passed to |
This test checks whether the metric calculated on a given subset of the data is significantly different from the metric calculated on any random subset of the same size. In other words: does the given subset have a clearly different disparity value than the rest of the data?
First, the metric (statistic) is applied to the subset sampled from the data (population).
Second, the metric is applied to random equally sized subsets from the data.
If the observed difference falls out of the random differences distribution, the differences are significant.
This algorithm is based on a similar procedure than in link[ade4]{rantest}.
If data is a dispRity object, the subsets, metric and replicates can be left missing and are automatically inherited from the dispRity if it contains respectively subsets (from chrono.subsets or custom.subsets) a metric (from dispRity) and bootstrap draws (from boot.matrix).
If data is a dispRity object subsets can be a list of subsets to compare for example list(c("A", "B"), c("B", "A")) will run two tests comparing respectively sample A to B and B to A. Note that it will only compare these two samples and use their combined size as the population size, if you want to compare a subset to all the subsets you can use list(c("A") or write down the specific subsets to be used.
This function returns a "randtest" object that can be passed to the generic S3 functions print.randtest or plot.randtest.
The output also contains to extra elements output$observed and output$random containing the raw results of respectively the observed and random tests.
Thomas Guillerme
randtest
## Simple example
dummy_matrix <- matrix(rnorm(500), 100, 5)
## Testing whether the mean of a random subset
## is different than the means of 100 subsets
dummy_test <- randtest.dispRity(dummy_matrix,
subset = sample(1:100, 20),
metric = mean)
dummy_test ; plot(dummy_test)
## Applying this on dispRity objects
data(disparity)
test_disparity <- test.dispRity(disparity,
test = randtest.dispRity)
## The summarised results
summary(test_disparity)
## Plotting the results
plot(test_disparity)
## Applying this on a dispRity object with specific subset comparisons
test_disparity2 <- randtest.dispRity(disparity, subsets = list(
## Comparing subset 90 to the whole population (traitspace)
c(observed = "90"),
## Comparing subset "70" to "90", "70" and "30"
c(observed = "70", random = c("90", "70", "30"))))
## Summarising and plotting the results
summary(test_disparity2)
plot(test_disparity2)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.