Skip to content
Prev 199824 / 398502 Next

Generate Random Draw from Gamma Distribution Re: Monte Carlo Simulation in R...

If the number of groups can be set "endogenously" my previous email about
the smallest `n' would apply.  You can view this as a "waiting time"
problem.  Here is one approach:

x <- round(pmax(1, pmin(rgamma(500, shape=0.067, rate=0.008), 85)))

csx <- cumsum(x)

ind <- which(csx > 2000)[1]

xg <- c(x[1:(ind-1)], 2000 - csx[ind-1])  # group sizes

sum(xg)

length(xg)  # number of groups

However, note that the elements of `xg' are not gamma variables (due to
min-max constraint), and they are all not independent (due to sum
constraint).

Hope this helps,
Ravi.

----------------------------------------------------------------------------
-------

Ravi Varadhan, Ph.D.

Assistant Professor, The Center on Aging and Health

Division of Geriatric Medicine and Gerontology 

Johns Hopkins University

Ph: (410) 502-2619

Fax: (410) 614-9625

Email: rvaradhan at jhmi.edu

Webpage:
http://www.jhsph.edu/agingandhealth/People/Faculty_personal_pages/Varadhan.h
tml

 

----------------------------------------------------------------------------
--------


-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On
Behalf Of Hongwei Dong
Sent: Tuesday, November 10, 2009 4:44 PM
To: R-help Forum
Subject: Re: [R] Generate Random Draw from Gamma Distribution Re: Monte
Carlo Simulation in R...

By the way, maybe the number of groups can be determined endogenously. It
will be better if I do not have to set the total number of groups
exogenously.

Thanks
Garry
On Tue, Nov 10, 2009 at 1:29 PM, Hongwei Dong <pdxdong at gmail.com> wrote:

            
them
----------------------------------------------------------------------------
http://www.jhsph.edu/agingandhealth/People/Faculty_personal_pages/Varadhan.h
tml<http://www.jhsph.edu/agingandhealth/People/Faculty_personal_pages/Varadh
an.html>
----------------------------------------------------------------------------
______________________________________________
R-help at 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.