Learn R Programming

capm (version 0.14.0)

CalculateStratifiedSampleSize: Stratified random sample size

Description

Calculates sample size to estimate a total from a stratified random sampling design.

Usage

CalculateStratifiedSampleSize(strata = NULL, x = NULL,
  conf.level = 0.95, error = 0.1)

Arguments

strata

vector, matrix or data.frame. If vector, named elements represent the size of the strata. If matrix or data.frame, first column represent the size of each strata, second column represent the expected mean in each strata and third column represent the expected variance in each strata. Each row is a strata and must be named.

x

data.frame representing a pilot sample. First column has the variable to be estimated and second column has the strata membership of each observation. Needed when strata is a vector.

conf.level

the confidence level required. It must be numeric between 0 and 1 inclusive.

error

the maximum relative difference between the estimate and the unknown population value. It must be numeric between 0 and 1 inclusive.

Value

numeric sample size rounded up to nearest integer.

References

Levy P and Lemeshow S (2008). Sampling of populations: methods and applications, Fourth edition. John Wiley and Sons, Inc.

http://oswaldosantos.github.io/capm

Examples

Run this code
# NOT RUN {
# Using a pilot sample from a population with 10000 sampling units.
strata <- rep(c("rural", "urban"), c(100, 9900))
pilot <- data.frame(c(rpois(5, 1.3), rpois(45, 0.8)),
                           rep(c("rural", "urban"), c(5, 45)))
CalculateStratifiedSampleSize(strata, pilot)
      
# Using expected mean and variance for a population with
# 10000 sampling units.
str_n <- c(rural = 100, urban = 9900)
str_mean <- c(rural = 1.4, urban = 0.98)
str_var <- c(rural = 1.48, urban = 1.02)
CalculateStratifiedSampleSize(cbind(str_n, str_mean, str_var))

# }

Run the code above in your browser using DataLab