-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from biometryhub/feature/unit-test
Feature/unit test
- Loading branch information
Showing
22 changed files
with
849 additions
and
561 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,28 @@ | ||
#' Title | ||
#' Generate JPS sampling without replacement on the provided population. | ||
#' | ||
#' @param pop Population | ||
#' @param n sample size | ||
#' @param H Set size | ||
#' @param tau controls the ranking quality | ||
#' @param K Number of rankers | ||
#' @inheritParams RSS | ||
#' @param tau A parameter which controls ranking quality. | ||
#' | ||
#' @return | ||
#' @keywords internal | ||
#' @return A matrix with ranks from each ranker. | ||
#' | ||
JPSD2F <- function(pop, n, H, tau, K) { | ||
############################################# | ||
# Ths function generates JPS sample ## | ||
############################################# | ||
# K: Number of rankers | ||
# tau: controls the ranking quality | ||
# n:sample size | ||
# H: Set szie | ||
# pop: population | ||
pop_size <- length(pop) # population size | ||
nsets <- matrix(sample(pop, n * H), ncol = H, nrow = n) | ||
################################################# | ||
# below consruct rank for each SRS unit post experimentally | ||
JPS <- matrix(0, ncol = K + 1, nrow = n) # store JPS sample | ||
############################################## | ||
JPSD2F <- function(pop, n, H, tau, K, with_replacement = FALSE) { | ||
verify_jps_params(pop, n, H, tau, K, with_replacement) | ||
|
||
sampling_matrix <- matrix(sample(pop, n * H, replace = with_replacement), ncol = H, nrow = n) | ||
|
||
# rank each SRS unit post experimentally | ||
jps_matrix <- matrix(0, ncol = K + 1, nrow = n) | ||
for (i in (1:n)) { | ||
Set <- nsets[i, ] # select compariosn set i | ||
tem <- rep(0, K) # initialize to store ranks of he rankers for ocm,parion set i | ||
comparison_set <- sampling_matrix[i, ] | ||
ranks <- rep(0, K) | ||
for (k in (1:K)) { | ||
DCSet <- Set + tau[k] * rnorm(H, 0, 1) # adjust ranking quality using Dell-Clutter | ||
# model | ||
RankSet <- rank(DCSet) # ranks the units in the comparion set i by ranker k | ||
tem[k] <- RankSet[1] # the rank of the i-th mesured unit by ranker k | ||
# adjust for ranking, Dell and Clutter | ||
adjusted_set <- comparison_set + tau[k] * rnorm(H, 0, 1) | ||
ranks[k] <- rank(adjusted_set)[1] | ||
} | ||
JPS[i, ] <- c(Set[1], tem) # meaured value of unit i and ranks by k rankers | ||
jps_matrix[i, ] <- c(comparison_set[1], ranks) | ||
} | ||
colnames(JPS) <- c("Y", paste("R", 1:K, sep = "")) | ||
return(JPS) | ||
|
||
colnames(jps_matrix) <- c("Y", paste0("R", 1:K)) | ||
return(jps_matrix) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.