[R] Fitting a Weibull/NaNs

Spencer Graves spencer.graves at pdf.com
Mon Oct 20 02:11:48 CEST 2003


      I have not used "nlm", but that happens routinely with function 
minimizers trying to test negative values for one or more component of 
x.  My standard approach to something like this is to parameterize 
"llfunc" in terms of log(shape) and log(scale), as follows: 

llfunc <- function (x) { -sum(dweibull(AM,shape=exp(x[1]),scale=exp(x[2]), log=TRUE))}

      Have you tried this?  If no, I suspect the warnings will disappear 
when you try this.  If not, I suggest you rewrite "llfunc" to store 
"nlglk <- (-sum(...))" and then print out x whenever nlglk is NA or Inf 
or Nan. 

      hope this helps.  spencer graves

Eric Rescorla wrote:

>I'm trying to fit a Weibull distribution to some data via maximum
>likelihood estimation. I'm following the procedure described by Doug
>Bates in his "Using Open Source Software to Teach Mathematical
>Statistics" but I keep getting warnings about NaNs being converted to
>maximum positive value:
>
>  
>
>>llfunc <- function (x) { -sum(dweibull(AM,shape=x[1],scale=x[2], log=TRUE))}
>>mle <- nlm(llfunc,c(shape=1.5,scale=40), hessian=TRUE)
>>    
>>
>Warning messages: 
>1: NaNs produced in: dweibull(x, shape, scale, log) 
>2: NA/Inf replaced by maximum positive value 
>3: NaNs produced in: dweibull(x, shape, scale, log) 
>4: NA/Inf replaced by maximum positive value 
>  
>
>
>Can someone offer some advice here?
>
>Thanks,
>-Ekr
>
>--
>[Eric Rescorla                                   ekr at rtfm.com]
>                      http://www.rtfm.com/
>
>______________________________________________
>R-help at stat.math.ethz.ch mailing list
>https://www.stat.math.ethz.ch/mailman/listinfo/r-help
>  
>




More information about the R-help mailing list