# **Only for Poisson, Censored data, fitdistrplus*** the function mle failed to estimat

#### mohsenhs82

##### New Member
Hello All,

I am getting the following error and it only happens for interval censoring, It does not happen for left and right censoring, and it also does not happen for exp, norm, lnorm, weibull,... I have to say I do not have any idea,
> max(z)
[1] 39011
> min(z)
[1] 1
>
I am using library(fitdistrplus). I also passed the start param for optim, but no success as suggested before in some forums earlier.
I have provided all scenarios (the first two ones work, the 3rd is my problem, and the 4th also works).
And No missing value. I am getting some NAN form gamma also, but I do not know the reason.

I appreciate any help.

Kind regards,
Mohsen

------works
z=rep(df$timenum,time=df$count)
y<-z
ycens <- data.frame(left=y,right=y)
max=27219
ct=max
for(i in max:28666 )
{
ycens$right[ct]=NA ct=ct+1 } ct=1; for(i in 1:28666 ) { if( ycens$left<3)
{
ycens$left[ct]=NA } if( i>max) { ycens$left[ct]=500
}
ct=ct+1
}
fitlnc<-fitdistcens(ycens,"pois")
> fitlnc
Fitting of the distribution ' pois ' on censored data by maximum likelihood
Parameters:
estimate
lambda 93.34093

