Learn R Programming

randomizr (version 0.16.1)

cluster_rs: Cluster Random Sampling

Description

cluster_rs implements a random sampling procedure in which groups of units are sampled together (as a cluster). This function conducts complete random sampling at the cluster level, unless simple = TRUE, in which case simple_rs analogues are used.

Usage

cluster_rs(clusters = NULL, n = NULL, prob = NULL, simple = FALSE,
  check_inputs = TRUE)

Arguments

clusters

A vector of length N that indicates which cluster each unit belongs to.

n

Use for a design in which n clusters are sampled. (optional)

prob

Use for a design in which either floor(N_clusters*prob) or ceiling(N_clusters*prob) clusters are sampled. The probability of being sampled is exactly prob because with probability 1-prob, floor(N_clusters*prob) clusters will be sampled and with probability prob, ceiling(N_clusters*prob) clusters will be sampled. prob must be a real number between 0 and 1 inclusive. (optional)

simple

logical, defaults to FALSE. If TRUE, simple random sampling of clusters. When simple = TRUE, please do not specify n.

check_inputs

logical. Defaults to TRUE.

Value

A numeric vector of length N that indicates if a unit is sampled (1) or not (0).

Examples

Run this code
# NOT RUN {
clusters <- rep(letters, times=1:26)

S <- cluster_rs(clusters = clusters)
table(S, clusters)

S <- cluster_rs(clusters = clusters, n = 13)
table(S, clusters)

# }

Run the code above in your browser using DataLab