Re: [R] Weibull distribution

From: Göran Broström <goran.brostrom_at_gmail.com>
Date: Fri 04 Aug 2006 - 07:04:43 EST

On 7/21/06, Thomas Lumley <tlumley@u.washington.edu> wrote:
> On Fri, 21 Jul 2006, Valentin Dimitrov wrote:
>
> > Dear Leaf,
> >
> > I modified your code as follows:
> >
> > gamma.fun <- function(mu,sd,start=100)
> > {
> > f.fn <- function(alpha)
> > {abs(sd^2-mu^2/(gamma(1+1/alpha))^2*(gamma(1+2/alpha)-(gamma(1+1/alpha))^2))}
> > alpha <- optim(start, f.fn)
> > beta <- mu/gamma(1+1/alpha$par)
> > return(list=c(a=alpha$par,b=beta));
> > }
> >
> > Now it works properly.
> >
> > First, I added an abs(). You tried to solve an
> > equation by means of the R-function optim(), which
> > finds a minimum. That's why you can find the solution
> > of f(x)=a through minimization of abs(f(x)-a).
> > Second, I deleted the optim-method BFGS from the
> > optim() function, because it is not appropriate in
> > this case.
>
> optim() is not appropriate at all in this case -- its help page says to
> use optimize() for one-dimensional problems.

Just to clarify: The help page says:

'optim' will work with one-dimensional 'par's, but the default method does not work well (and will warn). Use 'optimize' instead.

In other words, if you for instance use the 'BFGS' method, optim is perfectly OK for one-dimensional problems.
>
> In fact, in one dimension there isn't any need to resort to optimization
> when you really want root-finding, and uniroot() is more appropriate than
> optimize().

One reason to use optim instead of uniroot or optimize is that you need not specify a finite interval that covers the solution.

Göran



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Fri Aug 04 07:32:07 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Fri 04 Aug 2006 - 08:17:46 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.