An embedded and charset-unspecified text was scrubbed... Name: not available Url: https://stat.ethz.ch/pipermail/r-help/attachments/20040205/d599de1b/attachment.pl
rgamma question
5 messages · Icabalceta, Jorge L., Sundar Dorai-Raj, Peter Dalgaard +2 more
Icabalceta, Jorge L. wrote:
I was trying to generate random numbers with a gamma distribution. In R the function is: rgamma(n, shape, rate = 1, scale = 1/rate). My question is that if X~gamma(alpha, beta) and I want to generate one random number where do I plug alpha and beta in rgamma? and, what is the meaning and use of rate? Thanks for your attention, Jorge
Did you look at the help? From ?rgamma:
<quote>
Details:
If 'scale' is omitted, it assumes the default value of '1'.
The Gamma distribution with parameters 'shape' = a and 'scale' = s
has density
f(x)= 1/(s^a Gamma(a)) x^(a-1) e^-(x/s)
for x > 0, a > 0 and s > 0. The mean and variance are E(X) = a*s
and Var(X) = a*s^2.
</quote>
Then, depending how you define "alpha" and "beta" use the above to
figure out how to use rgamma.
-sundar
"Icabalceta, Jorge L." <Icabalceta_j at wlf.state.la.us> writes:
I was trying to generate random numbers with a gamma distribution. In R the function is: rgamma(n, shape, rate = 1, scale = 1/rate). My question is that if X~gamma(alpha, beta) and I want to generate one random number where do I plug alpha and beta in rgamma? and, what is the meaning and use of rate?
Well, it depends on your definition of alpha and beta.... You need to match up your notation for the gamma density with that given on help(rgamma), which will also tell you what to do with them. The "rate" argument just allows you to specify the scale as its inverse. A large rate corresponds to a narrow distribution. I suspect this is popular notation for interarrival distributions in queuing theory.
O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
On Thu, 5 Feb 2004, Icabalceta, Jorge L. wrote:
I was trying to generate random numbers with a gamma distribution. In R the function is: rgamma(n, shape, rate = 1, scale = 1/rate). My question is that if X~gamma(alpha, beta) and I want to generate one random number where do I plug alpha and beta in rgamma? and, what is the meaning and use of rate?
It depends on what you mean by gamma(alpha,beta). It could be rgamma(1,alpha,beta) or rgamma(1,alpha,1/beta) since both of these parameterisations are used. If you think the mean of gamma(alpha,beta) is alpha*beta, use the second one, if you think it is alpha/beta use the first one. -thomas
Jorge: If I have trouble understanding documentation with
something like this, I make plots, e.g., of dgamma vs. x for different
values for shape and rate or scale.
hope this helps. spencer graves
Peter Dalgaard wrote:
"Icabalceta, Jorge L." <Icabalceta_j at wlf.state.la.us> writes:
I was trying to generate random numbers with a gamma distribution. In R the function is: rgamma(n, shape, rate = 1, scale = 1/rate). My question is that if X~gamma(alpha, beta) and I want to generate one random number where do I plug alpha and beta in rgamma? and, what is the meaning and use of rate?
Well, it depends on your definition of alpha and beta.... You need to match up your notation for the gamma density with that given on help(rgamma), which will also tell you what to do with them. The "rate" argument just allows you to specify the scale as its inverse. A large rate corresponds to a narrow distribution. I suspect this is popular notation for interarrival distributions in queuing theory.