lundi 26 novembre 2018

rlnorm function in r-programming producing NA's

I am trying to generate a random values using log distribution. The reason for using log-distribution is keep the values positive.

   cv=0.2 # 20% cv for the values K used in the simulation 

calc_sd <- function(mean,cv){
  sd=mean*cv
  print(sd)
}
calc_sd((6.19*10^-3),(0.2))
mu<-6.19*10^-3
sd<- 0.001238
nsample=50000
kdist <- data.frame(id=1:nsample)
kdist$KE <- (rlnorm(nsample, meanlog=mu,sdlog=sd))

This is the warning message I keep getting

Warning messages: 1: In rlnorm(50000, mean = (6.19 * 10^-3), sd =sd) : NAs produced

My question is how do I adderss this issue. I ave tried using one of the previous suggestions which was mentioned here and it does not work.

https://msalganik.wordpress.com/2017/01/21/making-sense-of-the-rlnorm-function-in-r/

http://r.789695.n4.nabble.com/Is-my-understanding-of-rlnorm-correct-td853068.html

My second question is : is there a way to directly use CV instead of sd for the generating this ?

Thanks in advance.




Aucun commentaire:

Enregistrer un commentaire