[R] Fitting a Weibull/NaNs
Eric Rescorla
ekr at rtfm.com
Mon Oct 20 06:18:09 CEST 2003
Spencer Graves <spencer.graves at pdf.com> writes:
> Bates and Watts (1988) Nonlinear Regression Analysis and Its
> Applications (Wiley) explain that parameter effects curvature
> seems to be vastly greater than the "intrinsic curvature" of the
> nonlinear manifold, onto which a response vector is projected by
> nonlinear least square. This is different from maximum
> likelihood, but I believe that this principle would still likely
> apply. Does this make sense? spencer graves
Some :)
> p.s. I don't understand what you are saying about "0.41 3.70
> 1.00" below. You are giving me a set of three numbers when
> you are trying to estimate two parameters and getting NAs,
> Inf's and NaNs. I don't understand. Are you printing out
> "x" when the log(likelihood) is NA, NaN or Inf? If yes, is
> one component of "x" <= 0? Eric Rescorla wrote:
Doh! Typographical error to R. I had the "hessian=TRUE" clause inside
the c(). Doesn't make any difference for the results, though.
I'm doing the following:
> llfunc <-
+ function (zzz) {
+ tmp <- -sum(dweibull(d$Age.Month,shape=exp(zzz[1]),scale=exp(zzz[2]), log=TRUE))
+ if(is.infinite(tmp) | is.na(tmp)) { print(zzz);}
+ tmp
+
+ }
> mle <- nlm(llfunc,c(shape=.37,scale=4.0), hessian=TRUE)
[1] 0.37 4.00
[1] 0.37 4.00
[1] 0.370001 4.000000
[1] 0.370000 4.000004
[1] 0.3701 4.0000
[1] 0.3700 4.0004
[1] 0.3702 4.0000
[1] 0.3701 4.0004
[1] 0.3700 4.0008
Warning messages:
1: NA/Inf replaced by maximum positive value
2: NA/Inf replaced by maximum positive value
3: NA/Inf replaced by maximum positive value
4: NA/Inf replaced by maximum positive value
5: NA/Inf replaced by maximum positive value
6: NA/Inf replaced by maximum positive value
7: NA/Inf replaced by maximum positive value
8: NA/Inf replaced by maximum positive value
I'm a little vague on how this is supposed to work, but when
I just compute
-sum(dweibull(d$Age.Month,shape=1.5,scale=40,log=TRUE))
I get "Inf".
The problem seems to be that some of the values of d$Age.Month are 0
and since the Weibull always has a value of 0 at 0, the log likelihood
comes out insane. (I'm getting 0 values due to quantization error).
OTOH when I remove the 0 values it works great, but that seems
kind of ad hoc. Is there some standard fix for this?
Thanks much,
-Ekr
--
[Eric Rescorla ekr at rtfm.com]
http://www.rtfm.com/
More information about the R-help
mailing list