[R] Fitting Truncated Distribution

Lorenzo Isella lorenzo.isella at gmail.com
Fri Aug 7 12:57:52 CEST 2009


Dear All,
I know that this topic has been already discussed on this list (see e.g. 
http://markmail.org/message/bq2bdxwblwl4rpgf?q=r+fit+truncated+lognormal&page=1&refer=2ufc4fb2eftfwwml#query:r%20fit%20truncated%20lognormal+page:1+mid:7wxgkdxhixotorr5+state:results
for the case of weibull distribution), but I am experiencing some problems.
I deal with truncated distributions (that this to say data below/above a 
certain threshold are removed from the observations and I do not know 
any longer that there are any observations ruled out by a threshold).

(1) Consider the following snippet (along the lines of the suggestion in 
the link above)

rm(list=ls())
library(MASS)
set.seed(1234)

lt_lognormal <- function(x, meanlog, sdlog ){
  dlnorm(x, meanlog , sdlog )/plnorm(0.5, meanlog , sdlog  )
}

my_seq <- rlnorm(10000)

my_fit <- fitdistr(my_seq,"lognormal")

cut_low <- my_seq[which(my_seq>0.5)]

my_fit_low <- fitdistr(cut_low,lt_lognormal,list(meanlog=0.2,sdlog=0.7), 
lower=0.5 )

However, when I run it I get the following error

Error in optim(x = c(1.31973273433717, 2.95778647676973, 
1.53591253356589,  :
  L-BFGS-B needs finite values of 'fn'

Does anybody know what is going on? Am I making a mistake?

(2) How about the case of simultaneously left- and right-truncated data?
What is the easiest way to deal with them?

Many thanks

Lorenzo




More information about the R-help mailing list