From: Valentin Dimitrov <vsdimitrov_at_yahoo.com>

Date: Sat 22 Jul 2006 - 01:03:07 EST

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 Sat Jul 22 01:16:48 2006

Date: Sat 22 Jul 2006 - 01:03:07 EST

I modified your code as follows:

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. BFGS seeks to make the gradient (or here the first derivative) zero and in your case f(x) converges to a constant for big x, which means f'(x) is approximately 0 for big x, which is why BFGS stops almost immediately after the start value. The default method of optim() ( Nelder and Mead ) is more appropriate, since it does not need the first derivative and works only with function values.

Best regards,

Valentin

- Leaf Sun <leaflovesun@yahoo.ca> wrote:

> Hi all,

*>
**> By its definition, the mean and variance of two-par.
**> Weibull distribution are:
**>
**>
**>
**>
**>
**> (www.wikipedia.org)
**>
**>
**> I was wondering, if given mean and sd. could we
**> parameterize the distribution? I tried this in R.
**>
**> gamma.fun <- function(mu,sd,start=100)
**> {
**> f.fn <- function(alpha)
*

>

sd^2-mu^2/(gamma(1+1/alpha))^2*(gamma(1+2/alpha)-(gamma(1+1/alpha))^2)

> alpha <- optim(start, f.fn,method='BFGS')

*> beta <- mu/gamma(1+1/alpha$par)
**> return(list=c(a=alpha$par,b=beta));
**> }
**>
**>
**> But the problems come up here:
**>
**> 1) the return values of a and b are only related to
**> the input mean, and nothing to do with the sd. For
**> instance, when I apply a mean mu = 3 whatever I use
**> sd=2, sd=4, the function returned the same scale and
**> shape values.
**>
**> > gamma.fun(3,4,10);
**> a b
**> 5.112554 3.263178
**>
**> > gamma.fun(3,2,10);
**> a b
**> 5.112554 3.263178
**>
**> 2) the start value determines the results: if I
**> apply mean = 3, and sd=2, with a start of 10, it
**> would return alpha close to 10, if I use a start =
**> 100, it would return alpha close to 100.
**>
**> > gamma.fun(3,2,10);
**> a b
**> 5.112554 3.263178
**>
**> > gamma.fun(3,2,100);
**> a b
**> 99.999971 3.017120
**>
**> Since I am not a statistician, I guess there must be
**> some theoretical reasons wrong with this question.
**> So I am looking forward to some correction and
**> advice to solve these. Thanks a lot in advance!
**>
**> Leaf
**>
**> [[alternative HTML version deleted]]
**>
**> ______________________________________________
**> 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
*

>

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 Sat Jul 22 01:16:48 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 Sat 22 Jul 2006 - 02:16:00 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.
*