class: center, middle, inverse, title-slide # Ec140 - Mean and Expectation ### Fernando Hoces la Guardia ### 06/23/2022 --- <style type="text/css"> .remark-slide-content { font-size: 30px; padding: 1em 1em 1em 1em; } </style> # Housekeeping - Updated Syllabus - Unofficial Course Capture! - What is the weirdest concept you remember from yesterday? - Switch to finish yesterday's slides --- # This Lecture - Introduction to Data - Mean and Expectation - Variance and Standard Deviation --- # What Defines a Data Set? .font90[ - Data Set is the collection of any type information (of multiple *Datum*) - In quantitative analysis we focus on *structured* data sets (unlike, for example, unstructured field notes). - In econometrics the most commnon way to structure data is in tabular, or rectangular, form. - A tabular data set is a collection of variables that with information for one or more entities. - Entities can represent multiple individuals, one individual over time, firms, countries, etc. - Variables are represented in columns, and observations are represented by rows. (for more on variables [The Effect, Ch3](https://theeffectbook.net/ch-DescribingVariables.html#descriptions-of-variables)) ] --- # Data .pull-left[ .font60[
] ] --- # But What Can We Do With Data? -- .font90[ - We summarized it! (see the great [short story by J.L. Borges](https://tinyurl.com/yx2n5xon) on why summarizing is essential) .pull-left[ - One of the first thing we do when summarizing data is to look at *some type of average*. - Wait? *Type* of average? Isn't there just one average? called *the mean*? ] ] --- count:true background-image: url("Images/average_def.png") background-size: 50% background-position: 100% 40% # But What Can We Do With Data? .font90[ - We summarized it! (see the great [short story by J.L. Borges](https://tinyurl.com/yx2n5xon) on why summarizing is essential) .pull-left[ - One of the first thing we do when summarizing data is to look at *some type of average*. - Wait? *Type* of average? Isn't there just one average? called *the mean*? - These is also referred as measure of central tendency. - In this course, we will focus primarily on the mean. **From now on in this course mean = average**. ] ] --- # Mean - The mean is defined by the sum of a set of values divided by the number of values. Let’s look at the mean from the "hang out with a friend" exercise. - Total over N $$ `\begin{equation} Average(X) = \frac{ 1 \times 10 + 2 \times 9 + 3 \times 11 }{30} = \color{#9370DB}{2.03} \end{equation}` $$ - One number, **highly informative** for a variable of interest. - Always important to keep an eye on the units and magnitude (relevant for PS1). --- # Mean of a Binary Variable - The interpretation for the mean of a binary variable is different from the case when there are more than two values. - Above, the interpretation of `\(Average(X) = 2.03\)` can be read as "close to having an OK time with a friend". - But when variables only take two values, and we assing those values to be 0 and 1, the interpretation of the mean is "the proportion of all the cases where the variable takes the value of one". - Think of the the variable `hispanic` for students in this classroom (1 if identifies as hispanic, 0 otherwise). --- count:true # Mean: .font80[Notation (Message to me: draw histogram on the board)] -- .font90[ $$ `\begin{equation} Average(X) = \frac{ 1 \times 10 + 2 \times 9 + 3 \times 11 }{30} = \color{#9370DB}{2.03}\\ \end{equation}` $$ $$ `\begin{equation} Ave(X) = 1 \times \frac{10}{30} + 2 \times \frac{9}{30} + 3 \times \frac{11}{30} = \color{#9370DB}{2.03}\\ \end{equation}` $$ ] --- count:true # Mean: Notation .font90[ $$ `\begin{equation} Average(X) = \frac{ 1 \times 10 + 2 \times 9 + 3 \times 11 }{30} = \color{#9370DB}{2.03}\\ \end{equation}` $$ $$ `\begin{equation} Ave(X) = \color{#FD5F00}{1} \times \color{#007935}{\frac{10}{30}} + \color{#FD5F00}{2} \times \color{#007935}{\frac{9}{30}} + \color{#FD5F00}{3} \times \color{#007935}{\frac{11}{30} } = \color{#9370DB}{2.03}\\ \end{equation}` $$ ] -- .font90[ $$ `\begin{equation} \overline{X}_{n} = \color{#FD5F00}{x_{1}} \times \color{#007935}{proportion(x_{1})} + \color{#FD5F00}{x_{2}} \times \color{#007935}{proportion(x_{2})} + \color{#FD5F00}{x_{3}} \times \color{#007935}{proportion(x_{3})}\\ \end{equation}` $$ ] -- .font90[ $$ `\begin{equation} \overline{X}_{n} = \text{summing across all } x \left( \color{#FD5F00}{x} \times \color{#007935}{proportion_{n}(x)} \right)\\ \end{equation}` $$ ] -- .font90[ $$ `\begin{equation} \overline{X}_{n} = \sum_{x} \color{#FD5F00}{x} \times \color{#007935}{prop_{n}(x)}\\ \end{equation}` $$ ] --- count:true # Mean: Notation .font90[ $$ `\begin{equation} Average(X) = \frac{ 1 \times 10 + 2 \times 9 + 3 \times 11 }{30} = \color{#9370DB}{2.03}\\ \end{equation}` $$ $$ `\begin{equation} Ave(X) = \color{#FD5F00}{1} \times \color{#007935}{\frac{10}{30}} + \color{#FD5F00}{2} \times \color{#007935}{\frac{9}{30}} + \color{#FD5F00}{3} \times \color{#007935}{\frac{11}{30} } = \color{#9370DB}{2.03}\\ \end{equation}` $$ ] .font90[ $$ `\begin{equation} \overline{X}_{n} = \color{#FD5F00}{x_{1}} \times \color{#007935}{proportion(x_{1})} + \color{#FD5F00}{x_{2}} \times \color{#007935}{proportion(x_{2})} + \color{#FD5F00}{x_{3}} \times \color{#007935}{proportion(x_{3})}\\ \end{equation}` $$ ] .font90[ $$ `\begin{equation} \overline{X}_{n} = \text{summing across all } x \left( \color{#FD5F00}{x} \times \color{#007935}{proportion_{n}(x)} \right)\\ \end{equation}` $$ ] .font90[ $$ `\begin{equation} \overline{X}_{n} = \sum_{x} \color{#FD5F00}{x} \times \color{#007935}{prop_{n}(x)}\\ \end{equation}` $$ ] --- count:true # Expected Value - Let’s look at the histogram for the exercise above (drawn in the board) and pretend it is not a sample but the entire population. How can we move from frequencies into probabilities? - Replace frequencies by probabilities - The population version of the sample mean is the **expected value**. --- # Expected Value: Definition (Discrete) The expected value of a discrete random variable `\(X\)` is the weighted average of its `\(k\)` values `\(\{x_1, \dots, x_k\}\)` and their associated probabilities: $$ `\begin{aligned} \mathop{\mathbb{E}}(X) &= x_1 \mathop{\mathbb{P}}(X = x_1) + x_2 \mathop{\mathbb{P}}(X = x_2) + \dots +x_k \mathop{\mathbb{P}}(X = x_N) \\ &= \sum_{x} x\mathop{\mathbb{P}}(X = x) \end{aligned}` $$ -- - Also known as the .hi[population mean]. --- # Expected Value: Definition (Discrete) The expected value of a discrete random variable `\(X\)` is the weighted average of its `\(k\)` values `\(\{x_1, \dots, x_k\}\)` and their associated probabilities: $$ `\begin{aligned} \mathop{\mathbb{E}}(X) &= x_1 \mathop{\mathbb{P}}(X = x_1) + x_2 \mathop{\mathbb{P}}(X = x_2) + \dots +x_k \mathop{\mathbb{P}}(X = x_k) \\ &= \sum_{x} \color{#FD5F00}{x} \color{#007935}{\mathop{\mathbb{P}}(X = x)} = \sum_{x} \color{#FD5F00}{x} \color{#007935}{f(x)} \end{aligned}` $$ - Also known as the .hi[population mean]. Compare it to the sample mean: $$ `\begin{equation} \overline{X}_{n} = \sum_{x} \color{#FD5F00}{x} \times \color{#007935}{prop_{n}(x_{1})}\\ \end{equation}` $$ --- # Expected Value ## Example Rolling a six-sided die once can take values `\(\{1, 2, 3, 4, 5, 6\}\)`, each with equal probability. .hi-purple[What is the expected value of a roll?] -- `\(\mathop{\mathbb{E}}(\text{Roll}) = 1 \times \frac{1}{6} + 2 \times \frac{1}{6} + 3 \times \frac{1}{6} + 4 \times \frac{1}{6} + 5 \times \frac{1}{6} + 6 \times \frac{1}{6} = \color{#9370DB}{3.5}\)`. - __Note:__ The expected value can be a number that isn't a possible outcome of `\(X\)`. --- # Expected Value. Definition (Continuous) .pull-left[ If `\(X\)` is a continuous random variable and `\(f(x)\)` is its probability density function, then the expected value of `\(X\)` is $$ \mathop{\mathbb{E}}(X) = \int_{-\infty}^{\infty} x f(x) dx. $$ - __Note:__ `\(x\)` represents the particular values of `\(X\)`. - Same idea as the discrete definition: describes the .hi[population mean]. ] .pull-right[ <img src="03_exp_sd_files/figure-html/unnamed-chunk-3-1.svg" style="display: block; margin: auto;" /> ] --- count:true # Expected Value. Definition (Continuous) - Compare it to the discrete version - Continuous $$ \mathop{\mathbb{E}}(X) = \int_{-\infty}^{\infty} x f(x) dx. $$ - Discrete $$ \mathop{\mathbb{E}}(X) = \sum_{x} \color{#FD5F00}{x} \color{#007935}{f(x)} $$ --- # Expected Value. Definition (Continuous) - Compare it to the discrete version - Continuous $$ \mathop{\mathbb{E}}(X) = \color{#9370DB}{\int_{-\infty}^{\infty}} \color{#FD5F00}{x} \color{#007935}{f(x)} \color{#9370DB}{dx}. $$ - Discrete $$ \mathop{\mathbb{E}}(X) = \color{#9370DB}{\sum_{x}} \color{#FD5F00}{x} \color{#007935}{f(x)} $$ .right[ This explanation was inspired by [this lecture from Eddie Woo](https://youtu.be/tF2Kns7RrfQ) ] --- # Expected Value. Definition. One Last Thing 1/2 Let's go back to the mean of our exercise: $$ `\begin{equation} \overline{X}_{n} = \color{#FD5F00}{1} \times \color{#007935}{\frac{10}{30}} + \color{#FD5F00}{2} \times \color{#007935}{\frac{9}{30}} + \color{#FD5F00}{3} \times \color{#007935}{\frac{11}{30} } = \color{#9370DB}{2.03}\\ \end{equation}` $$ But now let's switch the values of the random variables to: 10, 20, 30. How should we compute the mean? -- $$ `\begin{equation} \overline{g(X)}_{n} = \color{#FD5F00}{10} \times \color{#007935}{\frac{10}{30}} + \color{#FD5F00}{20} \times \color{#007935}{\frac{9}{30}} + \color{#FD5F00}{30} \times \color{#007935}{\frac{11}{30} } = \color{#9370DB}{20.33}\\ \end{equation}` $$ --- # Expected Value. Definition. One Last Thing 2/2 Hence, we can conclude, that for a random variable `\(X\)`, any transformation `\(g(X)\)` has a sample aveage: $$ `\begin{equation} \overline{X}_{n} = \sum_{x} \color{#FD5F00}{g(x)} \times \color{#007935}{prop_{n}(x_{1})}\\ \end{equation}` $$ And an expectation: $$ \mathop{\mathbb{E}}(g(X)) = \color{#9370DB}{\sum_{x}} \color{#FD5F00}{g(x)} \color{#007935}{f(x)} $$ The same idea applies in the case of a continues random variable --- # Expected Value: Rules (or Properties) ## Rule 1 For any constant `\(c\)`, `\(\mathop{\mathbb{E}}(c) = c\)`. -- ## Not-so-exciting examples `\(\mathop{\mathbb{E}}(5) = 5\)`. `\(\mathop{\mathbb{E}}(1) = 1\)`. `\(\mathop{\mathbb{E}}(4700) = 4700\)`. --- # Expected Value ## Rule 2 For any constants `\(a\)` and `\(b\)`, `\(\mathop{\mathbb{E}}(aX + b) = a\mathop{\mathbb{E}}(X) + b\)`. -- ## Example Suppose `\(X\)` is the high temperature in degrees Celsius in Eugene during August. The long-run average is `\(\mathop{\mathbb{E}}(X) = 28\)`. If `\(Y\)` is the temperature in degrees Fahrenheit, then `\(Y = 32 + \frac{9}{5} X\)`. .hi-purple[What is] `\(\color{#9370DB}{\mathop{\mathbb{E}}(Y)}\)`.hi-purple[?] -- - `\(\mathop{\mathbb{E}}(Y) = 32 + \frac{9}{5} \mathop{\mathbb{E}}(X) = 32 + \frac{9}{5} \times 28 = \color{#9370DB}{82.4}\)`. --- # Expected Value ## Rule 3: Linearity If `\(\{a_1, a_2, \dots , a_n\}\)` are constants and `\(\{X_1, X_2, \dots , X_n\}\)` are random variables, then $$ \color{#FD5F00}{\mathop{\mathbb{E}}(a_1 X_1 + a_2 X_2 + \dots + a_n X_n)} = \color{#007935}{a_1 \mathop{\mathbb{E}}(X_1) + a_2 \mathop{\mathbb{E}}(X_2) + \dots + a_n \mathop{\mathbb{E}}(X_n)}. $$ In English, .hi-orange[the expected value of the sum] .mono[=] .hi-green[the sum of expected values]. --- # Expected Value ## Rule 3 .hi-orange[The expected value of the sum] .mono[=] .hi-green[the sum of expected values]. ## Example Suppose that a coffee shop sells `\(X_1\)` small, `\(X_2\)` medium, and `\(X_3\)` large caffeinated beverages in a day. The quantities sold are random with expected values `\(\mathop{\mathbb{E}}(X_1) = 43\)`, `\(\mathop{\mathbb{E}}(X_2) = 56\)`, and `\(\mathop{\mathbb{E}}(X_3) = 21\)`. The prices of small, medium, and large beverages are `\(1.75\)`, `\(2.50\)`, and `\(3.25\)` dollars. .hi-purple[What is expected revenue?] -- $$ `\begin{aligned} \color{#FD5F00}{\mathop{\mathbb{E}}(1.75 X_1 + 2.50 X_2 + 3.35 X_n)} &= \color{#007935}{1.75 \mathop{\mathbb{E}}(X_1) + 2.50 \mathop{\mathbb{E}}(X_2) + 3.25 \mathop{\mathbb{E}}(X_3)} \\ &= \color{#9370DB}{1.75(43) + 2.50(56) + 3.25(21)} \\ &= \color{#9370DB}{283.5} \end{aligned}` $$ --- # Expected Value ## __Caution__ Previously, we found that the expected value of rolling a six-sided die is `\(\mathop{\mathbb{E}} \left(\text{Roll} \right) = 3.5\)`. - If we square this number, we get `\(\left[\mathop{\mathbb{E}} ( \text{Roll} ) \right]^2 = 12.25\)`. __Is__ `\(\left[\mathop{\mathbb{E}} \left( \text{Roll} \right) \right]^2\)` __the same as__ `\(\mathop{\mathbb{E}} \left(\text{Roll}^2 \right)\)`__?__ -- __No!__ $$ `\begin{aligned} \mathop{\mathbb{E}} \left( \text{Roll}^2 \right) &= 1^2 \times \frac{1}{6} + 2^2 \times \frac{1}{6} + 3^2 \times \frac{1}{6} + 4^2 \times \frac{1}{6} + 5^2 \times \frac{1}{6} + 6^2 \times \frac{1}{6} \\ &\approx 15.167 \\ &\neq 12.25. \end{aligned}` $$ --- # Expected Value ## __Caution__ Except in special cases, .hi-purple[the transformation of an expected value] __is not__ .hi-green[the expected value of a transformed random variable]. For some function `\(g(\cdot)\)`, it is typically the case that `$$\color{#9370DB}{g \left( \mathop{\mathbb{E}}(X) \right)} \neq \color{#007935}{\mathop{\mathbb{E}} \left( g(X) \right)}.$$` --- # Activity 1 - Let's watch [another Stat 110's video](https://youtu.be/sheoa3TrcCI). Then get together in groups of 3 and discuss: - Don't worry about the law of large numbers yet - How does the random variables becomes continuous? - How does linearity help with computations?