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 f072ad4..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) @@ -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 )) } 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()