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)=\frac{1}{b-a} \qquad a \leq x \leq b\)
Distributional Notation: \(X\sim Unif(a,b)\)
Mean and variance: \(E[X]=\frac{b+a}{2} \qquad Var(X)=\frac{(b-a)^{2}}{12}\)
R commands:
punif(x, a, b)
to compute \(P(X\leq x)\) (the cdf)runif(N, a, b)
to randomly draw N samples from a \(X \sim 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)=\Biggl\{ \begin{array}{cc} \frac{1}{b-a} & \mbox{ for } a < x < b \\ 0& {otherwise} \end{array} \]
Calculate P\((0\leq X\leq 4)\). Do this by hand, and confirm your answer using punif
\[ \int_{0}^{4} \frac{1}{11} dx = \frac{1}{11}x \Biggl|_{0}^{4} = \frac{4}{11} \]
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) = \frac{b+a}{2} = \frac{8-3}{2} = 2.5 \\ SD(X) = \sqrt{\frac{(b-a)^2}{12}} = \sqrt{\frac{(8+3)^2}{12}} = 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)=\Biggl\{ \begin{array}{cc} \frac{1}{14} & \mbox{ for } -4 < x < 10 \\ 0& {otherwise} \end{array} \]
\[ \begin{aligned} E(X) =& \frac{10-4}{2} = 3 \\ SD(X) =& \sqrt{\frac{(10+4)^2}{12}} = 4.04 \\ P(-1 < X < 6) =& \int_{-1}^{6} \frac{1}{14}dx = \frac{1}{2} \end{aligned} \]
<- 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\sim Exp(\lambda)\) be an exponential random variable with rate \(\lambda\).
pdf: \(f(x) = \lambda e^{-\lambda y} \qquad y \geq 0\)
Mean and variance: \(E[X]=\frac{1}{\lambda} \qquad Var(X)=\frac{1}{\lambda^{2}}\)
R commands:
dunif(x, lambda)
to compute \(P(X == x)\)punif(x, lambda)
to compute \(P(X\leq x)\) (the cdf)runif(N, lambda)
to randomly draw N samples from a \(X \sim Exp(\lambda)\) 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 \(\lambda=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 \(X_{1}\) be the time until component 1 fails. Let \(X_{2}\) be the time until component 2 fails.
\[X_{1} \sim Exp(\frac{1}{5}), \qquad X_{2} \sim Exp(\frac{1}{5})\]
The system fails if \(X_{1}<10\) and \(X_{2}<10\). Since these are independent events,
\[P(system fail) = P(X_{1}<10)*P(X_{2}<10)\]
\[ \int_{0}^{10}\frac{1}{5}e^{-\frac{1}{5}x_{1}} \, dx_{1} * \int_{0}^{10}\frac{1}{5}e^{-\frac{1}{5}x_{2}} \, dx_{2} \]
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 \(\lambda = 5\) per hour. So the wait time in minutes is \(Exp(5/60)\).
\[ E(X) = \frac{1}{\lambda} = \frac{60}{5} = 12 \\ SD(X) = \sqrt{\frac{1}{\lambda^2}} = \frac{60}{5} = 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