---
title: Estimators
output:
  html:
    self-contained: TRUE
---

<iframe width="759" height="527" src="https://www.youtube.com/embed/Zgt7W3_Gf8s" title="2.2.1 Estimators for the expectation and variance of a random variable" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>

<div style="background-color:#d2ff96; border-width:3px; border-style:solid; border-color:#d2ff96; padding: 1em;">
<strong>Exercise 1: Understanding Estimators</strong> 
Let’s start with the basics! Given sample data, write down the formulas for:

1. The best estimator of a random variable’s expectation.
2. The best estimator of a random variable’s variance.
</div>

<div style="background-color:white; border-width:3px; border-style:solid; border-color:black; padding:1em;">
<em>Answers:</em>

- Estimator for a RV's expectation: $___$
- Estimator for a RV's variance: $___$
</div>

<br>

<div style="background-color:#d2ff96; border-width:3px; border-style:solid; border-color:#d2ff96; padding: 1em;">
<strong>Exercise 2: Estimating Expected Value</strong>
A real estate analyst collected data on the percentage change in home values over one year for six properties:

`{5.2%, -1.8%, 7.5%, 4.9%, 6.1%, 3.2%}`

Your task: What is the best estimate for the expected value of the random variable “annual percentage change in home value”? Use R code to solve this problem.
</div>

<div style="background-color:white; border-width:3px; border-style:solid; border-color:black; padding:1em;">
*Answer:* 

```{r}
# homes <- c(_____, _____, _____, _____, _____, _____)  
# avg <- sum(_____) / length(_____)  
# avg  
```
</div>
<br>

<div style="background-color:#d2ff96; border-width:3px; border-style:solid; border-color:#d2ff96; padding: 1em;">
<strong>Exercise 3: Estimating Variance</strong>
Using the same data from Exercise 2, what is the best estimate for the variance of the random variable “annual percentage change in home value”? Use R code to solve this problem.
</div>

<div style="background-color:white; border-width:3px; border-style:solid; border-color:black; padding:1em;">
*Answer:* 

```{r}
# sum((_____ - _____)^2) / (length(_____) - 1)
```
</div>
<br>

<div style="background-color:#d2ff96; border-width:3px; border-style:solid; border-color:#d2ff96; padding: 1em;">
<strong>Exercise 4: Checking Your Work</strong>
Let’s verify your answers to Exercises 2 and 3 using R’s built-in functions:

- `mean()` estimates the expected value of a RV.
- `var()` estimates the variance of a RV.
</div>

<div style="background-color:white; border-width:3px; border-style:solid; border-color:black; padding:1em;">
*Answer:* 

```{r}
# mean(_____)  
# var(_____)
```
</div>
