---
output:
  pdf_document: default
  html_document: default
---
# Section 3.1: Probability Mass Functions

## Random Variables

### Example 

1. Consider an experiment that is the single roll of a die, where the number of spots on the face up side of the die when rolled is observed. 

* Outcome space: 


* Space of the random variable $X$: 


2. Dr. D has 2 dogs and 2 cats in her household, so $S = \{cat, dog\}$. Let $Y$ be a random variable that denotes the type of animal. $Y$ then maps each element in $S$ to one and only one real number: 




### Distribution of a Random Variable:

### Example
Consider a crooked dice where the cube is shortened in the one-six direction. This has the effect that 1's and 6's have a probability of 1/4 of being rolled, where the other faces each have a probability of 1/8. 

* Define the random variable



* Write out the probability distribution.


* Is this a valid pmf?  Explain.


### You try it

Suppose your roll 2 dice. Let $X$ be the sum of the two die. Write out the pmf. Don't forget you can refer to Example 2.8 in the textbook to visualize the sample space. 



## Using simulation to estimate discrete probability distributions. 

### Example
Suppose your roll 2 dice. Let $X$ be the sum of the two die. Use simulation to estimate the probability distribution.



The pmf of $X$ is: 


## Plotting the pmf
We can use the function `plot` to plot the estimate of the pmf using the following code.



\newpage
### You try it

1. Three coins are tossed and the number of heads $X$ is counted. Write out the theoretical pmf for $X$ and confirm via simulation.



2. Seven balls number 1-7 are in an urn. Two balls are drawn from the urn without replacement and the sum of $X$ of the numbers is computed. Estimate via simulation the pmf of $X$.


What are the least likely outcomes of $X$?


\newpage

### Challenge Example

Suppose you have a bag full of marbles; 50 are red and 50 are blue. You are standing on a number line, and you draw a marble out of the bag. If you get red, you go left one unit. If you get blue, you go right one unit. This is called a *random walk*. You draw marbles up to 100 times, each time moving left or right one unit. Let $X$ be the number of marbles drawn from the bag until you return to 0 for the first time. The rv $X$ is called the *first return time* since it is the number of steps it takes to return to your starting position.


Estimate the pmf of $X$.

\newpage

## Sampling from a known distribution 

### Example: Blood types

In the United states, human blood comes in four types: O,A,B,AB. Take a sample of thirty blood types with the following probabilities: $P(O) = 0.45, P(A) = 0.4, P(B) = 0.11, P(AB) = 0.04$ 


The estimated pmf is then: 


### You try it

Suppose the proportion of M&Ms by color is: 14% yellow, 13% Red, 20% Orange, 12% Brown, 20% Green, and 21% Blue. Answer the following questions using simulation. 

a. What is the probability that a randomly selected M&M is not green?

b. What is the probability that a randomly selected M&M is red, orange, or yellow?
    
