Skip to content
Prev 199805 / 398502 Next

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

May be you are interested in the first `n' for which the sum of iid gamma
rvs exceeds 2000, subject to the min-max constraints on each rv. 

If so, the following one-liner will give it to you:

which(cumsum(pmax(1, pmin(rgamma(500, shape=0.067, rate=0.008), 85))) >
2000)[1]

Note that I have used a slightly inefficient code (a somewhat generous N of
500), but this permits economy of code (on-liner!).

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 2:57 PM
To: David Winsemius
Cc: R-help Forum
Subject: Re: [R] Generate Random Draw from Gamma Distribution Re: Monte
Carlo Simulation in R...

Thanks.
I tried the rgamma function too. But I'm still wondering how I can set the
min, max, and sum of the variates created by the random draws. Anyone has a
clue? Thanks.

Garry



On Tue, Nov 10, 2009 at 11:47 AM, David Winsemius
<dwinsemius at comcast.net>wrote:

            
0.008
wondering
help
______________________________________________
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.