From be6e704e41cb42ff975306b6d09105720e3d214a Mon Sep 17 00:00:00 2001
From: sanchezi <isabelle.sanchez@inrae.fr>
Date: Mon, 30 May 2022 10:01:37 +0200
Subject: [PATCH] MaJ issue #7 Bad -> OOR

---
 R/graph_functions.R | 10 +++++-----
 R/kfino.R           | 21 +++++++++------------
 man/kfino_fit.Rd    |  6 +++---
 man/kfino_plot.Rd   |  6 +++---
 4 files changed, 20 insertions(+), 23 deletions(-)

diff --git a/R/graph_functions.R b/R/graph_functions.R
index cb0bce9..765abab 100644
--- a/R/graph_functions.R
+++ b/R/graph_functions.R
@@ -12,10 +12,10 @@
 #' @details The produced graphic can be, according to typeG:
 #' \describe{
 #'  \item{quali}{The detection of outliers with a qualitative rule: OK values,
-#'       KO values (outliers) and Bad values (impossible values defined by
-#'       the user)}
+#'       KO values (outliers) and OOR values (out of range values defined 
+#'       by the user in `kfino_fit`) }
 #'  \item{quanti}{The detection of outliers with a quantitative display using
-#'       the calculated probability of the kafino algorithm}
+#'       the calculated probability of the kfino algorithm}
 #'  \item{prediction}{The prediction of the analyzed variable on OK values}
 #' }
 #'
@@ -99,13 +99,13 @@ kfino_plot<-function(resuin,
           geom_line(data=tp[!is.na(tp$prediction),], aes(y=.data$upr),
                     color="green") +
           scale_color_manual(values =
-                            c("KO"="purple", "OK" = "black", "Bad"="red")) +
+                            c("KO"="purple", "OK" = "black", "OOR"="red")) +
           ggtitle(tp.title1)
     } else {
       g1<-ggplot(tp,aes_string(x=Tvar))+
           geom_point( aes_string(y=Yvar,color="flag")) +
           scale_color_manual(values =
-                            c("KO"="purple", "OK" = "black", "Bad"="red")) +
+                            c("KO"="purple", "OK" = "black", "OOR"="red")) +
           ggtitle(tp.title1)
     }
     return(g1)
diff --git a/R/kfino.R b/R/kfino.R
index 5dd93fb..bbec12d 100644
--- a/R/kfino.R
+++ b/R/kfino.R
@@ -8,7 +8,7 @@
 #'                default TRUE
 #' @param method character, the method used to optimize the initial parameters:
 #'               Expectation-Maximization algorithm `"EM"` or Maximization
-#'               Likelihhod `"ML"`, default `"ML"`
+#'               Likelihood `"ML"`, default `"ML"`
 #' @param threshold numeric, threshold to qualify an observation as outlier
 #'        according to the label_pred, default 0.5
 #' @param kappa numeric, truncation setting, default 10
@@ -34,7 +34,7 @@
 #'              default seq(0.5,0.7,0.1)}
 #' }
 #' It has to be given by the user following his knowledge of the animal or
-#' the dataset. All parameters are compulsory except m0, mm and pp that can be
+#' the data set. All parameters are compulsory except m0, mm and pp that can be
 #' optimized by the algorithm. In the optimization step, those three parameters
 #' are initialized according to the input data (between the expert
 #' range) using quantile of the Y distribution (varying between 0.2 and 0.8 for
@@ -53,7 +53,7 @@
 #' \item{detectOutlier}{The whole dataset with the detected outliers flagged
 #'                      and prediction}
 #' \item{PredictionOK}{A dataset with the predictions on possible values}
-#' \item{kafino.results}{kfino results (a list of vectors) on optimized input
+#' \item{kfino.results}{kfino results (a list of vectors) on optimized input
 #'                      parameters or not}
 #' }
 #' @export
@@ -167,11 +167,12 @@ kfino_fit<-function(datain,Tvar,Yvar,
   # Flag impossible weight values (expert knowledge)
   # the algorithm works on the dataset with possible values
   # Create an artificial column numbering the rows for joining purpose
+  # OK: 'good' value - OOR: out of range value - KO: outlier value
   datain<-as.data.frame(datain)
   datain<-datain %>%
     mutate(rowNum=row_number(),
            flag1=if_else(.data[[Yvar]] > expertMin &
-                           .data[[Yvar]] <= expertMax,"OK","Bad"))
+                           .data[[Yvar]] <= expertMax,"OK","OOR"))
   tp.dt<-datain %>% filter(.data$flag1 == "OK")
 
   Y<-tp.dt[,Yvar]
