rarefy.stat: Rarefy a statistic

View source: R/rarefy.stat.R

rarefy.statR Documentation

Rarefy a statistic

Description

Rarefies or bootstraps a statistic

Usage

rarefy.stat(data, stat.fun, rarefaction, replicates = 100, observed, ...)

Arguments

data

The dataset upon which to calculate the statistics (a "matrix" or "data.frame")

stat.fun

The function to calculate the statistic (in format fun(data, ...)).

rarefaction

The amount of data to resample. Leave as NULL for bootstrapping.

replicates

The number of replicates (default is 100).

observed

Optional, an set observed statistic value.

...

Optional arguments to be passed to stat.fun.

Details

The bootstrap/rarefaction procedure is used with replacement (sample(..., replace = TRUE)) so that when simply bootstrapping the data (no-rarefaction), each row of the dataset has a equal chance of being sampled multiple times.

If the observed value is not provide, the observed statistic is directly measured as stat.fun(data).

Value

A vector of differences between the rarefy statistics and the observed statistics.

Author(s)

Thomas Guillerme

See Also

rand.test

Examples

## A dataset with two variables
data <- replicate(2, rnorm(50))

## A function to get a statistic (the Student statistic)
my.stat <- function(data) {t.test(data[1, ], data[2, ])$statistic[[1]]}

## Rarefy the statistic for only 10 rows
results <- rarefy.stat(data, my.stat, rarefaction = 10)
head(results)

## Summarising the results
quantile(results)
boxplot(results); abline(h = 0, lty = 3)


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