From 769bc62a9f692691e6efdcc5685d36dd4dbf2b03 Mon Sep 17 00:00:00 2001 From: sanchezi <isabelle.sanchez@inrae.fr> Date: Wed, 14 Sep 2022 16:39:40 +0200 Subject: [PATCH] insertion of comments by BC --- NAMESPACE | 6 +- R/kfino.R | 131 ++++++++++++++------------ R/utils_functions.R | 34 ++++--- doc/HowTo.html | 8 +- doc/multipleFit.html | 12 +-- man/kfino_fit.Rd | 18 ++-- man/{KBO_EM.Rd => utils_EM.Rd} | 19 ++-- man/{KBO_known.Rd => utils_fit.Rd} | 14 +-- man/{KBO_L.Rd => utils_likelihood.Rd} | 16 ++-- tests/testthat/test-outputAlgo.R | 4 +- 10 files changed, 140 insertions(+), 122 deletions(-) rename man/{KBO_EM.Rd => utils_EM.Rd} (69%) rename man/{KBO_known.Rd => utils_fit.Rd} (78%) rename man/{KBO_L.Rd => utils_likelihood.Rd} (68%) diff --git a/NAMESPACE b/NAMESPACE index 5732095..8868c61 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,11 +1,11 @@ # Generated by roxygen2: do not edit by hand -export(KBO_EM) -export(KBO_L) -export(KBO_known) export(doutlier) export(kfino_fit) export(kfino_plot) +export(utils_EM) +export(utils_fit) +export(utils_likelihood) importFrom(dplyr,"%>%") importFrom(dplyr,.data) importFrom(dplyr,arrange) diff --git a/R/kfino.R b/R/kfino.R index 2ee4611..0a20f77 100644 --- a/R/kfino.R +++ b/R/kfino.R @@ -7,15 +7,15 @@ #' @param doOptim logical, if TRUE optimization of the initial parameters, #' default TRUE #' @param method character, the method used to optimize the initial parameters: -#' Expectation-Maximization algorithm `"EM"` or Maximization -#' Likelihood `"ML"`, default `"ML"` +#' Expectation-Maximization algorithm `"EM"` (faster) or Maximization +#' Likelihood `"ML"` (more robust), 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 for likelihood optimization, -#' default 10 -#' @param kappaOpt numeric, truncation setting for initial parameters' -#' optimization, default 7 -#' @param verbose write stuff if TRUE (optional), default FALSE. +#' @param kappa numeric, truncation setting for likelihood optimization over +#' initial parameters, default 10 +#' @param kappaOpt numeric, truncation setting for the filtering and outlier +#' detection step with optimized parameters, default 7 +#' @param verbose write details if TRUE (optional), default FALSE. #' #' @details The initialization parameter list `param` contains: #' \describe{ @@ -65,7 +65,9 @@ #' \item{lwr}{lower bound of the confidence interval of the predicted value} #' \item{upr}{upper bound of the confidence interval of the predicted value} #' \item{flag}{flag of the value (OK value, KO value (outlier), OOR value -#' (out of range values defined by the user in `kfino_fit`)} +#' (out of range values defined by the user in `kfino_fit` with +#' `expertMin`, `expertMax` input parameters). If +#' flag == OOR the 4 previous columns are set to NA.} #' } #' @return PredictionOK: A subset of `detectOutlier` data set with the predictions #' of the analyzed variable on possible values (OK and KO values) @@ -240,17 +242,18 @@ kfino_fit<-function(datain,Tvar,Yvar, Y=YY[Subechant] Tps=TpsTps[Subechant] N=50 - Vopt=KBO_L(list(m0=m0opt, - mm=mmopt, - pp=popt, - aa=aa, - expertMin=expertMin, - expertMax=expertMax, - sigma2_mm=sigma2_mm, - sigma2_m0=sigma2_m0, - sigma2_pp=sigma2_pp, - K=K), - Y=Y,Tps=Tps,N=N,scalingC=scalingC,kappaOpt=kappaOpt) + Vopt=utils_likelihood(list(m0=m0opt, + mm=mmopt, + pp=popt, + aa=aa, + expertMin=expertMin, + expertMax=expertMax, + sigma2_mm=sigma2_mm, + sigma2_m0=sigma2_m0, + sigma2_pp=sigma2_pp, + K=K), + Y=Y,Tps=Tps,N=N, + scalingC=scalingC,kappaOpt=kappaOpt) for (m0 in seq(bornem0[1],bornem0[2],2) ){ for (mm in seq((m0-5),(m0+20),2) ){ @@ -261,17 +264,18 @@ kfino_fit<-function(datain,Tvar,Yvar, Y=YY[Subechant] Tps=TpsTps[Subechant] - V=KBO_L(list(m0=m0, - mm=mm, - pp=p, - aa=aa, - expertMin=expertMin, - expertMax=expertMax, - sigma2_mm=sigma2_mm, - sigma2_m0=sigma2_m0, - sigma2_pp=sigma2_pp, - K=K), - Y=Y,Tps=Tps,N=N,scalingC=scalingC,kappaOpt=kappaOpt) + V=utils_likelihood(list(m0=m0, + mm=mm, + pp=p, + aa=aa, + expertMin=expertMin, + expertMax=expertMax, + sigma2_mm=sigma2_mm, + sigma2_m0=sigma2_m0, + sigma2_pp=sigma2_pp, + K=K), + Y=Y,Tps=Tps,N=N, + scalingC=scalingC,kappaOpt=kappaOpt) if (V > Vopt){ Vopt=V m0opt=m0 @@ -296,7 +300,7 @@ kfino_fit<-function(datain,Tvar,Yvar, print("-------:") } - resultat=KBO_known(param=list(mm=mmopt, + resultat=utils_fit(param=list(mm=mmopt, pp=popt, m0=m0opt, aa=aa, @@ -328,7 +332,7 @@ 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){ - Res_EM=KBO_EM(param=list(mm=m_tmp, + Res_EM=utils_EM(param=list(mm=m_tmp, pp=p_tmp, m0=m0_tmp, aa=aa, @@ -362,7 +366,7 @@ 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){ - Res_EM=KBO_EM(param=list(mm=m_tmp, + Res_EM=utils_EM(param=list(mm=m_tmp, pp=p_tmp, m0=m0_tmp, aa=aa, @@ -401,7 +405,7 @@ kfino_fit<-function(datain,Tvar,Yvar, k=1 while (diff_m0 > 0.5 && diff_p > 0.0001 && diff_mm > 2){ print(k) - Res_EM=KBO_EM(param=list(mm=m_tmp, + Res_EM=utils_EM(param=list(mm=m_tmp, pp=p_tmp, m0=m0_tmp, aa=aa, @@ -411,7 +415,8 @@ kfino_fit<-function(datain,Tvar,Yvar, sigma2_mm=sigma2_mm, sigma2_pp=sigma2_pp, K=K), - kappaOpt=kappaOpt, Y=Y,Tps=Tps,N=N,scalingC=scalingC) + kappaOpt=kappaOpt, Y=Y,Tps=Tps,N=N, + scalingC=scalingC) diff_m0=abs(m0_tmp - Res_EM$m0[[1]]) diff_p=abs(p_tmp - Res_EM$pp) diff_mm=abs(m_tmp - Res_EM$mm[[1]]) @@ -447,7 +452,7 @@ kfino_fit<-function(datain,Tvar,Yvar, mmopt=quantile(Y[(3*N/4):N], probs = c(.5)) popt=0.5 - Vopt=KBO_EM(param=list(m0=m0opt, + Vopt=utils_EM(param=list(m0=m0opt, mm=mmopt, pp=popt, aa=aa, @@ -473,7 +478,7 @@ kfino_fit<-function(datain,Tvar,Yvar, cat("Optimized pp: ",popt,"\n") print("-------:") } - resultat=KBO_known(param=list(mm=mmopt, + resultat=utils_fit(param=list(mm=mmopt, pp=popt, m0=m0opt, aa=aa, @@ -502,31 +507,33 @@ kfino_fit<-function(datain,Tvar,Yvar, } popt=0.5 - Vopt=KBO_L(list(m0=m0opt, - mm=mmopt, - pp=popt, - aa=aa, - expertMin=expertMin, - expertMax=expertMax, - sigma2_mm=sigma2_mm, - sigma2_m0=sigma2_m0, - sigma2_pp=sigma2_pp, - K=K), - Y=Y,Tps=Tps,N=N,scalingC=scalingC,kappaOpt=kappaOpt) + Vopt=utils_likelihood(list(m0=m0opt, + mm=mmopt, + pp=popt, + aa=aa, + expertMin=expertMin, + expertMax=expertMax, + sigma2_mm=sigma2_mm, + sigma2_m0=sigma2_m0, + sigma2_pp=sigma2_pp, + K=K), + Y=Y,Tps=Tps,N=N, + scalingC=scalingC,kappaOpt=kappaOpt) for (m0 in seq(bornem0[1],bornem0[2],2) ){ for (mm in seq((m0-5),(m0+20),2) ){ for (p in seqp){ - V=KBO_L(list(m0=m0, - mm=mm, - pp=p, - aa=aa, - expertMin=expertMin, - expertMax=expertMax, - sigma2_mm=sigma2_mm, - sigma2_m0=sigma2_m0, - sigma2_pp=sigma2_pp, - K=K), - Y=Y,Tps=Tps,N=N,scalingC=scalingC,kappaOpt=kappaOpt) + V=utils_likelihood(list(m0=m0, + mm=mm, + pp=p, + aa=aa, + expertMin=expertMin, + expertMax=expertMax, + sigma2_mm=sigma2_mm, + sigma2_m0=sigma2_m0, + sigma2_pp=sigma2_pp, + K=K), + Y=Y,Tps=Tps,N=N, + scalingC=scalingC,kappaOpt=kappaOpt) if (V > Vopt){ Vopt=V @@ -545,7 +552,7 @@ kfino_fit<-function(datain,Tvar,Yvar, cat("Optimized pp: ",popt,"\n") print("-------:") } - resultat=KBO_known(param=list(mm=mmopt, + resultat=utils_fit(param=list(mm=mmopt, pp=popt, m0=m0opt, aa=aa, @@ -576,7 +583,7 @@ kfino_fit<-function(datain,Tvar,Yvar, print(X) print("-------:") } - resultat=KBO_known(param=list(m0=X[[1]], + resultat=utils_fit(param=list(m0=X[[1]], pp=X[[2]], mm=X[[3]], aa=aa, @@ -608,7 +615,7 @@ kfino_fit<-function(datain,Tvar,Yvar, print("Used parameters: ") print(X) } - resultat=KBO_known(param=list(m0=X[[1]], + resultat=utils_fit(param=list(m0=X[[1]], pp=X[[2]], mm=X[[3]], aa=aa, diff --git a/R/utils_functions.R b/R/utils_functions.R index 4869440..465eb6f 100644 --- a/R/utils_functions.R +++ b/R/utils_functions.R @@ -1,9 +1,9 @@ #------------------------------------------------------------------- # utils_functions.R: some useful functions for kfino method # doutlier() -# KBO_known() -# KBO_L() -# KBO_EM() +# utils_fit() +# utils_likelihood() +# utils_EM() #------------------------------------------------------------------- #' doutlier defines an outlier distribution (Surface of a @@ -38,7 +38,8 @@ doutlier<-function(y, #-------------------------------------------------------------------------- -#' KBO_known a function to calculate a likelihood on given parameters +#' utils_fit a fonction running the kfino algorithm to filter data and +#' detect outliers under the knowledge of all parameters #' #' @param param list, see initial parameter list in \code{kfino_fit} #' @param threshold numeric, threshold for confidence interval, default 0.5 @@ -80,8 +81,8 @@ doutlier<-function(y, #' K=2, #' seqp=seq(0.5,0.7,0.1)) #' print(Y) -#' KBO_known(param=param2,threshold=0.5,kappa=10,Y=Y,Tps=Tps,N=N) -KBO_known<-function(param,threshold,kappa=10,Y,Tps,N){ +#' utils_fit(param=param2,threshold=0.5,kappa=10,Y=Y,Tps=Tps,N=N) +utils_fit<-function(param,threshold,kappa=10,Y,Tps,N){ # load objects mm=param[["mm"]] pp=param[["pp"]] @@ -234,7 +235,7 @@ KBO_known<-function(param,threshold,kappa=10,Y,Tps,N){ } #------------------------------------------------------------------------ -#' KBO_L a function to calculate a likelihood on initial parameters +#' utils_likelihood a function to calculate a likelihood on initial parameters #' optimized by a grid search #' #' @param param list, see initial parameter list in \code{kfino_fit} @@ -246,10 +247,12 @@ KBO_known<-function(param,threshold,kappa=10,Y,Tps,N){ #' numeric vector. #' Tvar can be expressed as a proportion of day in seconds #' @param N numeric, length of the numeric vector of Y values -#' @param scalingC numeric, scaling constant +#' @param scalingC numeric, scaling constant. To be changed if the function is +#' not able to calculate the likelihood because the number of data is large #' #' @details uses the same input parameter list than the main function #' @return a likelihood +#' @keywords internal #' @export #' #' @examples @@ -269,8 +272,8 @@ KBO_known<-function(param,threshold,kappa=10,Y,Tps,N){ #' K=2, #' seqp=seq(0.5,0.7,0.1)) #' print(Y) -#' KBO_L(param=param2,kappaOpt=7,Y=Y,Tps=Tps,N=N,scalingC=6) -KBO_L<-function(param,kappaOpt=7,Y,Tps,N,scalingC){ +#' utils_likelihood(param=param2,kappaOpt=7,Y=Y,Tps=Tps,N=N,scalingC=6) +utils_likelihood<-function(param,kappaOpt=7,Y,Tps,N,scalingC){ # load objects mm=param[["mm"]] pp=param[["pp"]] @@ -383,8 +386,8 @@ KBO_L<-function(param,kappaOpt=7,Y,Tps,N,scalingC){ } #------------------------------------------------------------------------ -#' KBO_EM a function to calculate a likelihood on initial parameters -#' optimized by an Expectation-Maximization (EM) algorithm +#' utils_EM a function to estimate the parameters `m_0` , `mm`, `pp` through +#' an Expectation-Maximization (EM) method #' #' @param param list, see initial parameter list in \code{kfino_fit} #' @param kappaOpt numeric, truncation setting for initial parameters' @@ -395,7 +398,8 @@ KBO_L<-function(param,kappaOpt=7,Y,Tps,N,scalingC){ #' numeric vector. #' Tvar can be expressed as a proportion of day in seconds #' @param N numeric, length of the numeric vector of Y values -#' @param scalingC numeric, scaling constant +#' @param scalingC numeric, scaling constant. To be changed if the function is +#' not able to calculate the likelihood because the number of data is large #' #' @details uses the same input parameter list than the main function #' @return a list: @@ -424,8 +428,8 @@ KBO_L<-function(param,kappaOpt=7,Y,Tps,N,scalingC){ #' K=2, #' seqp=seq(0.5,0.7,0.1)) #' print(Y) -#' KBO_EM(param=param2,kappaOpt=7,Y=Y,Tps=Tps,N=N,scalingC=6) -KBO_EM<-function(param,kappaOpt,Y,Tps,N,scalingC){ +#' utils_EM(param=param2,kappaOpt=7,Y=Y,Tps=Tps,N=N,scalingC=6) +utils_EM<-function(param,kappaOpt,Y,Tps,N,scalingC){ # load objects mm<-param[["mm"]] pp<-param[["pp"]] diff --git a/doc/HowTo.html b/doc/HowTo.html index 71ede75..d1b5598 100644 --- a/doc/HowTo.html +++ b/doc/HowTo.html @@ -1512,7 +1512,7 @@ div.tocify { <h1 class="title toc-ignore">How to perform a kfino outlier detection</h1> <h4 class="author">B. Cloez & I. Sanchez</h4> -<h4 class="date">septembre 13, 2022</h4> +<h4 class="date">septembre 14, 2022</h4> </div> @@ -1920,9 +1920,9 @@ informations</h1> #> loaded via a namespace (and not attached): #> [1] highr_0.9 pillar_1.8.1 bslib_0.4.0 compiler_4.2.1 #> [5] jquerylib_0.1.4 tools_4.2.1 digest_0.6.29 jsonlite_1.8.0 -#> [9] evaluate_0.16 lifecycle_1.0.1 tibble_3.1.8 gtable_0.3.1 -#> [13] pkgconfig_2.0.3 rlang_1.0.5 cli_3.3.0 DBI_1.1.3 -#> [17] rstudioapi_0.14 yaml_2.3.5 xfun_0.32 fastmap_1.1.0 +#> [9] evaluate_0.16 lifecycle_1.0.2 tibble_3.1.8 gtable_0.3.1 +#> [13] pkgconfig_2.0.3 rlang_1.0.5 cli_3.4.0 DBI_1.1.3 +#> [17] rstudioapi_0.14 yaml_2.3.5 xfun_0.33 fastmap_1.1.0 #> [21] withr_2.5.0 stringr_1.4.1 knitr_1.40 generics_0.1.3 #> [25] vctrs_0.4.1 sass_0.4.2 grid_4.2.1 tidyselect_1.1.2 #> [29] glue_1.6.2 R6_2.5.1 fansi_1.0.3 rmarkdown_2.16 diff --git a/doc/multipleFit.html b/doc/multipleFit.html index da848d0..62d44b0 100644 --- a/doc/multipleFit.html +++ b/doc/multipleFit.html @@ -1512,7 +1512,7 @@ div.tocify { <h1 class="title toc-ignore">How to perform a kfino outlier detection on multiple individuals</h1> <h4 class="author">B. Cloez & I. Sanchez</h4> -<h4 class="date">septembre 13, 2022</h4> +<h4 class="date">septembre 14, 2022</h4> </div> @@ -1571,7 +1571,7 @@ for (i in seq_along(myIDE)){ #> [1] "250017033503096" #> [1] 566 5 Sys.time() - t0 -#> Time difference of 18.85249 secs +#> Time difference of 18.46779 secs print(length(resu1)) #> [1] 4</code></pre> @@ -1620,7 +1620,7 @@ resu2<-foreach(i=seq_along(myIDE), .packages="kfino") %dopar% parallel::stopCluster(myCluster) Sys.time() - t0 -#> Time difference of 9.442032 secs +#> Time difference of 9.275384 secs print(length(resu2)) #> [1] 4</code></pre> @@ -1667,9 +1667,9 @@ Adaptor for the ‘parallel’ Package</em>. R package version 1.0.17, <a href=" #> loaded via a namespace (and not attached): #> [1] highr_0.9 pillar_1.8.1 bslib_0.4.0 compiler_4.2.1 #> [5] jquerylib_0.1.4 tools_4.2.1 digest_0.6.29 jsonlite_1.8.0 -#> [9] evaluate_0.16 lifecycle_1.0.1 tibble_3.1.8 gtable_0.3.1 -#> [13] pkgconfig_2.0.3 rlang_1.0.5 cli_3.3.0 DBI_1.1.3 -#> [17] rstudioapi_0.14 yaml_2.3.5 xfun_0.32 fastmap_1.1.0 +#> [9] evaluate_0.16 lifecycle_1.0.2 tibble_3.1.8 gtable_0.3.1 +#> [13] pkgconfig_2.0.3 rlang_1.0.5 cli_3.4.0 DBI_1.1.3 +#> [17] rstudioapi_0.14 yaml_2.3.5 xfun_0.33 fastmap_1.1.0 #> [21] withr_2.5.0 stringr_1.4.1 knitr_1.40 generics_0.1.3 #> [25] vctrs_0.4.1 sass_0.4.2 grid_4.2.1 tidyselect_1.1.2 #> [29] glue_1.6.2 R6_2.5.1 fansi_1.0.3 rmarkdown_2.16 diff --git a/man/kfino_fit.Rd b/man/kfino_fit.Rd index 7d326d8..b0bc99d 100644 --- a/man/kfino_fit.Rd +++ b/man/kfino_fit.Rd @@ -31,19 +31,19 @@ Tvar should be expressed as a proportion of day in seconds} default TRUE} \item{method}{character, the method used to optimize the initial parameters: -Expectation-Maximization algorithm `"EM"` or Maximization -Likelihood `"ML"`, default `"ML"`} +Expectation-Maximization algorithm `"EM"` (faster) or Maximization +Likelihood `"ML"` (more robust), default `"ML"`} \item{threshold}{numeric, threshold to qualify an observation as outlier according to the label_pred, default 0.5} -\item{kappa}{numeric, truncation setting for likelihood optimization, -default 10} +\item{kappa}{numeric, truncation setting for likelihood optimization over +initial parameters, default 10} -\item{kappaOpt}{numeric, truncation setting for initial parameters' -optimization, default 7} +\item{kappaOpt}{numeric, truncation setting for the filtering and outlier +detection step with optimized parameters, default 7} -\item{verbose}{write stuff if TRUE (optional), default FALSE.} +\item{verbose}{write details if TRUE (optional), default FALSE.} } \value{ a S3 list with two data frames and a list of vectors of @@ -59,7 +59,9 @@ detectOutlier: The whole input data set with the detected outliers \item{lwr}{lower bound of the confidence interval of the predicted value} \item{upr}{upper bound of the confidence interval of the predicted value} \item{flag}{flag of the value (OK value, KO value (outlier), OOR value - (out of range values defined by the user in `kfino_fit`)} + (out of range values defined by the user in `kfino_fit` with + `expertMin`, `expertMax` input parameters). If + flag == OOR the 4 previous columns are set to NA.} } PredictionOK: A subset of `detectOutlier` data set with the predictions diff --git a/man/KBO_EM.Rd b/man/utils_EM.Rd similarity index 69% rename from man/KBO_EM.Rd rename to man/utils_EM.Rd index 591ebf3..7c19d22 100644 --- a/man/KBO_EM.Rd +++ b/man/utils_EM.Rd @@ -1,11 +1,11 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/utils_functions.R -\name{KBO_EM} -\alias{KBO_EM} -\title{KBO_EM a function to calculate a likelihood on initial parameters -optimized by an Expectation-Maximization (EM) algorithm} +\name{utils_EM} +\alias{utils_EM} +\title{utils_EM a function to estimate the parameters `m_0` , `mm`, `pp` through +an Expectation-Maximization (EM) method} \usage{ -KBO_EM(param, kappaOpt, Y, Tps, N, scalingC) +utils_EM(param, kappaOpt, Y, Tps, N, scalingC) } \arguments{ \item{param}{list, see initial parameter list in \code{kfino_fit}} @@ -22,7 +22,8 @@ Tvar can be expressed as a proportion of day in seconds} \item{N}{numeric, length of the numeric vector of Y values} -\item{scalingC}{numeric, scaling constant} +\item{scalingC}{numeric, scaling constant. To be changed if the function is +not able to calculate the likelihood because the number of data is large} } \value{ a list: @@ -34,8 +35,8 @@ a list: } } \description{ -KBO_EM a function to calculate a likelihood on initial parameters -optimized by an Expectation-Maximization (EM) algorithm +utils_EM a function to estimate the parameters `m_0` , `mm`, `pp` through +an Expectation-Maximization (EM) method } \details{ uses the same input parameter list than the main function @@ -57,5 +58,5 @@ param2<-list(m0=41, K=2, seqp=seq(0.5,0.7,0.1)) print(Y) -KBO_EM(param=param2,kappaOpt=7,Y=Y,Tps=Tps,N=N,scalingC=6) +utils_EM(param=param2,kappaOpt=7,Y=Y,Tps=Tps,N=N,scalingC=6) } diff --git a/man/KBO_known.Rd b/man/utils_fit.Rd similarity index 78% rename from man/KBO_known.Rd rename to man/utils_fit.Rd index fe48f4c..4372b67 100644 --- a/man/KBO_known.Rd +++ b/man/utils_fit.Rd @@ -1,10 +1,11 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/utils_functions.R -\name{KBO_known} -\alias{KBO_known} -\title{KBO_known a function to calculate a likelihood on given parameters} +\name{utils_fit} +\alias{utils_fit} +\title{utils_fit a fonction running the kfino algorithm to filter data and + detect outliers under the knowledge of all parameters} \usage{ -KBO_known(param, threshold, kappa = 10, Y, Tps, N) +utils_fit(param, threshold, kappa = 10, Y, Tps, N) } \arguments{ \item{param}{list, see initial parameter list in \code{kfino_fit}} @@ -35,7 +36,8 @@ a list } } \description{ -KBO_known a function to calculate a likelihood on given parameters +utils_fit a fonction running the kfino algorithm to filter data and + detect outliers under the knowledge of all parameters } \details{ uses the same input parameter list than the main function @@ -57,5 +59,5 @@ param2<-list(m0=41, K=2, seqp=seq(0.5,0.7,0.1)) print(Y) -KBO_known(param=param2,threshold=0.5,kappa=10,Y=Y,Tps=Tps,N=N) +utils_fit(param=param2,threshold=0.5,kappa=10,Y=Y,Tps=Tps,N=N) } diff --git a/man/KBO_L.Rd b/man/utils_likelihood.Rd similarity index 68% rename from man/KBO_L.Rd rename to man/utils_likelihood.Rd index f7c4b53..05bf42e 100644 --- a/man/KBO_L.Rd +++ b/man/utils_likelihood.Rd @@ -1,11 +1,11 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/utils_functions.R -\name{KBO_L} -\alias{KBO_L} -\title{KBO_L a function to calculate a likelihood on initial parameters +\name{utils_likelihood} +\alias{utils_likelihood} +\title{utils_likelihood a function to calculate a likelihood on initial parameters optimized by a grid search} \usage{ -KBO_L(param, kappaOpt = 7, Y, Tps, N, scalingC) +utils_likelihood(param, kappaOpt = 7, Y, Tps, N, scalingC) } \arguments{ \item{param}{list, see initial parameter list in \code{kfino_fit}} @@ -22,13 +22,14 @@ Tvar can be expressed as a proportion of day in seconds} \item{N}{numeric, length of the numeric vector of Y values} -\item{scalingC}{numeric, scaling constant} +\item{scalingC}{numeric, scaling constant. To be changed if the function is +not able to calculate the likelihood because the number of data is large} } \value{ a likelihood } \description{ -KBO_L a function to calculate a likelihood on initial parameters +utils_likelihood a function to calculate a likelihood on initial parameters optimized by a grid search } \details{ @@ -51,5 +52,6 @@ param2<-list(m0=41, K=2, seqp=seq(0.5,0.7,0.1)) print(Y) -KBO_L(param=param2,kappaOpt=7,Y=Y,Tps=Tps,N=N,scalingC=6) +utils_likelihood(param=param2,kappaOpt=7,Y=Y,Tps=Tps,N=N,scalingC=6) } +\keyword{internal} diff --git a/tests/testthat/test-outputAlgo.R b/tests/testthat/test-outputAlgo.R index d3a1992..9aeab27 100644 --- a/tests/testthat/test-outputAlgo.R +++ b/tests/testthat/test-outputAlgo.R @@ -57,7 +57,7 @@ test_that("kfino - optimisation - computed correctly", { expect_equal(as.vector(resu1[[3]]$likelihood),1.035855e-135) }) -test_that("KBO_L - likelihood - computed correctly", { +test_that("utils_likelihood - likelihood - computed correctly", { set.seed(1234) Y<-rnorm(n=10,mean=50,4) Tps<-seq(1,10) @@ -73,7 +73,7 @@ test_that("KBO_L - likelihood - computed correctly", { sigma2_pp=5, K=2, seqp=seq(0.5,0.7,0.1)) - resu<-KBO_L(param=param2,Y=Y,Tps=Tps,N=N,scalingC=6,kappaOpt=7) + resu<-utils_likelihood(param=param2,Y=Y,Tps=Tps,N=N,scalingC=6,kappaOpt=7) expect_equal(as.vector(resu),0.00490257592) -- GitLab