R/add_hazard_classes.R

Defines functions add_hasard_classes

Documented in add_hasard_classes

#' @title Hazard classes
#' @author Melody Premaillon
#'
#' @description Assign hazard classes to post probability values based on selected threshold
#'
#' @param df_postprob_freq postprob frequency data frame (from build_df_postprobfreq function)
#' @param seuils thresholds of hazard classes, by default JTC1 classes (7 classes from 10-7 à 1 by 10E-1). If you load a custom one first column must contain low threshold values, second one upper ones and third column the class name.
#'
#' @return postprob frequancy data frame with column of hasard class
#' @import dplyr
#' @export
#'


add_hasard_classes <- function(df_postprob_freq, seuils=jtc1_threshold){

  nseuils = nrow(seuils)

  tablefinal <- df_postprob_freq %>%
    arrange(POST_PROB) %>%
    mutate(hazard_class = "",
           somme = cumsum(POINTS),
           somme_prct = somme/sum(POINTS)*100)

  for (i in 1:nseuils){
    tablefinal$hazard_class[which(tablefinal$POST_PROB > seuils[i,1])] <- seuils[i, ncol(seuils)]
  }

  return(tablefinal)
}
MelodyPremaillon/valwoe documentation built on April 16, 2022, 12:46 a.m.