samplesize {biotools}R Documentation

Minimum Sample Size

Description

Function to determine the minimum sample size for calculating a statistic based on its the confidence interval.

Usage

samplesize(x, fun, sizes = NULL, lcl = NULL, ucl = NULL,
	nboot = 200, conf.level = 0.95, nrep = 500, graph = TRUE, ...)

Arguments

x

a numeric vector.

fun

an objective function at which to evaluate the sample size; see details.

sizes

a numeric vector containing sample sizes; if NULL (default), samplesize creates a vector ranging from 2 to n-1.

lcl

the lower confidence limit for the statistic defined in fun; if NULL (default), samplesize estimates lcl based on bootstrap percentile interval.

ucl

the upper confidence limit for the statistic defined in fun; if NULL (default), samplesize estimates ucl based on bootstrap percentile interval.

nboot

the number of bootstrap samples; it is used only if lcl or ucl is NULL.

conf.level

the confidence level for calculating the lcl and ucl; it is used only if lcl or ucl is NULL.

nrep

the resampling (with replacement) number for each sample size in sizes; default is 500.

graph

logical; default is TRUE.

...

further graphical arguments.

Details

If ucl or lcl is NULL, fun must be defined as in boot, i.e., the first argument passed will always be the original data and the second will be a vector of indices, frequencies or weights which define the bootstrap sample. By now, samplesize considers the second argument only as index.

Value

A list of

CI

a vector containing the lower and the upper confidence limit for the statistic evaluated.

pointsOut

a data frame containing the sample sizes (in sizes), the number of points outside the CI (n.out) and the proportion of this number (prop).

Side Effects

If graph = TRUE, a graphic with the dispersion of the estimates for each sample size, as well as the graphic containing the number of points outside the confidence interval for the reference sample.

Author(s)

Anderson Rodrigo da Silva <anderson.agro@hotmail.com>

Examples

cv <- function(x, i) sd(x[i]) / mean(x[i]) # coefficient of variation
x = rnorm(20, 15, 2)
cv(x)
samplesize(x, cv)

par(mfrow = c(1, 3), cex = 0.7, las = 1)
samplesize(x, cv, lcl = 0.05, ucl = 0.20)
abline(h = 0.05 * 500, col = "blue") # sample sizes with 5% (or less) out CI

# End (not run)

[Package biotools version 4.2 Index]