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.
require("Rgraphviz")
## Loading required package: Rgraphviz
## Loading required package: graph
## Loading required package: BiocGenerics
##
## Attaching package: 'BiocGenerics'
## The following objects are masked from 'package:stats':
##
## IQR, mad, sd, var, xtabs
## The following objects are masked from 'package:base':
##
## anyDuplicated, aperm, append, as.data.frame, basename, cbind,
## colnames, dirname, do.call, duplicated, eval, evalq, Filter, Find,
## get, grep, grepl, intersect, is.unsorted, lapply, Map, mapply,
## match, mget, order, paste, pmax, pmax.int, pmin, pmin.int,
## Position, rank, rbind, Reduce, rownames, sapply, setdiff, sort,
## table, tapply, union, unique, unsplit, which.max, which.min
## Loading required package: grid
PA1 <- .20 # Sporting Event
PA2 <- .35 # Academic Event
PA3 <- .45 # No Event
PB_A1 <- .7 # Garage Full - Sport
PB_A2 <- .25 # Garage Full - Academic
PB_A3 <- .05 # Garage Full - No Event
PA1_B <- (PA1 * PB_A1) / ((PA1*PB_A1)+(PA2*PB_A2)+(PA3*PB_A3))
PA1_B
## [1] 0.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
Creating Labels …
node1<-"P"
node2<-"Sporting Event"
node3<-"Academic Event"
node4<-"No Event"
node5<-"Sporting Event + Full"
node6<-"Sporting Event + Not Full"
node7<-"Academic Event + Full"
node8 <-"Academic Event + Not Full"
node9 <- "No Event + Full"
node10 <-"No Event + Not Full"
nodeNames<-c(node1,node2,node3,node4,node5,node6,node7,node8,node9,node10)
rEG <- new("graphNEL",
nodes=nodeNames,
edgemode="directed"
)
Create 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 Values to Branches…
eAttrs$label <- c(toString(PA1),toString(PA2),
toString(PA3), toString(PB_A1),
toString(PB_A2), toString(PB_A3), toString(PC1), toString(PC2), 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="yellow", fontsize="15"),
edge=list(color="black"),graph=list(rankdir="LR"))
#Plot the probability tree using Rgraphvis
plot(rEG, edgeAttrs=eAttrs, attrs=attributes)