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.

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

Arguments

clust_var

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

clust_var <- rep(letters, times=1:26) S <- cluster_rs(clust_var = clust_var) table(S, clust_var)
#> clust_var #> S a b c d e f g h i j k l m n o p q r s t u v w x y #> 0 0 0 3 0 0 0 7 8 9 10 0 12 0 0 15 0 17 18 19 0 21 0 0 0 25 #> 1 1 2 0 4 5 6 0 0 0 0 11 0 13 14 0 16 0 0 0 20 0 22 23 24 0 #> clust_var #> S z #> 0 26 #> 1 0
S <- cluster_rs(clust_var = clust_var, n = 13) table(S, clust_var)
#> clust_var #> S a b c d e f g h i j k l m n o p q r s t u v w x y #> 0 0 2 3 0 0 6 0 0 9 0 0 0 13 14 15 16 0 0 19 20 21 0 23 0 25 #> 1 1 0 0 4 5 0 7 8 0 10 11 12 0 0 0 0 17 18 0 0 0 22 0 24 0 #> clust_var #> S z #> 0 0 #> 1 26