H.sampler: Shannon's Diversity Re-sampler

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

View source: R/H.sampler.R

Description

This function is a wrapper for sample and can be used to determine the expected value of a diversity index under a specified sampling intensity. A Monte-Carlo procedure is used to re-sample a given observation with replacement at each user-specified sampling intensity. The resampling can take place through one of two schemes. First, where the observed frequencies of species are assumed to represent the true underlying values, and second, where a user-specified vector of probabilities is used to control the resampling. The function calculates a diversity index over each simulated sample and summarises these for each specified level of sampling intensity via their mean.

Usage

1
H.sampler(x = "community matrix (spp=col,obs=row)", n = "sample size vector", nit = "number of iterations to use", base = exp(1), corr = FALSE, p = NULL, method = "Shannon")

Arguments

x

A community matrix with observations in rows and species in columns.

n

A vector or scalar of sample size(s).

nit

Number of iterations of the Monte-Carlo procedure.

base

The base of the logarithm used to calculate Shannon's index (DEFAULT = e).

corr

Correction factor for small sample sizes.

p

A vector or matrix of weights corresponding to x, which can be used to simulate scenarios where forces other than sampling impact diversity.

method

The diversity metric: "Shannon" or "Gene diversity"

Details

The Monte-Carlo procedure draws random individuals based on the relative abundances of the species in a given observation. This process is repeated for the number of specified iterations at each designated sample level. For each iteration, the diversity index is calculated, and the mean is taken from all the indices produced in each iteration.

Value

A matrix of diversity indices for each observation (rows) at each sampling level (columns).

Author(s)

Matthew K. Lau and Raj Whitlock

See Also

sample, Gd, Hs, count

Examples

1
2
x=array(round(runif(100,1,10)),c(10,10))
H.sampler(x,n=1:10,nit=10,base=exp(1))

Example output

      N1        N2        N3       N4       N5       N6       N7       N8
 [1,]  0 0.6238325 1.0061927 1.316980 1.193550 1.482675 1.534876 1.609274
 [2,]  0 0.6931472 0.9599829 1.165269 1.273058 1.381534 1.492647 1.678589
 [3,]  0 0.6931472 0.8039118 1.074378 1.387631 1.413360 1.435855 1.507256
 [4,]  0 0.4852030 0.9599829 1.117530 1.255797 1.427744 1.507597 1.643931
 [5,]  0 0.6238325 0.9599829 1.143693 1.228071 1.317883 1.519926 1.596193
 [6,]  0 0.6238325 0.8501216 1.048216 1.359905 1.413360 1.420905 1.507256
 [7,]  0 0.4852030 0.9425412 1.143693 1.283523 1.404639 1.500122 1.401554
 [8,]  0 0.6931472 0.8501216 1.186845 1.276727 1.450849 1.532255 1.513797
 [9,]  0 0.4852030 0.9137730 1.095954 1.266262 1.372814 1.279655 1.533419
[10,]  0 0.6238325 0.9599829 1.095954 1.304453 1.395919 1.482938 1.557288
            N9      N10
 [1,] 1.579055 1.778920
 [2,] 1.659847 1.832808
 [3,] 1.650258 1.672557
 [4,] 1.484597 1.720070
 [5,] 1.559575 1.730535
 [6,] 1.677289 1.673249
 [7,] 1.603478 1.716672
 [8,] 1.544172 1.666632
 [9,] 1.532846 1.655988
[10,] 1.621189 1.664619
Warning message:
In if (n == "sample size vector") { :
  the condition has length > 1 and only the first element will be used

DiversitySampler documentation built on May 30, 2017, 4:20 a.m.