[R] (no subject)

From: Leaf Sun <leaflovesun_at_yahoo.ca>
Date: Fri 21 Jul 2006 - 06:25:05 EST

@yahoo.ca>
Subject: Re: [R] Weibull distribution
Message-ID: <200607201425040019536@yahoo.ca> X-mailer: Foxmail 6, 3, 103, 21 [cn]
Mime-Version: 1.0
Content-Type: multipart/alternative;

        boundary="=====003_Dragon527446281311_====="

This is a multi-part message in MIME format.

--=====003_Dragon527446281311_=====
Content-Type: text/plain;

        charset="gb2312"
Content-Transfer-Encoding: 7bit

Hi William,

Thanks a lot for your response. I checked the package and found that what I want to solve was the opposite, that is, from mean and sd to parameters shape and scale. Could anyone give some hints please? Any suggestion would be appreciated!

Leaf

From: William Asquith, wasquith@austin.rr.com Sent: 2006-07-17, 16:18:31
To: Leaf Sun, leaflovesun@yahoo.ca
Subject: Re: [R] Weibull distribution   

Do not have answer per se, but if you are seeking some comparisons-- try three parameter Weibull as implemented by the lmomco package.

William
On Jul 17, 2006, at 1:18 PM, Leaf Sun 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

--=====003_Dragon527446281311_=====
Content-Type: text/html;

        charset="gb2312"
