Hi, At each iteration in my program,I need to generate tree vectors,X1,X2,X3, from exponential distribution with parameters a1,a2,a3. Can you help me please how can I do it such that it take a little time? thank you khazaei
question about R
3 messages · khazaei at ceremade.dauphine.fr, Patrizio Frederic, Steve Lianoglou
# density function
desp <- function(x,lambda) {
return(lambda * exp(-lambda*x)*(x>=0))
}
# cum. probability function
pesp <- function(q,lambda) {
return((1-exp(-lambda*q)))
}
# quantile function
qesp <- function(p,lambda) {
return(-lambda^{-1}*log(1-p))
}
# random sample
resp <- function(n,lambda) {
return(qesp(runif(n),lambda))
}
resp(100,lambda=2) # generates 100 samples from the exponential
distribution with par 2
On Tue, May 11, 2010 at 6:36 PM, <khazaei at ceremade.dauphine.fr> wrote:
Hi, At each iteration in my program,I need to generate ?tree vectors,X1,X2,X3, from exponential distribution with parameters a1,a2,a3. Can you help me please how can I do it such that it take a little time? thank you khazaei
______________________________________________ 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.
+------------------------------------------------- | Patrizio Frederic, PhD | Assistant Professor, | Department of Economics, | University of Modena and Reggio Emilia, | Via Berengario 51, | 41100 Modena, Italy | | tel: +39 059 205 6727 | fax: +39 059 205 6947 | mail: patrizio.frederic at unimore.it +-------------------------------------------------
Hi,
On Tue, May 11, 2010 at 12:36 PM, <khazaei at ceremade.dauphine.fr> wrote:
Hi, At each iteration in my program,I need to generate ?tree vectors,X1,X2,X3, from exponential distribution with parameters a1,a2,a3. Can you help me please how can I do it such that it take a little time?
So, at each iteration you're sampling from three different exponential distributions, each with rate parameters a1, a2, a3 respectively? Say you have 100 iterations, you can create vectors of length 100 having samples from each distro like so: R> dist1 <- rexp(100, rate=a1) R> dist2 <- rexp(100, rate=a2) R> dist3 <- rexp(100, rate=a3) ... and use them as you would expect where you need them. -steve
Steve Lianoglou Graduate Student: Computational Systems Biology | Memorial Sloan-Kettering Cancer Center | Weill Medical College of Cornell University Contact Info: http://cbio.mskcc.org/~lianos/contact