calculate log-normal parameters using the mean and var of the given distribution and obtain the mean and var from the generated random variable

39 Views Asked by At

Following this question, I am trying to estimate the parameters of lognormal dist based on Var and mean, and generate some rand numbers. Then for checking the accuracy, I calculate the mean and var for these random numbers. The point is that the mean matches, but not the var. I think I have misunderstood sth.

Here is my code in R

mean=20
var=30
sdl=log(var+1)
meanl=log(mean/sqrt(1+var))
meanlc = meanl
sdlc =  sdl
nn=rlnorm(10000,mean=meanlc,sdl=sdlc)
mean(nn)
log(var(nn)+1)
sd(nn)
var(nn)
log(var(nn))

and the output

 > mean(nn)
 [1] 952.2693
 > log(var(nn)+1)
 [1] 19.89513
 > sd(nn)
 [1] 20901.25
 > var(nn)
 [1] 436862122
 > log(var(nn))
 [1] 19.89513