diff --git a/NAMESPACE b/NAMESPACE index 4ec3f732cda1d0160df93983aed056ffc6e5cd4a..27b81e64119211b38b2f266f70c305c485c1e912 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -5,6 +5,7 @@ export(KBO_known) export(kfino_fit) export(kfino_fit2) export(kfino_plot) +export(loi_outlier) importFrom(dplyr,"%>%") importFrom(dplyr,.data) importFrom(dplyr,arrange) diff --git a/R/utils.R b/R/utils.R index a59db8f024c0b29b0c2abec6ba2abcdd3fd6751b..9816d619c755c6b893eea8410f2a6b0db96d46fa 100644 --- a/R/utils.R +++ b/R/utils.R @@ -1,3 +1,28 @@ +#' loi_outlier This function defines an outlier distribution (Surface of a +#' trapezium) and uses input parameters given in the main function kfino_fit() +#' +#' @param y numeric, point +#' @param K numeric, constant value +#' @param expertMin numeric, the minimal weight expected by the user +#' @param expertMax numeric, the maximal weight expected by the user +#' +#' @details this function is used to calculate an outlier distribution +#' following a trapezium shape +#' @return a numeric value +#' @export +#' +#' @examples +#' loi_outlier(2,5,10,45) +loi_outlier<-function(y, + K, + expertMin, + expertMax){ + 2/((K+1)*(expertMax - expertMin)) + + (2*(K-1)/(K+1))*((y - expertMin)/((expertMax - expertMin)^2)) +} + + +#-------------------------------------------------------------------------- #' KBO_known #' #' @param param list, a list of 10 input parameters for mm, pp and m0 @@ -28,19 +53,12 @@ KBO_known<-function(param,threshold,Y,Tps,N){ # paramètre de troncature kappa <-10 - #--- function defining an outlier distribution (Surface of a trapezium) - # uses expertMin and expertMax - loi_outlier<-function(y){ - 2/((K+1)*(expertMax - expertMin)) + - (2*(K-1)/(K+1))*((y - expertMin)/((expertMax - expertMin)^2)) - } - # initialisation (1.1.1) #-------------------- m1= (sigma2_pp*m0 + Y[1]*sigma2_m0)/(sigma2_m0+sigma2_pp) sigma1=(sigma2_m0*sigma2_pp)/(sigma2_m0+sigma2_pp) - l0<- loi_outlier(Y[1]) + l0<- loi_outlier(Y[1],K,expertMin,expertMax) loinorm1<-dnorm(Y[1],m0, sqrt(sigma2_m0+sigma2_pp)) p0= ((1-pp)*l0) / (pp*loinorm1 + (1-pp)*l0) @@ -71,7 +89,7 @@ KBO_known<-function(param,threshold,Y,Tps,N){ qnew=rep(0 ,2^(k+1)) diffTps<-Tps[k+1] - Tps[k] #--- numérateur de pu0 - tpbeta<-loi_outlier(Y[k+1]) + tpbeta<-loi_outlier(Y[k+1],K,expertMin,expertMax) pnew[1:(2^k)]=p[1:(2^k)]*(1-pp)*tpbeta Lnew[1:(2^k)]=L[1:(2^k)]*tpbeta @@ -117,7 +135,7 @@ KBO_known<-function(param,threshold,Y,Tps,N){ diffTps<-Tps[k+1] - Tps[k] #--- numérateur de pu0 - tpbeta<-loi_outlier(Y[k+1]) + tpbeta<-loi_outlier(Y[k+1],K,expertMin,expertMax) pnew[1:(2^kappa)]=p[1:(2^kappa)]*(1-pp)*tpbeta Lnew[1:(2^kappa)]=L[1:(2^kappa)]*tpbeta @@ -200,13 +218,6 @@ KBO_L<-function(param,Y,Tps,N,dix){ sigma2_pp<-param[["sigma2_pp"]] K<-param[["K"]] - #--- function defining an outlier distribution (Surface of a trapezium) - # uses expertMin and expertMax - loi_outlier<-function(y){ - 2/((K+1)*(expertMax - expertMin)) + - (2*(K-1)/(K+1))*((y - expertMin)/((expertMax - expertMin)^2)) - } - #---- paramètre de troncature # Ici je met kappa =7, ca me fais retirer les proba <0.01 au lieu de 0.001 # comme qd kappa=10 mais ca divise par 10 le temps de calcul @@ -217,7 +228,7 @@ KBO_L<-function(param,Y,Tps,N,dix){ m1= (sigma2_pp*m0 + Y[1]*sigma2_m0)/(sigma2_m0+sigma2_pp) sigma1=(sigma2_m0*sigma2_pp)/(sigma2_m0+sigma2_pp) - l0<- loi_outlier(Y[1]) + l0<- loi_outlier(Y[1],K,expertMin,expertMax) loinorm1<-dnorm(Y[1],m0, sqrt(sigma2_m0+sigma2_pp)) p0= ((1-pp)*l0) / (pp*loinorm1 + (1-pp)*l0) @@ -242,7 +253,7 @@ KBO_L<-function(param,Y,Tps,N,dix){ qnew=rep(0 ,2^(k+1)) diffTps<-Tps[k+1] - Tps[k] #--- numérateur de pu0 - tpbeta<-loi_outlier(Y[k+1]) + tpbeta<-loi_outlier(Y[k+1],K,expertMin,expertMax) pnew[1:(2^k)]=p[1:(2^k)]*(1-pp)*tpbeta Lnew[1:(2^k)]=L[1:(2^k)]*tpbeta mnew[1:(2^k)]= m[1:(2^k)]*exp(-aa*diffTps) + mm*(1-exp(-aa*diffTps)) #m_u0 @@ -277,7 +288,7 @@ KBO_L<-function(param,Y,Tps,N,dix){ qnew=rep(0 ,2^(kappa+1)) diffTps<-Tps[k+1] - Tps[k] #--- numérateur de pu0 - tpbeta<-loi_outlier(Y[k+1]) + tpbeta<-loi_outlier(Y[k+1],K,expertMin,expertMax) pnew[1:(2^kappa)]=p[1:(2^kappa)]*(1-pp)*tpbeta Lnew[1:(2^kappa)]=L[1:(2^kappa)]*tpbeta mnew[1:(2^kappa)]= m[1:(2^kappa)]*exp(-aa*diffTps) + mm*(1-exp(-aa*diffTps)) #m_u0 diff --git a/man/loi_outlier.Rd b/man/loi_outlier.Rd new file mode 100644 index 0000000000000000000000000000000000000000..14d1ac847e05fc1c4c9c5afd95a7964ae4a82c39 --- /dev/null +++ b/man/loi_outlier.Rd @@ -0,0 +1,32 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/utils.R +\name{loi_outlier} +\alias{loi_outlier} +\title{loi_outlier This function defines an outlier distribution (Surface of a +trapezium) and uses input parameters given in the main function kfino_fit()} +\usage{ +loi_outlier(y, K, expertMin, expertMax) +} +\arguments{ +\item{y}{numeric, point} + +\item{K}{numeric, constant value} + +\item{expertMin}{numeric, the minimal weight expected by the user} + +\item{expertMax}{numeric, the maximal weight expected by the user} +} +\value{ +a numeric value +} +\description{ +loi_outlier This function defines an outlier distribution (Surface of a +trapezium) and uses input parameters given in the main function kfino_fit() +} +\details{ +this function is used to calculate an outlier distribution + following a trapezium shape +} +\examples{ +loi_outlier(2,5,10,45) +}