srs.samplesize {samplingR} | R Documentation |
Simple Random Sample size.
Description
Calculates the required sample size in order to achieve a relative or absolute sampling error less or equal to the specified for an specific estimator and an optional confidence interval in simple random sampling.
Usage
srs.samplesize(
N,
var,
error,
alpha,
estimator = c("total", "mean", "proportion", "class total"),
p,
mean,
replace = FALSE,
relative = FALSE
)
Arguments
N |
Number of instances of the data set. |
var |
Estimated quasivariance. |
error |
Sampling error |
alpha |
Significance level to obtain confidence intervals. |
estimator |
One of "total", "proportion", "mean", "class total". Default is "total" |
p |
Estimated proportion. If estimator is not "proportion" or "class total" it will be ignored. |
mean |
Estimated mean. If relative=FALSE it will be ignored. |
replace |
Whether the sample to be taken can have repeated instances or not. |
relative |
Whether the specified error is relative or not. |
Details
If the sample size result is not a whole number the number returned is
the next whole number so srs.samplesize>=n is satisfied.
To estimate sample size of estimators "total" and "mean" estimated quasivariance
must be provided. If the error is relative then estimated mean must also be provided.
To estimate sample size of estimator "proportion" and "class total" estimated
proportion must be provided. If p is not specified sample size will be estimated
based on worst-case scenario of p=0.5.
N must be always be provided for calculations.
Value
Number of instances of the sample to be taken.
Examples
data<-rnorm(200, 100, 20)
n<-srs.samplesize(200, var(data), estimator="total", error=400, alpha=0.05);n
sample<-data[srs.sample(200, n)]
srs.estimator(200, sample, "total", alpha=0.05)$sampling.error