On 11-Oct-2012 17:22:44 Andras Farkas wrote: > Dear All, > I have a questions I would like to ask about and wonder if you > have any thoughts to make it work in R. > > 1. I work in the field of medicine where physiologic variables > are often simulated, and they can not have negative values. > Most often the assumption is made to simulate this parameters > with a normal distribution but in the "log-domain" to avoid from > negative values to be generated. Since the expected mean and SD > is usually known from the normal domain, using the methods described > in the wikipedia article "Arithmetric moments" I generate μand Ï > and simulate with rlnorm(). At times though the following issue > comes up: I have the mean and SD for the parameters available > from the normal domain, and the covariance matrix from the normal > domain. Then I would like to simulate the values, but to avoid > from negative values being generated I have to fall back on rlnorm > in {compositions}. My issue is though that my covariance matrix is > representing the covariance of the parameters in the normal domain, > as opposed to in the lognormal domain. Any thoughts on how to work > around this? > > apreciate the help, > Andras
If I understand your question correctly, if Y is the variable being simulated then you know the mean (M, say) and the variance (V, say) of log(Y). So you can simulate X from a normal distribution with mean M and variance V = S^2 (S = SD of X), and then Y = exp(X): Y <- exp(rnorm(n,M,S)) where n is the number of sampled values you want. When Y is multivariate, with M the vector of means and V the covariance matrix of log(Y), then use a similar approach with the function mvrnorm() from the MASS package: library(MASS) Y <- mvrnorm(n,M,V) Does this help? Ted. ------------------------------------------------- E-Mail: (Ted Harding) <ted.hard...@wlandres.net> Date: 11-Oct-2012 Time: 18:51:47 This message was sent by XFMail ______________________________________________ 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.