[R] finding mean and SD for a log-normal distribution

2012-05-16 Thread Andras Farkas
Dear R Expert
 
allow me to ask a quick qestion: I have a mean value of 6 and a SD of 3 
describing my distribution. I would like to convert this distribution into a 
log normal distribution that would best describe it when resimulated using log 
normal distribution. Currently I am using another software to estimate the 
respective mean and SD on the log scale and the results are: 1.6667 and SD 
0.47071. Then, to best reproduce my original distribution in R, I use the 
following commands:
 
c - rlnorm(5000,1.6667,0.47071)
d - exp(c)
mean(c)
sd(c)
 
and the results for mean and SD are 5.92 and 2.94 (original 6 and 3), 
respectively, which I am reasonably happy with. I would like to grow 
independent of the another software I use, but am unable to figure out how to 
generate the values of 1.6667 and 0.47071 using R. could someone please help me 
with this question?
 
thanks,
 
Andras
[[alternative HTML version deleted]]

__
R-help@r-project.org 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.


Re: [R] finding mean and SD for a log-normal distribution

2012-05-16 Thread Uwe Ligges



On 16.05.2012 12:37, Andras Farkas wrote:

Dear R Expert

allow me to ask a quick qestion: I have a mean value of 6 and a SD of 3 describing my 
distribution. I would like to convert this distribution into a log normal 
distribution that would best describe it when resimulated using log normal distribution. 
Currently I am using another software to estimate the respective mean and SD on the log 
scale and the results are: 1.6667 and SD 0.47071. Then, to best reproduce my original 
distribution in R, I use the following commands:

c- rlnorm(5000,1.6667,0.47071)
d- exp(c)
mean(c)
sd(c)

and the results for mean and SD are 5.92 and 2.94 (original 6 and 3), 
respectively, which I am reasonably happy with. I would like to grow 
independent of the another software I use, but am unable to figure out how to 
generate the values of 1.6667 and 0.47071 using R. could someone please help me 
with this question?


Just make use of a textbook:

meanlog - log(6) - 0.5 * log(1 + 9/(6^2))
sdlog - sqrt(log(1 + 9/(6^2)))

Uwe Ligges





thanks,

Andras
[[alternative HTML version deleted]]




__
R-help@r-project.org 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.


__
R-help@r-project.org 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.


Re: [R] finding mean and SD for a log-normal distribution

2012-05-16 Thread David Winsemius


On May 16, 2012, at 6:37 AM, Andras Farkas wrote:


Dear R Expert

allow me to ask a quick qestion: I have a mean value of 6 and a SD  
of 3 describing my distribution. I would like to convert this  
distribution into a log normal distribution that would best describe  
it when resimulated using log normal distribution. Currently I am  
using another software to estimate the respective mean and SD on the  
log scale and the results are: 1.6667 and SD 0.47071. Then, to best  
reproduce my original distribution in R, I use the following commands:


c - rlnorm(5000,1.6667,0.47071)
d - exp(c)
mean(c)
sd(c)


I get a better match to those values with:
distrib - rlnorm(50,1.682,0.47071)

(Bad practice to use 'c' as an object name.)



and the results for mean and SD are 5.92 and 2.94 (original 6 and  
3), respectively, which I am reasonably happy with. I would like to  
grow independent of the another software I use, but am unable to  
figure out how to generate the values of 1.6667 and 0.47071 using R.  
could someone please help me with this question?


You need to review your resources on statistical distributions. The  
Wikipedia article has the needed transformations for parameters  
between the log and untransformed scales under the section entitled  
Arithmetic moments.


So that was the basis for this test:

# mu for LN
 log(6) - 0.5*log(1+9/6^2)
[1] 1.680188
# sigma for LN
 sqrt( log( 1 +9/6^2))
[1] 0.4723807
 c - rlnorm(50,1.680188,0.4723807)
 d - exp(c)
# Expected value
 mean(c)
[1] 5.99303
# SD
 sd(c)
[1] 2.996532

So my half-assed approximation was in better agreement with theory  
than your other software. On the other hand you haven't really given  
us much background for this estimation process so its not possible to  
offer a solid value judgment. R has package that do distribution  
fitting, MASS has fitdistr and there is a fitdistrplus package   
and others I believe. There's a monograph out about R's facilities but  
at the moment I cannot put my hands on my copy. There is a  
Distributions TaskView:

http://cran.r-project.org/web/views/Distributions.html

--

David Winsemius, MD
West Hartford, CT

__
R-help@r-project.org 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.


Re: [R] finding mean and SD for a log-normal distribution

2012-05-16 Thread peter dalgaard

On May 16, 2012, at 12:37 , Andras Farkas wrote:

 Dear R Expert
  
 allow me to ask a quick qestion: I have a mean value of 6 and a SD of 3 
 describing my distribution. I would like to convert this distribution into 
 a log normal distribution that would best describe it when resimulated using 
 log normal distribution. Currently I am using another software to estimate 
 the respective mean and SD on the log scale and the results are: 1.6667 and 
 SD 0.47071. Then, to best reproduce my original distribution in R, I use the 
 following commands:
  
 c - rlnorm(5000,1.6667,0.47071)
 d - exp(c)
 mean(c)
 sd(c)
  
 and the results for mean and SD are 5.92 and 2.94 (original 6 and 3), 
 respectively, which I am reasonably happy with. I would like to grow 
 independent of the another software I use, but am unable to figure out how to 
 generate the values of 1.6667 and 0.47071 using R. could someone please help 
 me with this question?

Perhaps this was what you were looking for:

 d - log(c)
 mean(d)
[1] 1.675003
 sd(d)
[1] 0.4656469

Taking exp() of a log-normal rarely makes much sense. More commonly, you take 
log() to get a normal distribution.

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd@cbs.dk  Priv: pda...@gmail.com

__
R-help@r-project.org 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.