Search code examples
rdistributionsimulategamma

simulate Y if Y = log(X) and X ~ Gamma in R


This question is very closely related to posts here and also here.

Let's say that random variable X = Gamma(k, theta), and I am interested in simulating Y, where Y = log(X).

Could you suggest R-package which allows to do it (or suggest an R-code)? Thank you very much in advance!


Solution

  • If you need to extract Y samples, just try:

    #set the number of samples
    n<-10000
    Y<-log(rgamma(n,k,theta))
    

    Then, for instance, you can hist(Y) to see the distribution.