sample: Random Samples and Permutations for 'Vegsoup*' Objects

Description Usage Arguments Details Value Author(s) References See Also Examples

Description

The methods take a sample of the specified size from the elements of x using either with or without replacement. Permutations and random subsamples of the input object can be performed with method sample. Heterogeneity-constrained random samples are obtained with method hcr.

Usage

1
2
3
4
5
6
7
8
## S4 method for signature 'Vegsoup'
sample(x, size, replace = FALSE, prob = NULL)

## S4 method for signature 'Vegsoup'
hcr(x, size, nperm = 1000, fast = FALSE, ...)

## S4 method for signature 'VegsoupPartition'
hcr(x, size, nperm = 1000, fast = FALSE, ...)

Arguments

x

Vegsoup* object.

size

non-negative integer giving the number of items to choose. For hcr defaults to floor(nrow(x) * 0.1) and for sample to nrow(x).

replace

should sampling be with replacement?

prob

vector of probability weights for obtaining the elements of the vector being sampled.

nperm

the number of permutations.

fast

accelerate computations using package 'parallel'.

...

additional arguments replace and prob passed to sample.

Details

See sample for details. If replace = TRUE and size is missing, all duplicated plots are removed from the sample. Method hcr returns the most representative subsample of specified size by selecting from nperm independent subsets the one that has lowest mean dissimilarity and highest variance.

Value

An object of the same class as the input object.

Author(s)

Roland Kaiser, method hcr is an re-implementation of function hcr in package vegclust by Miquel De Cáceres that is capable of forking parallel processes.

References

Lengyel, A., Chytry, M., Tichy, L. (2011). Heterogeneity-constrained random resampling of phytosociological databases. Journal of Vegetation Science 22: 175-183.

See Also

hcr in vegclust, Vegsoup, seriation

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
library(vegsoup)
data(windsfeld)
x <- windsfeld

rownames(sample(x))            # order is permuted
rownames(sample(x, size = 3))  # 3 random plots

# heterogeneity-constrained random samples
# Vegsoup method
hcr(x, size = 20) 

# VegsoupPartition method
# we use base::sample to obtain 2 random partitions
p <- VegsoupPartition(x, clustering = sample(2, nrow(x), replace = TRUE))

pp <- hcr(p, size = min(table(partitioning(p))))

summary(lm(richness(pp, "sa") ~ partitioning(pp)))

# compare run times
## Not run: 
system.time(hcr(windsfeld, size = 20, nperm = 100000, fast = FALSE))
system.time(hcr(windsfeld, size = 20, nperm = 100000, fast = TRUE))
system.time(vegclust::hcr(as.dist(windsfeld), nout = 20, nsampl = 100000))

## End(Not run)

vegsoup documentation built on Feb. 24, 2021, 3 a.m.