[R] Fwd: Help please
Rolf Turner
rolf.turner at xtra.co.nz
Wed Jul 20 13:33:04 CEST 2011
On 20/07/11 21:08, Simon Knapp wrote:
> Hi All,
>
> This is not really an R question but a statistical one. If someone could
> either give me the brief explanation or point me to a reference that might
> help, I'd appreciate it.
>
> I want to estimate the mean of a log-normal distribution, given the (log
> scale normal) parameters mu and sigma squared (sigma2). I understood this
> should simply be:
>
> exp(mu + sigma2)
I think you meant exp(mu + sigma2/2); that's what you used below
(and that's what the right answer is.
> ... but I the following code gives me something strange:
>
> R<- 10000000
> mu<- -400
> sigma2<- 200
> tmp<- rlnorm(R, mu, sqrt(sigma2)) # a sample from the desired log-normal
> distribution
> muh<- mean(log(tmp))
> sigma2h<- var(log(tmp))
>
> #by my understanding, all of the the following vectors should then contain
> very similar numbers
> c(mu, muh)
> c(sigma2, sigma2h)
> c(exp(mu + sigma2/2), exp(muh + sigma2h/2), mean(tmp))
>
>
> I get the following (for one sample):
>> c(mu, muh)
> [1] -400.0000 -400.0231
>> c(sigma2, sigma2h)
> [1] 200.0000 199.5895
>> c(exp(mu + sigma2/2), exp(muh + sigma2h/2), mean(tmp))
> [1] 5.148200e-131 4.097249e-131 5.095888e-150
>
> so they do all contain similar numbers, with the exception of the last
> vector, which is out by a factor of 10^19. Is this likely to be because one
> needs **very** large samples to get a reasonable estimate of the mean... or
> am I missing something?
This is in effect an FAQ.
You seem to be missing an understanding of floating point arithmetic.
All of the last three values that you display are ***zero*** to all
practical
intents and purposes.
Experiment with some values where you are not dealing with exp(-300)
if you want to gain some insight into the log normal distribution.
cheers,
Rolf Turner
More information about the R-help
mailing list