4
$\begingroup$

I want to simulate a vector x in R with 1000 entries. The j'th entry comes from a exponential distribution with density

$$ f_{j}(x)=j \beta e^{-j \beta x}, x>0 $$

Let us just say that $\beta=2$.

So the first entry in x comes from an exponential distribution with density $$f_{1}(x)=1 \beta e^{-1 \beta x}, x>0$$

The second entry in x comes from an exponential distribution with density $$f_{2}(x)=2 \beta e^{-2 \beta x}, x>0$$

etc.

$\endgroup$

2 Answers 2

5
$\begingroup$

R will happily vectorize the rate parameter:

beta <- 2
rexp(1000,rate=(1:1000)*beta)
$\endgroup$
1
  • $\begingroup$ Thanks! I'm new to R, so this is a big deal to me. $\endgroup$
    – Xenusi
    Commented May 22, 2021 at 15:28
6
$\begingroup$

General method (shown in R) that does not rely on how R's rexp works.

set.seed(2021)
n = 1:1000
x = -(1:1000)*log(runif(1000))

plot(n,x)

enter image description here

$\endgroup$
3
  • $\begingroup$ Interesting. What theorem is this based on? $\endgroup$
    – Xenusi
    Commented May 22, 2021 at 15:44
  • 1
    $\begingroup$ The CDF of $\mathsf{Exp}(\mathrm{rate}=\beta)$ is $F_X(x) = 1 - e^{-x/\beta},$ for $x > 0.$ Then find the inverse CDF (quantile function). if it exists in closed form. A general method of generating values of $X$ is $F_X^{-1}(U),$ where $U\sim\mathsf{Unif}(0,1).$ See Wikipedia. In this particular application, note that $1-U \sim\mathsf{Unif}(0,1),$ also. $\endgroup$
    – BruceET
    Commented May 22, 2021 at 17:15
  • $\begingroup$ Thanks Bruce. Nice to know. $\endgroup$
    – Xenusi
    Commented May 22, 2021 at 17:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.