# Understanding rexp function in R to draw samples from exponential distribution

I want to get the number of arrivals per 1 second for a 10 second period. Let's assume that lambda is 15 per second, and I want a sample size of 10. I generate random numbers exponentially distributed with

x <- rexp(10, 15)
> x
 0.00285 0.06528 0.07963 0.01826 0.00915 0.13058 0.15633 0.00758 0.02254  0.22933
> 1/x
 350.53  15.32  12.56  54.75 109.34   7.66   6.40 131.87  44.38   4.36


Is 1/x the arrival rate for each of 10 time slots or am I missing something?

Exponential distribution describes times between events happening at constant rate $\lambda$ with expected value $1/\lambda$. Quoting Wikipedia:

The exponential distribution is used to model the time between the occurrence of events in an interval of time, or the distance between events in space. The exponential distribution may be useful to model events such as

• The time between goals scored in a World Cup soccer match
• The duration of a phone call to a help center
• The time between meteors greater than 1 meter diameter striking earth
• The time between successive failures of a machine
• The time from diagnosis until death in patients with metastatic cancer
• The distance between successive breaks in a pipeline

The exponential distribution is an appropriate model if the following conditions are true.

• X is the time (or distance) between events, with X > 0.
• The occurrence of one event does not affect the probability that a second event will occur. That is, events occur independently.
• The rate at which events occur is constant. The rate cannot be higher in some intervals and lower in other intervals.
• Two events cannot occur at exactly the same instant.

If these conditions are true, then X is an exponential random variable, and the distribution of X is an exponential distribution. If these conditions are not true, then the exponential distribution is not appropriate.

Is 1/x the arrival rate for each of 10 time slots or am I missing something?

The answer is no, 1/x has nothing to do with arrival rates per time unit. Exponential distribution describes arrival times happening at common, constant rate $\lambda$ per time unit. So arrival rate per each of the time units is the same and equal to $\lambda$ and you know this because by choosing exponential distribution for your simulation this is what you assume.

Using your example, say that we simulate 50 arrival times x happening at rate $\lambda = 15$ per time unit:

set.seed(123)
x <- rexp(50, 15)


average arrival time is mean(x) = 0.075, that is pretty close to the expected arrival time $E(X) = 1/\lambda = 0.067$ (notice that we are dealing with pretty small sample, it would be closer with larger one). In total, fifty arrivals took sum(x) = 3.768, what again is what we could expect from $50$ arrivals happening ar rate $15$ per time unit $50/15 = 3.333$. If you look at cumulative sum of arrival times

    1     2     3     4     5     6     7     8     9    10    11    12    13    14    15
0.056 0.095 0.183 0.185 0.189 0.210 0.231 0.241 0.423 0.425 0.492 0.524 0.542 0.567 0.580
16    17    18    19    20    21    22    23    24    25    26    27    28    29    30
0.637 0.741 0.773 0.812 1.082 1.138 1.202 1.301 1.391 1.469 1.576 1.676 1.781 1.783 1.822
31    32    33    34    35    36    37    38    39    40    41    42    43    44    45
1.967 2.001 2.018 2.191 2.273 2.326 2.368 2.451 2.491 2.566 2.594 3.075 3.131 3.146 3.220
46    47    48    49    50
3.369 3.460 3.499 3.680 3.768


you will notice that until the end of first time unit we observed $19$ arrivals, in the next time unit we observed $13$ arrivals, and in the third one $10$ arrivals. Again, if we used larger sample size for simulation, on average we would expect to see approximately $\lambda = 15$ arrivals per time unit.

If you want to simulate process where arrival rate changes, exponential distribution is inappropriate, as described above. On another hand, if you are interested in simulating number of events that happen in fixed time interval with known average rate, then Poisson distribution seems to be more appropriate.

• "The rate at which events occur is constant. The rate cannot be higher in some intervals and lower in other intervals." This means not like a drum beaet constant but say in every 10,000 hours of soccer played, there will be 30,000 goals? How do we choose the interval size to ensure that this assumption holds? – mLstudent33 Feb 17 at 23:12
• @mLstudent33 it doesn't say that you can find such interval. It says that if your data is about a process that has constant rate, then it can be described by exponential distribution. – Tim Feb 18 at 5:52