Situation: Uniform random variables can be either discrete or continuous, and describe a distribution where all outcomes are equally likely. Examples include
pdf: f(x)=1b−aa≤x≤b
Distributional Notation: X∼Unif(a,b)
Mean and variance: E[X]=b+a2Var(X)=(b−a)212
R commands:
punif(x, a, b)
to compute P(X≤x) (the cdf)runif(N, a, b)
to randomly draw N samples from a X∼Unuf(a,b) distribution.Visualizing the shape of the distribution What happens to the distribution as you change a and b?
Suppose a random variable X has a uniform distribution on the interval [-3,8], then the p.d.f. of X is
f(x)={1b−a for a<x<b0otherwise
Calculate P(0≤X≤4). Do this by hand, and confirm your answer using punif
∫40111dx=111x|40=411
punif(4, -3, 8) - punif(0, -3, 8) # 4/11
## [1] 0.3636364
Calculate the mean and standard deviation. Do this by hand, and confirm your answer using simulation.
E(X)=b+a2=8−32=2.5SD(X)=√(b−a)212=√(8+3)212=3.17
<- runif(10000, -3, 8)
x mean(x)
## [1] 2.495369
sd(x)
## [1] 3.190014
Suppose that a random variable X has a uniform distribution on the interval [-4,10]. Write down the pdf of X, find the mean, standard deviation and the value of P(−1<X<6) both theoretically and using simulation.
f(x)={114 for −4<x<100otherwise
E(X)=10−42=3SD(X)=√(10+4)212=4.04P(−1<X<6)=∫6−1114dx=12
<- runif(10000, -4, 10)
x mean(x)
## [1] 2.964397
sd(x)
## [1] 4.03015
mean(x < 6 & x > -1)
## [1] 0.4943
Situation: Exponential random variables measure the waiting time until the first event occurs in a Poisson process.
Distributional Notation: Let X∼Exp(λ) be an exponential random variable with rate λ.
pdf: f(x)=λe−λyy≥0
Mean and variance: E[X]=1λVar(X)=1λ2
R commands:
dunif(x, lambda)
to compute P(X==x)punif(x, lambda)
to compute P(X≤x) (the cdf)runif(N, lambda)
to randomly draw N samples from a X∼Exp(λ) distribution.Visualizing the shape of the distribution What happens to the distribution as you change lambda?
Suppose the time to failure (in years) for a particular component is distributed as an exponential random variable with rate λ=1/5. For better performance, the system has two components installed, and the system will work as long as either components installed, and the system will work as long as either component is functional. Assume the time to failure for the two components is independent. What is the probability that the system will fail before 10 years has passed?
Let X1 be the time until component 1 fails. Let X2 be the time until component 2 fails.
X1∼Exp(15),X2∼Exp(15)
The system fails if X1<10 and X2<10. Since these are independent events,
P(systemfail)=P(X1<10)∗P(X2<10)
∫10015e−15x1dx1∗∫10015e−15x2dx2
I don’t want to integrate that.
pexp(10, 1/5)^2
## [1] 0.7476451
<- rexp(10000, 1/5)
time.of.failure mean(time.of.failure<10)^2
## [1] 0.7511689
Customers arrive at a teller’s window at a uniform rate 5 per hour. Let X be the length in minutes of time that the teller has to wait until they see their first customer after starting their shift.
Customers arriving is a poisson process with λ=5 per hour. So the wait time in minutes is Exp(5/60).
E(X)=1λ=605=12SD(X)=√1λ2=605=12
<- rexp(10000, 5/60)
wait.time mean(wait.time)
## [1] 12.01216
sd(wait.time)
## [1] 11.93927
Use both theoretical formulas (pexp
)
pexp(10, 5/60)
## [1] 0.5654018
and simulation (rexp
).
mean(wait.time < 10)
## [1] 0.5678