@@ -296,8 +297,6 @@ kfino_fit<-function(datain,Tvar,Yvar,
           diff_m0=diff_mm=diff_p=20
           k=1
           while (diff_m0 > 0.5 && diff_p > 0.0001 && diff_mm > 2){
-            print("ici boucle low")
-            print(k)
             Res_EM=KBO_EM(param=list(mm=m_tmp,
                                      pp=p_tmp,
                                      m0=m0_tmp,
@@ -333,8 +332,6 @@ kfino_fit<-function(datain,Tvar,Yvar,
           diff_m0=diff_mm=diff_p=20
           k=1
           while (diff_m0 > 0.5 && diff_p > 0.0001 && diff_mm > 2){
-            print("ici boucle up")
-            print(k)
             Res_EM=KBO_EM(param=list(mm=m_tmp,
                                      pp=p_tmp,
                                      m0=m0_tmp,
@@ -590,8 +587,8 @@ kfino_fit<-function(datain,Tvar,Yvar,
   # Formatting output results
   #---------------------------------------------------------------------------
   # If resultat NULL then create output with datain and 2 NULL objects
-  # else create output with detectoutlier, PredictionOK and kafino.results
-  # useful for the kafino_plot() function
+  # else create output with detectoutlier, PredictionOK and kfino.results
+  # useful for the kfino_plot() function
   #---------------------------------------------------------------------------
   if (is.null(resultat)){
     dt.out<-datain %>% mutate(flag=.data$flag1)
@@ -599,7 +596,7 @@ kfino_fit<-function(datain,Tvar,Yvar,
     resultat<-NULL
 
     mylist<-list(dt.out,dt.pred,resultat)
-    names(mylist)<-c("detectOutlier","PredictionOK","kafino.results")
+    names(mylist)<-c("detectOutlier","PredictionOK","kfino.results")
     class(mylist) = c("kfino")
     return(invisible(mylist))
   } else {
@@ -614,7 +611,7 @@ kfino_fit<-function(datain,Tvar,Yvar,
 
     # join dt.pred with the initial datain containing all the observations
     dt.out<-left_join(datain,dt.pred,by="rowNum")
-    dt.out<-mutate(dt.out,flag=if_else(.data$flag1 == "Bad",
+    dt.out<-mutate(dt.out,flag=if_else(.data$flag1 == "OOR",
                                        .data$flag1, .data$flag))
     dt.out<-arrange(dt.out,.data$rowNum)
 
diff --git a/man/kfino_fit.Rd b/man/kfino_fit.Rd
index 281bc86..ca7e85f 100644
--- a/man/kfino_fit.Rd
+++ b/man/kfino_fit.Rd
@@ -31,7 +31,7 @@ default TRUE}
 
 \item{method}{character, the method used to optimize the initial parameters:
 Expectation-Maximization algorithm `"EM"` or Maximization
-Likelihhod `"ML"`, default `"ML"`}
+Likelihood `"ML"`, default `"ML"`}
 
 \item{threshold}{numeric, threshold to qualify an observation as outlier
 according to the label_pred, default 0.5}
@@ -47,7 +47,7 @@ kfino results
 \item{detectOutlier}{The whole dataset with the detected outliers flagged
                      and prediction}
 \item{PredictionOK}{A dataset with the predictions on possible values}
-\item{kafino.results}{kfino results (a list of vectors) on optimized input
+\item{kfino.results}{kfino results (a list of vectors) on optimized input
                      parameters or not}
 }
 }
@@ -75,7 +75,7 @@ The initialization parameter list param contains:
              default seq(0.5,0.7,0.1)}
 }
 It has to be given by the user following his knowledge of the animal or
-the dataset. All parameters are compulsory except m0, mm and pp that can be
+the data set. All parameters are compulsory except m0, mm and pp that can be
 optimized by the algorithm. In the optimization step, those three parameters
 are initialized according to the input data (between the expert
 range) using quantile of the Y distribution (varying between 0.2 and 0.8 for
diff --git a/man/kfino_plot.Rd b/man/kfino_plot.Rd
index 49a6957..1c86f0a 100644
--- a/man/kfino_plot.Rd
+++ b/man/kfino_plot.Rd
@@ -31,10 +31,10 @@ kfino_plot a graphical function for the result of a kfino run
 The produced graphic can be, according to typeG:
 \describe{
  \item{quali}{The detection of outliers with a qualitative rule: OK values,
-      KO values (outliers) and Bad values (impossible values defined by
-      the user)}
+      KO values (outliers) and OOR values (out of range values defined 
+      by the user in `kfino_fit`) }
  \item{quanti}{The detection of outliers with a quantitative display using
-      the calculated probability of the kafino algorithm}
+      the calculated probability of the kfino algorithm}
  \item{prediction}{The prediction of the analyzed variable on OK values}
 }
 }
-- 
GitLab