rand.test: Random test

View source: R/rand.test.R

rand.testR Documentation

Random test

Description

Performs a random test

Usage

rand.test(
  distribution,
  subset,
  test,
  replicates = 100,
  resample = TRUE,
  rarefaction,
  test.parameter = FALSE,
  parameter,
  alternative = "two-sided",
  ...
)

Arguments

distribution

A numeric distribution to draw from.

subset

A numeric vector of the elements of the distribution to test.

test

The test to apply (a function).

replicates

A numeric value for the number of replicates (default = 100).

resample

logical wether to resample the full distribution (TRUE) or the distribution without the subset (FALSE).

rarefaction

Optional, a numeric value for rarefying the subset.

test.parameter

Optional, whether to test the calculated parameter (TRUE) or not (FALSE - default).

parameter

Optional, if the parameter is tested, which parameter to select (can be left empty if test outputs a single value or a named object containing a statistic element).

alternative

Optional, if the parameter is tested, what is the alternative hypothesis. Can be "two-sided" (default), "greater" or "lesser".

...

Any optional arguments to be passed to test.

Details

First, the subset of the distribution is compared to the whole distribution (observed difference). Second, random equally sized subsets are compared to the whole distribution (random differences). If the observed difference falls out of the random differences distribution, the differences are significant.

If test.parameter is set to TRUE, the code tests whether the resulting test parameters between the observed subset and the random ones are significantly different (base on the same procedure as in link[ade4]{rantest}).

Value

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.

Author(s)

Thomas Guillerme

See Also

link[ade4]{randtest}

Examples

## Loading the geomorph dataset
require(geomorph)
data(plethodon)

## Performing the Procrustes superimposition
proc_super <- gpagen(plethodon$land, print.progress = FALSE)

## Getting the two most different specimen based on their landmark change radii
var_range <- variation.range(proc_super)

set.seed(1)

## Selecting 6 random landmarks
random_part <- sample(1:nrow(var_range), 6)

## Testing the difference between the two sets of landmarks
stats::t.test(var_range[random_part, "radius"], var_range[-random_part, "radius"])

## Testing whether this difference is expected by chance
random_test <- rand.test(var_range[, "radius"], random_part, test = stats::t.test,
                        test.parameter = TRUE)

## Summarising the results
random_test

## Plotting the results
plot(random_test)

## Rarefying the area difference to 4 elements without testing the parameter
rarefy_test <- rand.test(var_range[, "radius"], random_part, rarefaction = 5,
                         test = stats::t.test)
plot(rarefy_test)


TGuillerme/landvR documentation built on July 4, 2025, 10:16 p.m.