# Log-normal density function using rlnorm() in R

I tried to draw a log-normal density function by generating random numbers in R. However, the function is not working how I think it should. I draw two similar distribution using two different sample size.

plot(density(rlnorm(1000000,meanlog = -1.43, sdlog = 0.7)))

plot(density(rlnorm(100000000,meanlog = -1.43, sdlog = 0.7)))


For some reason, I got two very different distributions.

Am I getting something wrong? I thought that these two density function should be nearly similar.

Edit:

I draw the density function also in excel. I think this should be the correct distribution. Is there some error in R-function?

• what is the default number of samples? How does that compare to your domain width? – EngrStudent Jul 5 '18 at 16:57
• The area under the first density is around 1.0 while the area under the second is around 3.0. A fix (and NOT an explanation) is to use a larger number of points to estimate the density: plot(density(rlnorm(100000000,meanlog = -1.43, sdlog = 0.7), n=2^12)). – JimB Jul 5 '18 at 17:37
• I was a bit sloppy in my terminology: By "use a larger number of points to estimate the density" I didn't mean the number of random sample points but rather the number of points used to created the display. The default number of display points for density is 512 but that just isn't enough in this case. I think the problem is because density calls the function fft with too few sample points for this case. – JimB Jul 6 '18 at 15:10

This is an issue with density() and not with rlnorm(): controlling the support of the estimated density produces a complete agreement for different sample sizes:
plot(density(rlnorm(1e7),from=0,to=10),col="steelblue",lty=1)