Learn R Programming

biotools (version 2.0)

samplesize: 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.

Value

  • A list of
  • CIa vector containing the lower and the upper confidence limit for the statistic evaluated.
  • pointsOuta 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.

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.

Examples

Run this code
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(2, 1), cex = 0.8)
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)

Run the code above in your browser using DataLab