diff --git a/R/kfino.R b/R/kfino.R index 1a2db71d8b0feff408b82d07f8744d9923177dfd..b02e62c2a56add68de6dc3d92bf5479dd0a8f9ab 100644 --- a/R/kfino.R +++ b/R/kfino.R @@ -185,10 +185,10 @@ kfino_fit<-function(datain,Tvar,Yvar, #WARNING WARNING: AU lieu de calculer L qui est arrondi à 0, # je calcule 10^N fois Lu et 10^N q. Au total pr chaque donnée - # je multiplie par 100 mais comme c'est l'ordre de grandeur de loioutlier() + # je multiplie par 100 mais comme c'est l'ordre de grandeur de doutlier() # ca ne me parait pas disproportionné. # Au lieu de 10 et 10 je fais simplement sqrt(expertMax - expertMin) - dix=sqrt(expertMax - expertMin) + scalingC=sqrt(expertMax - expertMin) #------------------------------------------------------------------------ # Optimisation on Initial parameters or not @@ -227,7 +227,7 @@ kfino_fit<-function(datain,Tvar,Yvar, sigma2_m0=sigma2_m0, sigma2_pp=sigma2_pp, K=K), - Y=Y,Tps=Tps,N=N,dix=dix,kappaOpt=kappaOpt) + 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) ){ @@ -248,7 +248,7 @@ kfino_fit<-function(datain,Tvar,Yvar, sigma2_m0=sigma2_m0, sigma2_pp=sigma2_pp, K=K), - Y=Y,Tps=Tps,N=N,dix=dix,kappaOpt=kappaOpt) + Y=Y,Tps=Tps,N=N,scalingC=scalingC,kappaOpt=kappaOpt) if (V > Vopt){ Vopt=V m0opt=m0 @@ -311,7 +311,7 @@ kfino_fit<-function(datain,Tvar,Yvar, sigma2_mm=sigma2_mm, sigma2_pp=sigma2_pp, K=K), - kappaOpt=kappaOpt, Y=Y,Tps=Tps,N=N,dix=dix) + 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]]) @@ -345,7 +345,7 @@ kfino_fit<-function(datain,Tvar,Yvar, sigma2_mm=sigma2_mm, sigma2_pp=sigma2_pp, K=K), - kappaOpt=kappaOpt, Y=Y,Tps=Tps,N=N,dix=dix) + 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]]) @@ -384,7 +384,7 @@ kfino_fit<-function(datain,Tvar,Yvar, sigma2_mm=sigma2_mm, sigma2_pp=sigma2_pp, K=K), - kappaOpt=kappaOpt, Y=Y,Tps=Tps,N=N,dix=dix) + 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]]) @@ -430,7 +430,8 @@ kfino_fit<-function(datain,Tvar,Yvar, sigma2_m0=sigma2_m0, sigma2_pp=sigma2_pp, K=K), - Y=Y,Tps=Tps,N=N,dix=dix,kappaOpt=kappaOpt)$likelihood + Y=Y,Tps=Tps,N=N,scalingC=scalingC, + kappaOpt=kappaOpt)$likelihood if (Vopt_low > Vopt){ m0opt<-m0opt_low @@ -479,7 +480,7 @@ kfino_fit<-function(datain,Tvar,Yvar, sigma2_m0=sigma2_m0, sigma2_pp=sigma2_pp, K=K), - Y=Y,Tps=Tps,N=N,dix=dix,kappaOpt=kappaOpt) + 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){ @@ -493,7 +494,7 @@ kfino_fit<-function(datain,Tvar,Yvar, sigma2_m0=sigma2_m0, sigma2_pp=sigma2_pp, K=K), - Y=Y,Tps=Tps,N=N,dix=dix,kappaOpt=kappaOpt) + Y=Y,Tps=Tps,N=N,scalingC=scalingC,kappaOpt=kappaOpt) if (V > Vopt){ Vopt=V diff --git a/R/utils_functions.R b/R/utils_functions.R index ef18f9cf312e67575796599618504778f112d71a..0d94b02e21964623129cfcd50f1ced5299d5dc84 100644 --- a/R/utils_functions.R +++ b/R/utils_functions.R @@ -33,15 +33,16 @@ doutlier<-function(y, #-------------------------------------------------------------------------- #' KBO_known a function to calculate a likelihood on given parameters #' -#' @param param list, a list of 10 input parameters for mm, pp and m0 +#' @param param list, see initial parameter list in \code{kfino_fit} #' @param threshold numeric, threshold for CI, default 0.5 -#' @param kappa numeric, truncation setting, default 10 +#' @param kappa numeric, truncation setting for likelihood optimization, +#' default 10 #' @param Y character, name of the numeric variable to predict in the #' data.frame datain #' @param Tps character, time column name in the data.frame datain, a #' numeric vector. #' Tvar can be expressed as a proportion of day in seconds -#' @param N numeric, length of Y +#' @param N numeric, length of the numeric vector of Y values #' #' @details uses the same input parameter list than the main function #' @return a list @@ -229,15 +230,16 @@ KBO_known<-function(param,threshold,kappa=10,Y,Tps,N){ #' KBO_L a function to calculate a likelihood on initial parameters #' optimized by a grid search #' -#' @param param a list of 10 input parameters mm, pp and m0 -#' @param kappaOpt numeric, truncation setting, default 7 +#' @param param list, see initial parameter list in \code{kfino_fit} +#' @param kappaOpt numeric, truncation setting for initial parameters' +#' optimization, default 7 #' @param Y character, name of the numeric variable to predict in the #' data.frame datain #' @param Tps character, time column name in the data.frame datain, a #' numeric vector. #' Tvar can be expressed as a proportion of day in seconds -#' @param N numeric, length of Y -#' @param dix num +#' @param N numeric, length of the numeric vector of Y values +#' @param scalingC numeric, scaling constant #' #' @details uses the same input parameter list than the main function #' @return a likelihood @@ -258,10 +260,10 @@ KBO_known<-function(param,threshold,kappa=10,Y,Tps,N){ #' sigma2_mm=0.05, #' sigma2_pp=5, #' K=2, -#' seqp=seq(0.5,0.7,0.1)) +#' seqp=seq(0.5,0.7,0.1)) #' print(Y) -#' KBO_L(param=param2,kappaOpt=7,Y=Y,Tps=Tps,N=N,dix=6) -KBO_L<-function(param,kappaOpt=7,Y,Tps,N,dix){ +#' KBO_L(param=param2,kappaOpt=7,Y=Y,Tps=Tps,N=N,scalingC=6) +KBO_L<-function(param,kappaOpt=7,Y,Tps,N,scalingC){ # load objects mm=param[["mm"]] pp=param[["pp"]] @@ -293,8 +295,8 @@ KBO_L<-function(param,kappaOpt=7,Y,Tps,N,dix){ m=c(m0,m1) p=c(p0,p1) sigma2=c(sigma2_m0,sigma1) - L=dix*c(l0,loinorm1) #Attention *2 pr le grandir - q=c(1,1) #attention + L=scalingC*c(l0,loinorm1) # increase it with the scaling constant + q=c(1,1) #iteration (1.1.2) #----------------------- @@ -327,8 +329,8 @@ KBO_L<-function(param,kappaOpt=7,Y,Tps,N,dix){ sigma2=sigma2new p=pnew/sum(pnew) - L=dix*Lnew - q=dix*qnew + L=scalingC*Lnew + q=scalingC*qnew } # after truncation @@ -364,8 +366,8 @@ KBO_L<-function(param,kappaOpt=7,Y,Tps,N,dix){ m=mnew[selection] sigma2=sigma2new[selection] p=pnew[selection]/sum(pnew[selection]) - L=dix*Lnew[selection] - q=dix*qnew[selection] + L=scalingC*Lnew[selection] + q=scalingC*qnew[selection] } Vraisemblance=L%*%q @@ -377,15 +379,16 @@ KBO_L<-function(param,kappaOpt=7,Y,Tps,N,dix){ #' KBO_EM a function to calculate a likelihood on initial parameters #' optimized by an Expectation-Maximization (EM) algorithm #' -#' @param param a list of 10 input parameters mm, pp and m0 -#' @param kappaOpt numeric, truncation setting, default 7 +#' @param param list, see initial parameter list in \code{kfino_fit} +#' @param kappaOpt numeric, truncation setting for initial parameters' +#' optimization, default 7 #' @param Y character, name of the numeric variable to predict in the #' data.frame datain #' @param Tps character, time column name in the data.frame datain, a #' numeric vector. #' Tvar can be expressed as a proportion of day in seconds -#' @param N numeric, length of Y -#' @param dix num +#' @param N numeric, length of the numeric vector of Y values +#' @param scalingC numeric, scaling constant #' #' @details uses the same input parameter list than the main function #' @return a list: @@ -412,10 +415,10 @@ KBO_L<-function(param,kappaOpt=7,Y,Tps,N,dix){ #' sigma2_mm=0.05, #' sigma2_pp=5, #' K=2, -#' seqp=seq(0.5,0.7,0.1)) +#' seqp=seq(0.5,0.7,0.1)) #' print(Y) -#' KBO_EM(param=param2,kappaOpt=7,Y=Y,Tps=Tps,N=N,dix=6) -KBO_EM<-function(param,kappaOpt,Y,Tps,N,dix){ +#' KBO_EM(param=param2,kappaOpt=7,Y=Y,Tps=Tps,N=N,scalingC=6) +KBO_EM<-function(param,kappaOpt,Y,Tps,N,scalingC){ # load objects mm<-param[["mm"]] pp<-param[["pp"]] @@ -447,8 +450,8 @@ KBO_EM<-function(param,kappaOpt,Y,Tps,N,dix){ m=c(m0,m1) p=c(p0,p1) sigma2=c(sigma2_m0,sigma1) - L=dix*c(l0,loinorm1) #Attention *2 pr le grandir - q=c(1,1) #attention + L=scalingC*c(l0,loinorm1) + q=c(1,1) a=c(1,sigma2_pp/(sigma2_m0+sigma2_pp)) b=c(0,0) @@ -521,8 +524,8 @@ KBO_EM<-function(param,kappaOpt,Y,Tps,N,dix){ Znew[(2^k+1):(2^(k+1)),]=cbind(Z, rep(1,2^k)) Z=Znew - L=dix*Lnew # fois 2 pr le grandir - q=dix*qnew + L=scalingC*Lnew # fois 2 pr le grandir + q=scalingC*qnew } # after truncation @@ -573,8 +576,8 @@ KBO_EM<-function(param,kappaOpt,Y,Tps,N,dix){ m=mnew[selection] sigma2=sigma2new[selection] p=pnew[selection]/sum(pnew[selection]) - L=dix*Lnew[selection] #fois 2 pr le grandir - q=dix*qnew[selection] + L=scalingC*Lnew[selection] + q=scalingC*qnew[selection] Znew=matrix(rep(0,(k+1)*2^(kappa+1)), ncol=k+1, nrow=2^(kappa+1), byrow=TRUE) Znew[1:2^kappa,]=cbind(Z, rep(0,2^kappa)) diff --git a/man/KBO_EM.Rd b/man/KBO_EM.Rd index 1b5835a667468928b63322c1c1189c66ec6f3fdc..591ebf3e361991e8ffd819048ed6afe6075ee3d6 100644 --- a/man/KBO_EM.Rd +++ b/man/KBO_EM.Rd @@ -5,12 +5,13 @@ \title{KBO_EM a function to calculate a likelihood on initial parameters optimized by an Expectation-Maximization (EM) algorithm} \usage{ -KBO_EM(param, kappaOpt, Y, Tps, N, dix) +KBO_EM(param, kappaOpt, Y, Tps, N, scalingC) } \arguments{ -\item{param}{a list of 10 input parameters mm, pp and m0} +\item{param}{list, see initial parameter list in \code{kfino_fit}} -\item{kappaOpt}{numeric, truncation setting, default 7} +\item{kappaOpt}{numeric, truncation setting for initial parameters' +optimization, default 7} \item{Y}{character, name of the numeric variable to predict in the data.frame datain} @@ -19,9 +20,9 @@ data.frame datain} numeric vector. Tvar can be expressed as a proportion of day in seconds} -\item{N}{numeric, length of Y} +\item{N}{numeric, length of the numeric vector of Y values} -\item{dix}{num} +\item{scalingC}{numeric, scaling constant} } \value{ a list: @@ -54,7 +55,7 @@ param2<-list(m0=41, sigma2_mm=0.05, sigma2_pp=5, K=2, - seqp=seq(0.5,0.7,0.1)) + seqp=seq(0.5,0.7,0.1)) print(Y) -KBO_EM(param=param2,kappaOpt=7,Y=Y,Tps=Tps,N=N,dix=6) +KBO_EM(param=param2,kappaOpt=7,Y=Y,Tps=Tps,N=N,scalingC=6) } diff --git a/man/KBO_L.Rd b/man/KBO_L.Rd index a951cb6f39db6d8628725d2b64b67b391794bb22..f7c4b533c004500267a7ef342365d7a4ceb04e46 100644 --- a/man/KBO_L.Rd +++ b/man/KBO_L.Rd @@ -5,12 +5,13 @@ \title{KBO_L a function to calculate a likelihood on initial parameters optimized by a grid search} \usage{ -KBO_L(param, kappaOpt = 7, Y, Tps, N, dix) +KBO_L(param, kappaOpt = 7, Y, Tps, N, scalingC) } \arguments{ -\item{param}{a list of 10 input parameters mm, pp and m0} +\item{param}{list, see initial parameter list in \code{kfino_fit}} -\item{kappaOpt}{numeric, truncation setting, default 7} +\item{kappaOpt}{numeric, truncation setting for initial parameters' +optimization, default 7} \item{Y}{character, name of the numeric variable to predict in the data.frame datain} @@ -19,9 +20,9 @@ data.frame datain} numeric vector. Tvar can be expressed as a proportion of day in seconds} -\item{N}{numeric, length of Y} +\item{N}{numeric, length of the numeric vector of Y values} -\item{dix}{num} +\item{scalingC}{numeric, scaling constant} } \value{ a likelihood @@ -48,7 +49,7 @@ param2<-list(m0=41, sigma2_mm=0.05, sigma2_pp=5, K=2, - seqp=seq(0.5,0.7,0.1)) + seqp=seq(0.5,0.7,0.1)) print(Y) -KBO_L(param=param2,kappaOpt=7,Y=Y,Tps=Tps,N=N,dix=6) +KBO_L(param=param2,kappaOpt=7,Y=Y,Tps=Tps,N=N,scalingC=6) } diff --git a/man/KBO_known.Rd b/man/KBO_known.Rd index 641f63812cabe3468fa75c218427b1cf22c4507e..e28e51fafc0f7ee221d2d15ee76b7935cb19fa78 100644 --- a/man/KBO_known.Rd +++ b/man/KBO_known.Rd @@ -7,11 +7,12 @@ KBO_known(param, threshold, kappa = 10, Y, Tps, N) } \arguments{ -\item{param}{list, a list of 10 input parameters for mm, pp and m0} +\item{param}{list, see initial parameter list in \code{kfino_fit}} \item{threshold}{numeric, threshold for CI, default 0.5} -\item{kappa}{numeric, truncation setting, default 10} +\item{kappa}{numeric, truncation setting for likelihood optimization, +default 10} \item{Y}{character, name of the numeric variable to predict in the data.frame datain} @@ -20,7 +21,7 @@ data.frame datain} numeric vector. Tvar can be expressed as a proportion of day in seconds} -\item{N}{numeric, length of Y} +\item{N}{numeric, length of the numeric vector of Y values} } \value{ a list