11# ' Generate JPS sampling on the provided population.
22# '
3- # ' @inheritParams rss_sample
3+ # ' @param pop Population that will be sampled.
4+ # ' @param n Sample size.
5+ # ' @param H Set size for each ranking group.
6+ # ' @param K Number of rankers.
47# ' @param tau A parameter which controls ranking quality.
8+ # ' @param replace A boolean which specifies whether to sample with replacement or not.
9+ # ' @param with_index A boolean which specifies whether to return the index of the sampled population.
510# '
611# ' @return A matrix with ranks from each ranker.
712# ' @export
3641# ' #> [9,] 8.701285 2 1 2
3742# ' #> [10,] 13.323884 3 3 3
3843# '
39- jps_sample <- function (pop , n , H , tau , K , replace = FALSE ) {
40- verify_jps_params(pop , n , H , tau , K , replace )
44+ jps_sample <- function (pop , n , H , tau , K , replace = FALSE , with_index = FALSE ) {
45+ verify_jps_params(pop , n , H , tau , K , replace , with_index )
4146
42- sampling_matrix <- matrix (sample(pop , n * H , replace = replace ), ncol = H , nrow = n )
47+ sampling_indices <- sample(seq_along(pop ), n * H , replace = replace )
48+ sampling_matrix <- matrix (pop [sampling_indices ], ncol = H , nrow = n )
4349
4450 # rank each SRS unit post experimentally
4551 jps_matrix <- matrix (0 , ncol = K + 1 , nrow = n )
@@ -55,6 +61,10 @@ jps_sample <- function(pop, n, H, tau, K, replace = FALSE) {
5561 }
5662
5763 colnames(jps_matrix ) <- c(" Y" , paste0(" R" , 1 : K ))
64+ if (with_index ) {
65+ jps_matrix <- cbind(sampling_indices [1 : n ], jps_matrix )
66+ colnames(jps_matrix )[1 ] <- " i"
67+ }
68+
5869 return (jps_matrix )
5970}
60- # ' @export
0 commit comments