From 724a88a6e954b80cc6902930a1da6f18ebbbfa00 Mon Sep 17 00:00:00 2001 From: Joe Brown Date: Wed, 17 Apr 2024 10:21:21 -0400 Subject: [PATCH 1/2] extracting run_numbers from one of the dfs in scrores_list rather than independent run_number count --- R/multi_criteria_weighting.R | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/R/multi_criteria_weighting.R b/R/multi_criteria_weighting.R index f072ad4..c0b6cf5 100644 --- a/R/multi_criteria_weighting.R +++ b/R/multi_criteria_weighting.R @@ -60,9 +60,12 @@ multi_criteria_weighting <- function(scores_list, criterion_weights = NULL) { # normalize the combined weights to sum to 1 normalized_combined_scores <- combined_scores / sum(combined_scores) + # extract run_numbers from one of the data frames in scores_list + run_numbers <- scores_list[[1]]$run_number + # return a df with run number and normalized multi-criteria weights return(data.frame( - run_number = 1:length(normalized_combined_scores), + run_number = run_numbers, mc_weight = normalized_combined_scores )) } From 1894492ea815f01adf284be09503c0cd4de0a06e Mon Sep 17 00:00:00 2001 From: Joe Brown Date: Wed, 17 Apr 2024 10:31:01 -0400 Subject: [PATCH 2/2] Editing examples (and re-documenting) and test code to make sure examples have run_numbers --- DESCRIPTION | 2 +- R/multi_criteria_weighting.R | 6 +++--- man/multi_criteria_weighting.Rd | 6 +++--- tests/testthat/test-multi_criterion_weighting.R | 9 ++++++--- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 098527b..d0f802c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -32,6 +32,6 @@ Suggests: testthat (>= 3.0.0) Remotes: github::JGCRI/hector -RoxygenNote: 7.2.3 +RoxygenNote: 7.3.1 Config/testthat/edition: 3 VignetteBuilder: knitr diff --git a/R/multi_criteria_weighting.R b/R/multi_criteria_weighting.R index c0b6cf5..9c18991 100644 --- a/R/multi_criteria_weighting.R +++ b/R/multi_criteria_weighting.R @@ -12,9 +12,9 @@ #' #' @examples #' # Data frames representing scored ensemble using different scoring criterion -#' score_df1 <- data.frame(weights = c(0.8, 0.6, 0.9)) -#' score_df2 <- data.frame(weights = c(0.7, 0.5, 0.8)) -#' score_df3 <- data.frame(weights = c(0.9, 0.8, 0.7)) +#' score_df1 <- data.frame(run_number = c(1, 2, 3), weights = c(0.8, 0.6, 0.9)) +#' score_df2 <- data.frame(run_number = c(1, 2, 3), weights = c(0.7, 0.5, 0.8)) +#' score_df3 <- data.frame(run_number = c(1, 2, 3), weights = c(0.9, 0.8, 0.7)) #' #' # List of score data frames #' scores_list <- list(score_df1, score_df2, score_df3) diff --git a/man/multi_criteria_weighting.Rd b/man/multi_criteria_weighting.Rd index 735774c..42cd2f6 100644 --- a/man/multi_criteria_weighting.Rd +++ b/man/multi_criteria_weighting.Rd @@ -23,9 +23,9 @@ Weighting ensemble members using multiple criterion } \examples{ # Data frames representing scored ensemble using different scoring criterion -score_df1 <- data.frame(weights = c(0.8, 0.6, 0.9)) -score_df2 <- data.frame(weights = c(0.7, 0.5, 0.8)) -score_df3 <- data.frame(weights = c(0.9, 0.8, 0.7)) +score_df1 <- data.frame(run_number = c(1, 2, 3), weights = c(0.8, 0.6, 0.9)) +score_df2 <- data.frame(run_number = c(1, 2, 3), weights = c(0.7, 0.5, 0.8)) +score_df3 <- data.frame(run_number = c(1, 2, 3), weights = c(0.9, 0.8, 0.7)) # List of score data frames scores_list <- list(score_df1, score_df2, score_df3) diff --git a/tests/testthat/test-multi_criterion_weighting.R b/tests/testthat/test-multi_criterion_weighting.R index d9d2695..7fa064c 100644 --- a/tests/testthat/test-multi_criterion_weighting.R +++ b/tests/testthat/test-multi_criterion_weighting.R @@ -1,7 +1,10 @@ # Sample data -score_df1 <- data.frame(weights = c(0.6, 0.4)) -score_df2 <- data.frame(weights = c(0.5, 0.5)) -score_df3 <- data.frame(weights = c(0.9, 0.1)) +score_df1 <- data.frame(run_number = c(1, 2), + weights = c(0.6, 0.4)) +score_df2 <- data.frame(run_number = c(1, 2), + weights = c(0.5, 0.5)) +score_df3 <- data.frame(run_number = c(1, 2), + weights = c(0.9, 0.1)) # Sample lists L1 <- list()