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 |
lcl |
the lower confidence limit for the statistic defined in |
ucl |
the upper confidence limit for the statistic defined in |
nboot |
the number of bootstrap samples; it is used only if |
conf.level |
the confidence level for calculating the |
nrep |
the resampling (with replacement) number for each sample size in |
graph |
logical; default is |
... |
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 |
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)