-----------------Works method 2--------------
z=rep(df$timenum,time=df$count)
> y<-z
>
> ycens <- data.frame(left=y,right=y)
> max=27219
> ct=max
> for(i in max:28666 )
+ {
+ ycens$right[ct]=NA + + ct=ct+1 + + } > ct=1; > for(i in 1:28666 ) + { + + if( ycens$left<3)
+ {
+ ycens$left[ct]=NA + + } + ct=ct+1 + } > fitlnc<-fitdistcens(ycens,"pois") > fitlnc Fitting of the distribution ' pois ' on censored data by maximum likelihood Parameters: estimate lambda 142.0141 ==================PROBLEEEEEEEEEEMMMM====================== z=rep(df$timenum,time=df$count) y<-z ycens <- data.frame(left=y,right=y) max=27219 ct=max for(i in max:28666 ) { ycens$right[ct]=y[ct]
ycens$left[ct]=500 ct=ct+1 } ct=1; for(i in 1:28666 ) { if( ycens$left<4)
{
ycens$left[ct]=1 } ct=ct+1 } > fitlnc<-fitdistcens(ycens,"pois") [1] "Error in optim(par = vstart, fn = fnobjcens, fix.arg = fix.arg, rcens = rcens, : \n initial value in 'vmmin' is not finite\n" attr(,"class") [1] "try-error" attr(,"condition") <simpleError in optim(par = vstart, fn = fnobjcens, fix.arg = fix.arg, rcens = rcens, lcens = lcens, icens = icens, ncens = ncens, ddistnam = ddistname, pdistnam = pdistname, hessian = TRUE, method = meth, lower = lower, upper = upper, ...): initial value in 'vmmin' is not finite> Error in fitdistcens(ycens, "pois") : the function mle failed to estimate the parameters, with the error code 100 ====================Works========================= z=rep(df$timenum,time=df$count) y<-z ycens <- data.frame(left=y,right=y) max=27219 ct=max for(i in max:28666 ) { ycens$right[ct]=y[ct]
ycens$left[ct]=500 ct=ct+1 } ct=1; for(i in 1:28666 ) { if( ycens$left<4)
{
ycens$left[ct]=1 } ct=ct+1 } fitlnc<-fitdistcens(ycens,"lnorm") fitlnc<-fitdistcens(ycens,"exp") > fitlnc<-fitdistcens(ycens,"gamma") There were 12 warnings (use warnings() to see them) > warnings() Warning messages: 1: In dgamma(x = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ... : NaNs produced 2: In pgamma(q = c(2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, ... : NaNs produced 3: In pgamma(q = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ... : NaNs produced 4: In dgamma(x = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ... : NaNs produced 5: In pgamma(q = c(2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, ... : NaNs produced 6: In pgamma(q = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ... : NaNs produced 7: In dgamma(x = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ... : NaNs produced 8: In pgamma(q = c(2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, ... : NaNs produced 9: In pgamma(q = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ... : NaNs produced 10: In dgamma(x = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ... : NaNs produced 11: In pgamma(q = c(2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, ... : NaNs produced 12: In pgamma(q = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ... : NaNs produced #### GretaGarbo ##### Human Re: **Only for Poisson, Censored data, fitdistrplus*** the function mle failed to est A reproducible example would make it more clear. (Also, please use code tags. Highlight and click #) #### mohsenhs82 ##### New Member Re: **Only for Poisson, Censored data, fitdistrplus*** the function mle failed to est Hi GretaGarbo, Thanks for your reply. Please find the data in my Dropbox. I also did the changes that you mentioned. Many thanks Mohsen ------works Code: df= read.csv ("E:/mydata/Motorway-Urban/hour/PathAll_TWOMONTH _BothDirection715_2.csv") z=rep(df$timenum,time=df$count) y<-z ycens <- data.frame(left=y,right=y) max=27219 ct=max for(i in max:28666 ) { ycens$right[ct]=NA
ct=ct+1
}
ct=1;
for(i in 1:28666 )
{
if( ycens$left[i]<3) { ycens$left[ct]=NA
}
if( i>max)
{
ycens$left[ct]=500 } ct=ct+1 } fitlnc<-fitdistcens(ycens,"pois") fitlnc Fitting of the distribution ' pois ' on censored data by maximum likelihood Parameters: estimate lambda 93.34093 -----------------Works method 2-------------- Code: z=rep(df$timenum,time=df$count) y<-z ycens <- data.frame(left=y,right=y) max=27219 ct=max for(i in max:28666 ) { ycens$right[ct]=NA

ct=ct+1

}
ct=1;
for(i in 1:28666 )
{

if( ycens$left[i]<3) { ycens$left[ct]=NA

}
ct=ct+1
}
fitlnc<-fitdistcens(ycens,"pois")
fitlnc
Fitting of the distribution ' pois ' on censored data by maximum likelihood
Parameters:
estimate
lambda 142.0141

==================PROBLEEEEEEEEEEMMMM======================
Code:
z=rep(df$timenum,time=df$count)
y<-z

ycens <- data.frame(left=y,right=y)
max=27219
ct=max
for(i in max:28666 )
{
ycens$right[ct]=y[ct] ycens$left[ct]=500
ct=ct+1

}
ct=1;
for(i in 1:28666 )
{

if( ycens$left[i]<4) { ycens$left[ct]=1

} ct=ct+1
}
fitlnc<-fitdistcens(ycens,"pois")
[1] "Error in optim(par = vstart, fn = fnobjcens, fix.arg = fix.arg, rcens = rcens, : \n initial value in 'vmmin' is not finite\n"
attr(,"class")
[1] "try-error"
attr(,"condition")
<simpleError in optim(par = vstart, fn = fnobjcens, fix.arg = fix.arg, rcens = rcens, lcens = lcens, icens = icens, ncens = ncens, ddistnam = ddistname, pdistnam = pdistname, hessian = TRUE, method = meth, lower = lower, upper = upper, ...): initial value in 'vmmin' is not finite>
Error in fitdistcens(ycens, "pois") :
the function mle failed to estimate the parameters,
with the error code 100
====================Works=========================
Code:
z=rep(df$timenum,time=df$count)
y<-z

ycens <- data.frame(left=y,right=y)
max=27219
ct=max
for(i in max:28666 )
{
ycens$right[ct]=y[ct] ycens$left[ct]=500
ct=ct+1

}
ct=1;
for(i in 1:28666 )
{

if( ycens$left[i]<4) { ycens$left[ct]=1

}
ct=ct+1
}

fitlnc<-fitdistcens(ycens,"lnorm")
fitlnc<-fitdistcens(ycens,"exp")
fitlnc<-fitdistcens(ycens,"gamma")
There were 12 warnings (use warnings() to see them)
warnings()
Warning messages:
1: In dgamma(x = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ... : NaNs produced
2: In pgamma(q = c(2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, ... : NaNs produced
3: In pgamma(q = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ... : NaNs produced
4: In dgamma(x = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ... : NaNs produced
5: In pgamma(q = c(2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, ... : NaNs produced
6: In pgamma(q = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ... : NaNs produced
7: In dgamma(x = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ... : NaNs produced
8: In pgamma(q = c(2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, ... : NaNs produced
9: In pgamma(q = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ... : NaNs produced
10: In dgamma(x = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ... : NaNs produced
11: In pgamma(q = c(2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, ... : NaNs produced
12: In pgamma(q = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ... : NaNs produced