-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathev-continuous.Rmd
124 lines (93 loc) · 5.84 KB
/
ev-continuous.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# Expected Value of Continuous Random Variables {#ev-continuous}
## Theory {-}
<iframe width="560" height="315" src="https://www.youtube.com/embed/hpGoz6-4CC8" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
```{definition, name="Expected Value of a Continuous Random Variable"}
Let $X$ be a continuous random variable with p.d.f. $f(x)$. Then, the
expected value of $X$ is defined as
\begin{equation}
E[X] = \int_{-\infty}^\infty x \cdot f(x)\,dx.
(\#eq:ev-continuous)
\end{equation}
```
Compare this definition with the definition of expected value for a discrete random
variable \@ref(eq:ev). We simply replaced the p.m.f. by the p.d.f. and
the sum by an integral.
```{example ev-unif, name="Expected Value of the Uniform Distribution"}
Let $X$ be a $\text{Uniform}(a, b)$ random variable. What is $E[X]$?
First, the p.d.f. is
\[ f(x) = \begin{cases} \frac{1}{b-a} & a \leq x \leq b \\ 0 & \text{otherwise} \end{cases}, \]
which is non-zero only between $a$ and $b$. So, even though \@ref(eq:ev-continuous) says we should
integrate from $-\infty$ to $\infty$, the integrand will only be non-zero between $a$ and $b$.
\begin{align*}
E[X] &= \int_a^b x \cdot \frac{1}{b-a} \,dx \\
&= \frac{1}{b-a} \left. \frac{x^2}{2} \right]_a^b \\
&= \frac{1}{b-a} (b^2 - a^2) \frac{1}{2} \\
&= \frac{a + b}{2}.
\end{align*}
This is just the midpoint of the possible values of this uniform random variable. This is clearly the
point where the p.d.f. would balance, if we put it on a scale.
```{r ev-continuous, echo=FALSE, engine='tikz', out.width='70%', fig.ext='png', fig.align='center', fig.cap='Expected Value of the Uniform Distribution', engine.opts = list(template = "tikz_template.tex")}
\begin{tikzpicture}
\draw [gray,<->] (-2, 0) coordinate -- (2, 0) coordinate;
\fill[red!50] (-.3, -0.5) -- (0, 0) -- (.3, -0.5) -- cycle;
\node[anchor=north,red] at (0, -0.5) {$\frac{a + b}{2}$};
\node[anchor=north] at (-1, 0) {$a$};
\node[anchor=north] at (1, 0) {$b$};
\draw[thick] (-2, 0) coordinate -- (-1, 0) coordinate -- (-1, 1) coordinate -- (1, 1) coordinate -- (1, 0) coordinate -- (2, 0) coordinate;
\end{tikzpicture}
```
```{example ev-expo, name="Expected Value and Median of the Exponential Distribution"}
Let $X$ be an $\text{Exponential}(\lambda)$ random variable. What is $E[X]$? Does the
random variable have an equal chance of being above as below the expected value?
First, we calculate the expected value using \@ref(eq:ev-continuous) and the
p.d.f. of the exponential distribution \@ref(eq:exponential-pdf). This is an
exercise in integration by parts.
\begin{align*}
E[X] &= \int_0^\infty x \cdot \lambda e^{-\lambda x} \,dx \\
&= -x e^{-\lambda x} \Big|_0^\infty - \int_0^\infty -e^{-\lambda x}\,dx \\
&= \ (-0 + 0) - \underbrace{\frac{1}{\lambda} e^{-\lambda x} \Big|_0^\infty}_{0 - \frac{1}{\lambda}} \\
&= \frac{1}{\lambda}
\end{align*}
Now, let's calculate the probability that the random variable is below expected value.
\[ P(X < E[X]) = P(X < \frac{1}{\lambda}) = \int_0^{1/\lambda} \lambda e^{-\lambda x}\,dx = 1 - e^{-1} \approx .632. \]
The random variable does not have an 50/50 chance of being above or below its expected value.
The value that a random variable has an equal chance of being above or below is called its **median**. To
calculate the median, we have to solve for $m$ such that
\[ P(X < m) = 0.5. \]
(Equivalently, we could solve $P(X > m) = 0.5$. It also doesn't matter whether we use
$<$ or $\leq$, since this is a continuous random variable, so $P(X = m) = 0$.)
Calculating the probability in terms of $m$, we have
\[ 0.5 = P(X < m) = \int_0^m \lambda e^{-\lambda x}\,dx = 1 - e^{-\lambda m}. \]
Solving for $m$, we see that the median is $-\log(0.5) / \lambda$. (Note: $\log$ here is the natural logarithm,
base $e$.)
```{r, echo=FALSE, engine='tikz', out.width='70%', fig.ext='png', fig.align='center', fig.cap='Mean vs. Median of the Exponential Distribution', engine.opts = list(template = "tikz_template.tex")}
\begin{tikzpicture}
\draw[red!50,dashed,thick] (1, 0) -- (1, 2);
\fill[red!50] (.8, -0.4) -- (1, 0) -- (1.2, -0.4) -- cycle;
\node[anchor=east,red,rotate=90] at (1.01, -0.4) {$E[X]$};
\fill [blue!40,smooth,samples=50,domain=0:.693] (0, 0) -- plot(\x,{2*exp(-(\x))}) -- (.693, 0);
\draw[blue!40,dashed,thick] (.693, 0) -- (.693, 2);
\node[anchor=east,blue,rotate=90] at (.65, 0) {median};
\node[blue] at (0.33, 0.65) {{\small 50\%}};
\draw [gray,->] (-0.1, 0) coordinate -- (3.5, 0) coordinate;
\draw [gray,->] (0, -0.1) coordinate -- (0, 2.1) coordinate;
\node[anchor=north] at (3.5, 0) {$x$};
\node[anchor=east] at (0, 1.8) {$f(x)$};
\draw [thick,smooth,samples=100,domain=0:3.5] plot(\x,{2*exp(-(\x))});
\end{tikzpicture}
```
Formulas for the variance of named continuous distributions can be found
in Appendix \@ref(continuous-distributions).
## Essential Practice {-}
1. The distance (in hundreds of miles) driven by a trucker in one day is a continuous
random variable $X$ whose cumulative distribution function (c.d.f.) is given by:
\[ F(x) = \begin{cases} 0 & x < 0 \\ x^3 / 216 & 0 \leq x \leq 6 \\ 1 & x > 6 \end{cases}. \]
a. Calculate $E[X]$, the expected value of $X$.
b. Calculate the median of $X$.
c. Sketch a graph of the p.d.f., along with the locations of the expected value and median.
2. Suppose that an electronic device has a lifetime $T$ (in hours) that follows
an $\text{Exponential}(\lambda=\frac{1}{1000})$ distribution.
a. What is $E[T]$?
b. Suppose that the cost of manufacturing one such item is $2. The manufacturer sells
the item for $5, but guarantees a total refund if the lifetime ends up being less than 900 hours.
What is the manufacturer's expected profit per item?