In fact, it looks as though dlnorm3
(which is built into the FAdist
package) already returns a zero probability when x<=thres
, so plugging dlnorm3
straight into fitdistr
appears to work fine:
set.seed(12345)
library(FAdist)
library(MASS)
X <- rlnorm3(n=100, shape = 2, scale = 1.5, thres = 1)
fitdistr(X,dlnorm3,start=list(shape = 2, scale = 1.5, thres = 1))
Results:
shape scale thres
2.31116615 1.94366899 1.02798643
(0.18585476) (0.23426764) (0.01480906)
This does fail if we use the rllog3
function to generate values (we get much more extreme values):
Y <- rllog3(n=100, shape = 2, scale = 1.5, thres = 1)
fitdistr(Y,dlnorm3,start=list(shape = 2, scale = 1.5, thres = 1),
method="Nelder-Mead")
## Error in stats::optim(x = c(10.1733112422871,
## 310.508398424974, 1.08946140904075, :
## non-finite finite-difference value [3]
Using debug(optim)
, it appears that if we switch to Nelder-Mead we can postpone the problem until the Hessian is computed.
If we use bbmle::mle2
instead we can get at least get the coefficients (with a warning that the Hessian can't be inverted ...)
library(bbmle)
mle2(Y~dlnorm3(m,s,t),
data=data.frame(Y),
start=list(m= 2, s = 1.5, t = 1),
method="Nelder-Mead")
## Call:
## mle2(minuslogl = Y ~ dlnorm3(m, s, t), start = list(m = 2, s = 1.5,
## t = 1), method = "Nelder-Mead", data = data.frame(Y))
## Coefficients:
## m s t
## 4.227529 1.606202 1.001115
## Log-likelihood: -440.27
## Warning message:
## In mle2(Y ~ dlnorm3(m, s, t), data = data.frame(Y), start = list(m = 2, :
## couldn't invert Hessian