I'm attempting to fit a truncated log-normal distribution in R. In the below x is list of integers. I believe the function Optim() is likely to be the best way to do this, as below.
log.lklh.lnorm <- function(x, mu, sd, input_min, input_max){-sum(log(dlnorm(x, meanlog = mu, sdlog = sd, log = FALSE)/((plnorm(input_max, meanlog = mu, sdlog = sd, lower.tail = TRUE, log.p = FALSE)) - (plnorm(input_min, meanlog = mu, sdlog = sd, lower.tail = TRUE, log.p = FALSE)))))}
optim(par = c(0,1,1,100000), log.lklh.lnorm)
I used excel solver to solve (i.e. find the maximum value of this sum) for mu and sd (subject to the input max and min). However, i cant seem to replicate this in R. I've tried various versions of the above code, including:
- Set input min and input max to certain values, such as 1 and 100,000 respectively.
- Order of Optim() calls, i.e. input x, par and fn order)
Any help is greatly appreciated, thanks!
Dave