Hello I would like to simulate datasets in the following way: x <- rpois(999, 2000) y <- sum(exp(rgamma(x, scale=2, shape=0.5))) The problem is, that by calling "y" I just get 1 value back and not 999 values. Can anyone help me? Thanks! Brigitte [[alternative HTML version deleted]]
Hi r-help-bounces at stat.math.ethz.ch napsal dne 01.05.2007 09:03:46:> > Hello > > I would like to simulate datasets in the following way: > > x <- rpois(999, 2000) > y <- sum(exp(rgamma(x, scale=2, shape=0.5)))You computed sum of your 999 values. Regardless of how many values are summed the result is always only one number. Did not you want cumsum? Regards Petr> > The problem is, that by calling "y" I just get 1 value back and not 999 > values. Can anyone help me? Thanks! > > Brigitte > > > > > > > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code.
maybe you're looking for something like this:
x <- rpois(999, 2000)
y <- numeric(length(x))
for (i in seq_along(x))
y[i] <- sum(exp(rgamma(x[i], scale = 2, shape = 0.5)))
I hope it helps.
Best,
Dimitris
----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven
Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
http://www.student.kuleuven.be/~m0390867/dimitris.htm
Quoting Th?r Brigitte <Brigitte.Thuer at swica.ch>:
>
> Hello
>
> I would like to simulate datasets in the following way:
>
> x <- rpois(999, 2000)
> y <- sum(exp(rgamma(x, scale=2, shape=0.5)))
>
> The problem is, that by calling "y" I just get 1 value back and
not
> 999 values. Can anyone help me? Thanks!
>
> Brigitte
>
>
>
>
>
>
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at stat.math.ethz.ch 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.
>
>
Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm
Thats exactly what I am looking for! Thanks for your help! -----Urspr?ngliche Nachricht----- Von: Peter Dalgaard [mailto:p.dalgaard at biostat.ku.dk] Gesendet: Dienstag, 1. Mai 2007 11:46 An: Dimitris Rizopoulos Cc: Th?r Brigitte; r-help at stat.math.ethz.ch Betreff: Re: [R] simulation Dimitris Rizopoulos wrote:> maybe you're looking for something like this: > > x <- rpois(999, 2000) > y <- numeric(length(x)) > for (i in seq_along(x)) > y[i] <- sum(exp(rgamma(x[i], scale = 2, shape = 0.5))) > >Or use sapply, sapply(x, function(x) sum(exp(rgamma(x[i], scale = 2, shape = 0.5)) ) or even replicate(999, sum(exp(rgamma(rpois(1,2000), scale = 2, shape = 0.5)) ) *** eSafe at SWICA scanned this email for malicious content and found it to be clean ***