R Under development (unstable) (2024-07-10 r86888 ucrt) -- "Unsuffered Consequences" Copyright (C) 2024 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > visualize <- FALSE # TRUE for manual tests with visualization of results > require(fitdistrplus) Loading required package: fitdistrplus Loading required package: MASS Loading required package: survival > > myoptimize <- function(fn,par,ui,ci,...){ + res <- constrOptim(f=fn,theta=par,method="Nelder-Mead",ui=ui,ci=ci, ...) + standardres <- c(res,convergence=0,value=res$objective,par=res$minimum,hessian=NA) + return(standardres) + } > > > #one parameter example > x <- rexp(100) > > #binding example > fitdist(x, "exp", custom.optim=myoptimize, ui=1, ci=2, start=list(rate=10)) Fitting of the distribution ' exp ' by maximum likelihood Parameters: estimate rate 2 > fitdist(x, "exp", lower= 2, optim.method="L-BFGS-B") Fitting of the distribution ' exp ' by maximum likelihood Parameters: estimate Std. Error rate 2 0.1999999 > > #two parameter example > > if(visualize) { # check ERROR on aarch64-apple-darwin20.4.0 (64-bit) (2021/05/12) + x <- rbeta(100, pi, 1/pi) + + set.seed(1234) + fitdist(x, "beta") + + #binding example + fitdist(x, "beta", custom.optim=myoptimize, ui=rbind(1,1), ci=c(1/2,1/2), start=list(shape1=5, shape2=5)) + fitdist(x, "beta", lower= c(1/2,1/2), optim.method="L-BFGS-B") + } > > > #true example > library(GeneralizedHyperbolic) > args(dnig) function (x, mu = 0, delta = 1, alpha = 1, beta = 0, param = c(mu, delta, alpha, beta)) NULL > > > x <- rnig(100, 3, 1/2, 1/2, 1/4) > ui<-rbind(c(0,1,0,0),c(0,0,1,0),c(0,0,1,-1),c(0,0,1,1)) > ci<-c(0,0,0,0) > fitdist(x, "nig", custom.optim=myoptimize, ui=ui, ci=ci, start=list(mu = 0, delta = 1, alpha = 1, beta = 0)) Fitting of the distribution ' nig ' by maximum likelihood Parameters: estimate mu 2.9008141 delta 0.7821121 alpha 1.0770687 beta 0.3289673 Warning messages: 1: In fitdist(x, "nig", custom.optim = myoptimize, ui = ui, ci = ci, : The dnig function should return a vector of with NaN values when input has inconsistent parameters and not raise an error 2: In fitdist(x, "nig", custom.optim = myoptimize, ui = ui, ci = ci, : The pnig function should return a vector of with NaN values when input has inconsistent values and not raise an error > > > proc.time() user system elapsed 1.67 0.25 1.90