---
title: "Lab 6"
output:
  html_document: default
  pdf_document: default
  word_document: default
date: "February 22-23, 2022"
---

## Objectives:
  * Review laws of probability
  * Practice using laws of probability and building a venn diagram


In class last week, we discussed and practiced the rules of probability.  In today's lab, we will review these concepts. 


## Properties of Probability


  * Addition Rule: $P(A \cup B) = P(A) + P(B) - P(A \cap B)$
  
  * Complement Rule: $P(A^C) = 1 - P(A)$
  
  * Multiplication Rule: $P(A \cap B) = P(A)P(B|A)$
  
  * Law of Total Probability: $P(A) = P(A \cap B) + P(A \cap B^c)$
  
  * Bayes' Rule: $P(A|B) = \frac{P(A)P(B|A)}{P(A)P(B|A) + P(A^c)P(B|A^c)}$
  
  * Sensitivity: $P(Test+ | Disease+)$
  
  * Specificity: $P(Test- | Disease -)$
  
  * False Positive: $P(Test+| Disease -) = 1-Specificity$
  
  * False Negative: $P(Test-| Disease +) = 1-Sensitivity$
  
  * Prevalence: $P(Disease)$



## Independence VS Mutually Exclusive

These two terms are very easily confused, but need to be kept separate as they mean two different things.  Two outcomes are said to be independent if the probability of the first outcome does not change the probability of the second outcome.


  * Independence: 
    * $P(A|B) = P(A)$
    * $P(B|A) = P(B)$


This independence works both ways as the outcome of A will also not effect the outcome of B.  Mutually exclusive on the other hand, is the idea that the two outcomes cannot occur simultaneously.  That is, the intersection of the two events is always equal to zero. In terms of a Venn diagram the two circles will never overlap. Note that an event and it's compliment are ALWAYS mutually exclusive (an event either happens or it doesn't).


  * Mutually Exclusive: 
    * $P(A \cap B) = 0$
    * $P(A \cap A^c) = 0$


## Practice Probability Examples

<br>
 
#### 1. On the Iowa Football Team there are exactly 99 players on the team.  Of them 32 are freshman, 12 are sophmores, 34 are juniors, and 21 are seniors. 

  * Are the years of study mutually exclusive?

  * If a football player is selected at random what is the probability that he is not a senior?

  * If you select a random football player and it is given that he is not a senior what is the probability of him being a sophomore?

  * What is the probability that I pull two juniors out randomly with replacement?  Without replacement?

  What assumption changed based on the question asked?
  
<br>

#### 2. Consider the following table regarding the periodontal status of individuals and their gender. Periodontal status refers to gum disease where individuals are classified as either healthy, have gingivitis, or have periodontal disease. Assume the study included 8027 individuals.

```{r, echo = FALSE, message = FALSE}
library(tidyverse)
library(kableExtra)
tab2 <- data.frame(Gender = c("Male", "Female", "Total"),
                   Healthy = character(3),
                   Gingivitis = character(3),
                   Perio = character(3),
                   Total = character(3))
kable(tab2) %>%
  kable_styling(bootstrap_options = c("striped", "hover")) %>%
  add_header_above(c(" " = 1, "Periodontal Status" = 3, " " = 1))
```


Fill in the following table with the given information as COUNTS:
  
  The probability that a person is male is 0.3749,
  
  The probability that a person is both male and healthy is 0.1429, 
  
  The probability that a person is both male and has Perio is 0.1167,
  
  The probability of being healthy is 0.4672,
  
  The probability that a person is female and has Perio 0.1147
  
  
  * Calculate the probability that the participant is male or healthy. 

  * What is the probability of being female and having either gingivitis or periodontal disease? 

  * What is the probability of an individual having periodontal disease given that she is female?

<br>

#### 3. In a certain region, one in every thousand people (0.001) is infected by the HIV virus that causes AIDS. Tests for presence of the virus are fairly accurate but not perfect.If someone actually has HIV, the probability of testing positive is 0.95.

  * Let H denote the event of having HIV, and T the event of testing positive. Express the information that is given in the problem in terms of the events H and T.

  * Find the probability that someone chosen at random from the population has HIV and tests positive.         *Interpret this as a rate per 10,000 people*

  * If someone has HIV, what is the probability of testing negative?


<br>

#### 4. Scenario (from Gigerenzer 2007): The prevalence of breast cancer in women is 1%. A mammography has sensitivity of 90% (90% of women with breast cancer will test positive) and a false positive rate of 9%.


What is the probability a person has the disease given that they tested positive (use Bayes' rule).

  * To set up this equation, first write the information provided in the form of probability notation and identify the corresponding proportions. You should do this for prevalence of cancer, prevalence of no cancer, sensitivity, specificity, and false positive and false negative rates.  

  * Now modify the Bayes' rule formula to match the notation you wrote in part (a) to find the probability of breast cancer given that the test is positive. 

  * Finally plug in and calculate the answer. Interpret the results. 


<br>

#### 5. The probability of it raining on any given day in Iowa City is 0.2. The probability that it is raining in Hawaii is 0.6. With the given information, construct a Venn diagram that includes the whole event space. 

<br>

![](H:/venn.png)

<br>

#### 6. Suppose that we have a standard deck of 52 playing cards.

  * What is the probability of drawing a face card (jack, queen, or king)?
  * What is the probability of drawing a red face card?
  * What is the probability of drawing a red card or a face card?
  * What is the probability of drawing a red card or a face card or a 7?
  
 <br>
  
