R/evaluate_mix_rules.R

Defines functions evaluate_mixture_rules

Documented in evaluate_mixture_rules

#' Evaluate mixture rules found during the PRE process
#'
#' @param data Input data
#' @param rules Dataframe of the rules determined
#' @importFrom dplyr transmute
#' @return binary_rule_matrix: A binary matrix where each column is the mixture
#' rule evaluated into a binary vector.

#'
#' @export

evaluate_mixture_rules <- function(data, rules) {
  rule_binary_match_list <- list()

  for (i in seq(dim(rules)[1])) {
    rule_t <- rules[i, ]
    if (rule_t$description != "1") {
      mix_decisions <- rule_t$description
      rule_binary <- data %>%
        dplyr::transmute(A = ifelse(eval(parse(text = mix_decisions)), 1, 0))

      rule_binary_match_list[i] <- rule_binary
    }
  }

  rule_binary_match_df <- base::do.call(cbind, rule_binary_match_list)

  colnames(rule_binary_match_df) <- rules$description

  binary_rule_matrix <- rule_binary_match_df

  return(binary_rule_matrix)
}
blind-contours/CVtreeMLE documentation built on June 22, 2024, 8:53 p.m.