1 Uniform Distribution

1.1 Definition

A random variable \(X\) has a uniform distribution on the interval \([a, b]\) (for \(a < b\)) if its pdf is

\[\begin{equation} f(x) = \begin{cases} \frac{1}{b-a}, & a \leq x \leq b \\ 0, & \text{otherwise.} \end{cases} \tag{1.1} \end{equation}\]

If \(X \sim \text{Unif}(a, b)\), then

\[\begin{equation} E(X) = \frac{a + b}{2} \tag{1.2} \end{equation}\] \[\begin{equation} V(X) = \frac{(b-a)^2}{12} \tag{1.3} \end{equation}\]

1.2 Example

Suppose \(X \sim \text{Unif}(10, 20)\).

  1. Find the \(E(X)\) and \(V(X)\) using the definitions of \(E(X)\) and \(V(X)\).
# part a.
xfx <- function(x){x/10}
EX <- integrate(xfx, 10, 20)$value
EX
[1] 15
x2fx  <- function(x){(x - EX)^2/10}
VX <- integrate(x2fx, 10, 20)$value
VX
[1] 8.333333
  1. Find the \(E(X)\) and \(V(X)\) using the short cut formulas in (1.2) and (1.3).

\(E(X) = \frac{a+b}{2}=\frac{10 + 20}{2} = 15\), and \(V(X) = \frac{(b-a)^2}{12} = \frac{(20 - 10)^2}{12} = \frac{100}{12} = 8.3333333.\)

  1. Simulate 10,000 values of the random variable and estimate \(E(X)\) and \(V(X)\).
# part c.
set.seed(89)
sims <- 10^4
X <- runif(sims, 10, 20)
EX <- mean(X)
VX <- var(X)
c(EX, VX)
[1] 14.997757  8.392661
  1. Find \(E(\bar{X})\) and \(V(\bar{X})\) for \(n = 8\) exactly and via simulation.

\(E(\bar{X}) = \mu_{\bar{X}} = \mu_X = 15\), \(V(\bar{X}) = \frac{\sigma^2_{X}}{n} = \frac{\frac{100}{12}}{8} = 1.0416667\)

set.seed(46)
sims <- 10^4
n <- 8
a <- 10
b <- 20
xbar <- numeric(sims)
for(i in 1:sims){
  X <- runif(n, a, b)
  xbar[i] <- mean(X)
}
mean(xbar)
[1] 15.01263
var(xbar)
[1] 1.043381

2 Exponential

2.1 Problem

Let \(X_1, X_2, \ldots, X_{20} \overset{i.i.d}\sim\text{Exp}(\lambda = 2)\). Let \(Y = \sum_{i=1}^{20}X_i.\)

  1. Simulate the sampling distribution of \(Y\) in R.
sims <- 10^4
Y <- numeric(sims)
for(i in 1:sims){
 Y[i] <- sum(rexp(20, 2))
}
EY <- mean(Y)
VY <- var(Y)
c(EY, VY)
[1] 10.017660  5.028047
mean(Y <= 10)
[1] 0.5268