1. Please explain Bayes Theorem in your own words, and give an example. Less than 10 sentences. Also, write out the formula. Pick up on how to to type equations in R Markdown using Latex terminology

Bayes Theorem: Bayes Theorem is when we update the probability based on new information or evidence. By being able to use updated information in our formula, it can help us create a more accurate probability hypothesis. This theorem is an extension of conditional probabilities. Since we know conditional probability is what we use to predict the probability of A|B (A happening given that B happened). By using Bayes Theorem, we can essentially calculate the probability of A occurring if we know the probability of another event related to B occurring.

The formula is listed below.

\(P(A \mid B)\) = \(\displaystyle \frac{P(B\mid A)* P(A) }{P(B)}\)

2.1 QUESTION: Guided Practice 3.43: Jose visits campus every Thursday evening. However, some days the parking garage is full, often due to college events. There are academic events on 35% of evenings, sporting events on 20% of evenings, and no events on 45% of evenings. When there is an academic event, the garage fills up about 25% of the time, and it fills up 70% of evenings with sporting events. On evenings when there are no events, it only fills up about 5% of the time. If Jose comes to campus and finds the garage full, what is the probability that there is a sporting event? Use a tree diagram to solve this problem.

Below, I have listed the probabilities for each type of event along with their corresponding % of how full the garage gets.

Academic Events: 35%

Sporting Events: 20%

No events: 45%

# Sporting Event
PA1 <- .20 

# Academic Event
PA2 <- .35  

# No Event
PA3 <- .45  

# Garage Full - Sporting Event
PB_A1 <- .70  

# Garage Full - Academic Event
PB_A2 <- .25 

# Garage Full - No Event
PB_A3 <- .05 

PA1_B <- (PA1 * PB_A1) / ((PA1*PB_A1)+(PA2*PB_A2)+(PA3*PB_A3))
PA1_B 
## [1] 0.56

As we can see above, the probability of there being a sporting event when Jose sees the garage full is 56%.

Our numerator was probability of the garage being full during a sporting event * the probability of there being a sporting event

\(P(B \mid A)* P(A)\) = 0.20*0.70 = 0.14

We then set up our denominator being the sum of each events probability * the probability of the garage being full for that event

\({P(B)}\) = (0.20 * 0.70)+(0.35 * 0.25)+(0.45 * 0.05)

(0.14+0.0875+0.0225) = 0.25

\(P(A \mid B)\) = 0.14/0.025 = 0.56 = 56%

PC1 <- 1-PB_A1 # Not Full - Sport
PC2 <- 1-PB_A2 # Not Full - Academic
PC3 <- 1-PB_A3 # Not Full - No Event

# Create Joint Probabilities #

PAB1 <- PA1 * PB_A1
PAC1 <- PA1 * PC1

PAB2 <- PA2 * PB_A2
PAC2 <- PA2 * PC2

PAB3 <- PA3 * PB_A3
PAC3 <- PA3 * PC3

Graph

Nodes

node1<-"P"
node2<-"Sport"
node3<-"Academic"
node4<-"No Event"
node5<-"Sport Full"
node6<-"Sport N_Full"
node7<-"Acad Full"
node8 <-"Acad N_Full"
node9 <- "No Event Full"
node10 <-"No Event N_Full"
nodeNames<-c(node1,node2,node3,node4,node5,node6,node7,node8,node9,node10)

rEG <- new("graphNEL", 
           nodes=nodeNames, 
           edgemode="directed"
)

Branches

rEG <- addEdge(nodeNames[1], nodeNames[2], rEG, 1)
rEG <- addEdge(nodeNames[1], nodeNames[3], rEG, 1)
rEG <- addEdge(nodeNames[1], nodeNames[4], rEG, 1)
rEG <- addEdge(nodeNames[2], nodeNames[5], rEG, 1)
rEG <- addEdge(nodeNames[2], nodeNames[6], rEG, 1)
rEG <- addEdge(nodeNames[3], nodeNames[7], rEG, 1)
rEG <- addEdge(nodeNames[3], nodeNames[8], rEG, 1)
rEG <- addEdge(nodeNames[4], nodeNames[9], rEG, 1)
rEG <- addEdge(nodeNames[4], nodeNames[10], rEG, 1)

eAttrs <- list()
 
q<-edgeNames(rEG)

Adding Probability

eAttrs$label <- c(toString(PA1),
                  toString(PA2),
                  toString(PA3), 
                  toString(PB_A1),
                  toString(PC1), 
                  toString(PB_A2), 
                  toString(PC2), 
                  toString(PB_A3), 
                  toString(PC3)
                  )
names(eAttrs$label) <- c(q[1],q[2], q[3], q[4], q[5], q[6], q[7], q[8], q[9])
edgeAttrs<-eAttrs

# Set the color, etc, of the tree
attributes<-list(node=list(label="example", 
                           fillcolor="lightblue", 
                           fontsize=""),
 edge=list(color="black"),
 graph=list(rankdir="LR"))
 
#Plot the probability tree using Rgraphvis
plot(rEG, edgeAttrs=eAttrs, attrs=attributes)

nodes(rEG)
##  [1] "P"               "Sport"           "Academic"        "No Event"       
##  [5] "Sport Full"      "Sport N_Full"    "Acad Full"       "Acad N_Full"    
##  [9] "No Event Full"   "No Event N_Full"