Content-Transfer-Encoding: 7bit

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<META content="MSHTML 6.00.2900.2912" name=GENERATOR></HEAD>
<BODY>
<DIV>Hi William,</DIV>
<DIV>&nbsp;</DIV>
<DIV>Thanks a lot for your response. I checked the package and found that what I 
want to solve was the opposite, that is, from mean and sd to parameters shape and scale. Could anyone give some hints please? Any suggestion would be appreciated!</DIV>
<DIV><BR>Leaf</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV>----- Original Message -----</DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=2><FONT face=Tahoma><STRONG>From:</STRONG> William 
Asquith,&nbsp;&nbsp;<A
href="mailto:wasquith@austin.rr.com">wasquith@austin.rr.com</A><BR><B>Sent:</B> 2006-07-17,&nbsp; 16:18:31<BR><B>To:</B> Leaf Sun, <A href="mailto:leaflovesun@yahoo.ca">leaflovesun@yahoo.ca</A><BR><B>Subject:</B>&nbsp; Re: [R] Weibull distribution</FONT></FONT></DIV>
<DIV>&nbsp;&nbsp;</DIV>
<DIV>
<TABLE width="100%">

  <TBODY>
  <TR>
    <TD width="100%">
      <BLOCKQUOTE 
      style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
        <DIV>Do &nbsp;not &nbsp;have &nbsp;answer &nbsp;per &nbsp;se, &nbsp;but 
        &nbsp;if &nbsp;you &nbsp;are &nbsp;seeking &nbsp;some 
        &nbsp;comparisons-- &nbsp;</DIV>
        <DIV>try &nbsp;three &nbsp;parameter &nbsp;Weibull &nbsp;as 
        &nbsp;implemented &nbsp;by &nbsp;the &nbsp;lmomco &nbsp;package.</DIV>
        <DIV>&nbsp;</DIV>
        <DIV>William</DIV>
        <DIV>On &nbsp;Jul &nbsp;17, &nbsp;2006, &nbsp;at &nbsp;1:18 &nbsp;PM, 
        &nbsp;Leaf &nbsp;Sun &nbsp;wrote:</DIV>
        <DIV>&nbsp;</DIV>
        <DIV>&gt; &nbsp;Hi &nbsp;all,</DIV>
        <DIV>&gt;</DIV>
        <DIV>&gt; &nbsp;By &nbsp;its &nbsp;definition, &nbsp;the &nbsp;mean 
        &nbsp;and &nbsp;variance &nbsp;of &nbsp;two-par. &nbsp;Weibull &nbsp; 
        &nbsp;</DIV>
        <DIV>&gt; &nbsp;distribution &nbsp;are:</DIV>
        <DIV>&gt;</DIV>
        <DIV>&gt;</DIV>
        <DIV>&gt;</DIV>
        <DIV>&gt;</DIV>
        <DIV>&gt;</DIV>
        <DIV>&gt; &nbsp; &nbsp;(www.wikipedia.org)</DIV>
        <DIV>&gt;</DIV>
        <DIV>&gt;</DIV>
        <DIV>&gt; &nbsp;I &nbsp;was &nbsp;wondering, &nbsp;if &nbsp;given 
        &nbsp;mean &nbsp;and &nbsp;sd. &nbsp;could &nbsp;we &nbsp;parameterize 
        &nbsp;the &nbsp; &nbsp;</DIV>
        <DIV>&gt; &nbsp;distribution? &nbsp;I &nbsp;tried &nbsp;this &nbsp;in 
        &nbsp;R.</DIV>
        <DIV>&gt;</DIV>
        <DIV>&gt; &nbsp;gamma.fun &nbsp; &lt;- 
        &nbsp;function(mu,sd,start=100)</DIV>
        <DIV>&gt; &nbsp;{</DIV>
        <DIV>&gt; &nbsp;f.fn &nbsp; &lt;- &nbsp;function(alpha) 
        &nbsp;sd^2-mu^2/(gamma(1+1/alpha))^2*(gamma(1+2/ &nbsp;</DIV>
        <DIV>&gt; &nbsp;alpha)-(gamma(1+1/alpha))^2)</DIV>
        <DIV>&gt; &nbsp;alpha &nbsp; &lt;- &nbsp;optim(start, 
        &nbsp;f.fn,method='BFGS')</DIV>
        <DIV>&gt; &nbsp;beta &nbsp; &lt;- &nbsp;mu/gamma(1+1/alpha$par)</DIV>
        <DIV>&gt; &nbsp;return(list=c(a=alpha$par,b=beta));</DIV>
        <DIV>&gt; &nbsp;}</DIV>
        <DIV>&gt;</DIV>
        <DIV>&gt;</DIV>
        <DIV>&gt; &nbsp;But &nbsp;the &nbsp;problems &nbsp;come &nbsp;up 
        &nbsp;here:</DIV>
        <DIV>&gt;</DIV>
        <DIV>&gt; &nbsp;1) &nbsp; &nbsp;the &nbsp;return &nbsp;values &nbsp;of 
        &nbsp;a &nbsp;and &nbsp;b &nbsp;are &nbsp;only &nbsp;related &nbsp;to 
        &nbsp;the &nbsp;input &nbsp; &nbsp;</DIV>
        <DIV>&gt; &nbsp;mean, &nbsp;and &nbsp;nothing &nbsp;to &nbsp;do 
        &nbsp;with &nbsp;the &nbsp;sd. &nbsp;For &nbsp;instance, &nbsp;when 
        &nbsp;I &nbsp;apply &nbsp;a &nbsp; &nbsp;</DIV>
        <DIV>&gt; &nbsp;mean &nbsp;mu &nbsp;= &nbsp;3 &nbsp;whatever &nbsp;I 
        &nbsp;use &nbsp;sd=2, &nbsp;sd=4, &nbsp;the &nbsp;function 
        &nbsp;returned &nbsp;the &nbsp; &nbsp;</DIV>
        <DIV>&gt; &nbsp;same &nbsp;scale &nbsp;and &nbsp;shape 
        &nbsp;values.</DIV>
        <DIV>&gt;</DIV>
        <DIV>&gt; &gt; &nbsp;gamma.fun(3,4,10);</DIV>
        <DIV>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a 
        &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;b</DIV>
        <DIV>&gt; &nbsp;5.112554 &nbsp;3.263178</DIV>
        <DIV>&gt;</DIV>
        <DIV>&gt; &gt; &nbsp;gamma.fun(3,2,10);</DIV>
        <DIV>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a 
        &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;b</DIV>
        <DIV>&gt; &nbsp;5.112554 &nbsp;3.263178</DIV>
        <DIV>&gt;</DIV>
        <DIV>&gt; &nbsp;2) &nbsp;the &nbsp;start &nbsp;value &nbsp;determines 
        &nbsp;the &nbsp;results: &nbsp;if &nbsp;I &nbsp;apply &nbsp;mean &nbsp;= 
        &nbsp;3, &nbsp;and &nbsp; &nbsp;</DIV>
        <DIV>&gt; &nbsp;sd=2, &nbsp;with &nbsp;a &nbsp;start &nbsp;of &nbsp;10, 
        &nbsp;it &nbsp;would &nbsp;return &nbsp;alpha &nbsp;close &nbsp;to 
        &nbsp;10, &nbsp;if &nbsp;I &nbsp; &nbsp;</DIV>
        <DIV>&gt; &nbsp;use &nbsp;a &nbsp;start &nbsp;= &nbsp;100, &nbsp;it 
        &nbsp;would &nbsp;return &nbsp;alpha &nbsp;close &nbsp;to 
        &nbsp;100.</DIV>
        <DIV>&gt;</DIV>
        <DIV>&gt; &gt; &nbsp;gamma.fun(3,2,10);</DIV>
        <DIV>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a 
        &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;b</DIV>
        <DIV>&gt; &nbsp;5.112554 &nbsp;3.263178</DIV>
        <DIV>&gt;</DIV>
        <DIV>&gt; &gt; &nbsp;gamma.fun(3,2,100);</DIV>
        <DIV>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
        &nbsp;a &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
        &nbsp;b</DIV>
        <DIV>&gt; &nbsp;99.999971 &nbsp; &nbsp;3.017120</DIV>
        <DIV>&gt;</DIV>
        <DIV>&gt; &nbsp;Since &nbsp;I &nbsp;am &nbsp;not &nbsp;a 
        &nbsp;statistician, &nbsp;I &nbsp;guess &nbsp;there &nbsp;must &nbsp;be 
        &nbsp;some &nbsp; &nbsp;</DIV>
        <DIV>&gt; &nbsp;theoretical &nbsp;reasons &nbsp;wrong &nbsp;with 
        &nbsp;this &nbsp;question. &nbsp;So &nbsp;I &nbsp;am &nbsp;looking 
        &nbsp; &nbsp;</DIV>
        <DIV>&gt; &nbsp;forward &nbsp;to &nbsp;some &nbsp;correction &nbsp;and 
        &nbsp;advice &nbsp;to &nbsp;solve &nbsp;these. &nbsp;Thanks &nbsp;a 
        &nbsp;lot &nbsp; &nbsp;</DIV>
        <DIV>&gt; &nbsp;in &nbsp;advance!</DIV>
        <DIV>&gt;</DIV>
        <DIV>&gt; &nbsp;Leaf</DIV>
        <DIV>&gt;</DIV>
        <DIV>&gt; &nbsp; [[alternative &nbsp;HTML &nbsp;version 
        &nbsp;deleted]]</DIV>
        <DIV>&gt;</DIV>
        <DIV>&gt; &nbsp;______________________________________________</DIV>
        <DIV>&gt; &nbsp;R-help@stat.math.ethz.ch &nbsp;mailing &nbsp;list</DIV>
        <DIV>&gt; &nbsp;https://stat.ethz.ch/mailman/listinfo/r-help</DIV>
        <DIV>&gt; &nbsp;PLEASE &nbsp;do &nbsp;read &nbsp;the &nbsp;posting 
        &nbsp;guide! &nbsp;<A 
        href="http://www.R-project.org/posting-">http://www.R-project.org/posting-</A> 
        &nbsp;</DIV>
        <DIV>&gt; &nbsp;guide.html</DIV>
        <DIV>&nbsp;</DIV></BLOCKQUOTE></TD></TR></TBODY></TABLE></DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV></BODY></HTML>

--=====003_Dragon527446281311_=====--



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 Jul 21 06:32:47 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 21 Jul 2006 - 08:18:33 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.