Skip to content

question about R

3 messages · khazaei at ceremade.dauphine.fr, Patrizio Frederic, Steve Lianoglou

#
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
#
# 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,
On Tue, May 11, 2010 at 12:36 PM, <khazaei at ceremade.dauphine.fr> wrote:
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