nStrata: Calculates the sample size in a stratified desgin

Description Usage Arguments Value Examples

View source: R/nStrata.R

Description

This function returns the number of elements to be sampled in a stratified based survey. If the method choosen is 'prop' or 'optimum', the function return the allocation too.

Usage

1
2
nStrata(data, stratanames, alpha, moe, S2 = NULL, pq = NULL,
  V = NULL, N, method = c("prop", "optimum"))

Arguments

data

The data.frame containing the variable denoted as the cluster.

stratanames

The variable name of the considered strata. Can be a vector of variable names.

alpha

(1 - confidence level).

moe

Margin of error.

S2

The variance, as σ^2. Not necessary if pq or V is not NULL.

pq

The variance, as P(1-P). Not necessary if S2 or V is not NULL.

V

The variance, as (d/t)^2. Not necessary if S2 or pq is not NULL.

N

Population size.

method

A string with prop or optimum. With optimum, it uses Neyman allocation.

Value

The value (integer) of the number of elements to sample in stratified sampling. If prop or optimum where used, the function returns a list with the elements per strata.

n

Total number of elements in the sample.

nh

The allocation in each strata.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
library(survey)
data("api")
nStrata(apipop,stratanames = "stype", alpha = 0.05, moe = 0.05,
        pq = 0.25, N = nrow(apipop), method = "prop")
nStrata(apipop,stratanames = "stype", alpha = 0.05, moe = 0.05,
        pq = 0.25, N = nrow(apipop), method = "optimum")
### Cochran's example (Cochran, W. G. (2007). Sampling techniques. John Wiley & Sons. p. 106-107)
data_cochran=data.frame(stratum=rep(c(1:6),c(13,18,26,42,73,24)))
nStrata(data_cochran,stratanames = "stratum", N=196, method = "optimum",
        S2=c(325^2,190^2,189^2,82^2,86^2,190^2),V=7974976/196^2)

cgu-dados/auditsampling documentation built on March 24, 2021, 9:38 a.m.