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. > library(fitdistrplus) Loading required package: MASS Loading required package: survival > > > > #an example with lower bounds for gamma > > data(groundbeef) > serving <- groundbeef$serving > #(f1 <- fitdist(serving, "gamma", optim.method="Nelder-Mead")) > (f1 <- fitdist(serving, "gamma", optim.method="Nelder-Mead", lower=0)) Fitting of the distribution ' gamma ' by maximum likelihood Parameters: estimate Std. Error shape 4.00748101 0.359909 rate 0.05441516 1.586904 > > f1 <- mledist(serving, "gamma", optim.method="Nelder-Mead", lower=0) > > f1 <- fitdist(serving, "gamma", start=as.list(f1$estimate)) > > #manual optimization > lnl <- function(theta, obs, dfun) + sum(do.call(dfun, c(list("x"=obs), theta, "log"=TRUE))) > > H <- optimHess(coef(f1), lnl, obs=serving, dfun=dgamma) > > -solve(H) shape rate shape 0.116463806 1.580501e-03 rate 0.001580501 2.435556e-05 > vcov(fitdist(serving, "gamma", start=as.list(f1$estimate))) shape rate shape 0.116463806 1.580501e-03 rate 0.001580501 2.435556e-05 > > > > #an example with lower bounds for ztbinom > if(FALSE) + { + library(actuar) + n <- 1e3 + x <- rztbinom(n, 30, 1/2) + lnl(c(35, 1/2), obs=x, dfun=dztbinom) + + optim(c(35, 1/2), lnl, obs=x, dfun=dztbinom, control=list(fnscale=-1)) + optimHess(c(35, ), lnl, obs=x, dfun=dztbinom) + + mledist(x, "ztbinom", fix.arg = list(size=30)) + fitdist(x, "ztbinom", fix.arg = list(size=30)) + + mledist(x, "ztbinom", lower=0) + fitdist(x, "ztbinom", lower=0) + + dztbinom(5, 30.5, 1/2) + + llsurface(data = x, distr="ztbinom", plot.arg=c("size", "prob"), + min.arg=c(max(x)+1, 0.4), max.arg=c(31, 0.6), back.col = FALSE, + main="log-likelihood for ZT binomial distribution") + + } > > proc.time() user system elapsed 1.53 0.31 1.84