rm(list=ls()) # remove all objects from environment cat(“) # Clear the console graphics.off() # Clear all graphs gc() # Clear unused memory

a1<-0.2 a2<-0.35 a3<-0.45 bGivena1<-0.7 bGivena2<-0.25 bGivena3<-0.05 notbGivena1<-0.3 notbGivena2<-0.75 notbGivena3<-0.95

a1ANDb <- a1 * bGivena1 a1ANDnotb <- a1 * notbGivena1 a1Givenb <- (bGivena1a1)/((bGivena1a1)+(bGivena2a2)+(bGivena3a3))

a2ANDb <- a2 * bGivena2 a2ANDnotb <- a2 * notbGivena2 a2Givenb <- (bGivena2a2)/((bGivena1a1)+(bGivena2a2)+(bGivena3a3))

a3ANDb <- a3 * bGivena3 a3ANDnotb <- a3 * notbGivena3 a3Givenb <- (bGivena3a3)/((bGivena1a1)+(bGivena2a2)+(bGivena3a3))

node1 <- “P” node2 <- “Sporting” node3 <- “Academic” node4 <- “None” node5 <- “Full for Sport” node6 <- “SpaceAva for Sport” node7 <- “Full for Acad” node8 <- “SpaceAva for Acad” node9 <- “Full for None” node10 <- “SpaceAva for None” nodeNames <- c(node1, node2, node3, node4, node5, node6, node7,node8,node9,node10)

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

Erase any existing plots

dev.off()

LINES

Draw the “lines” or “branches” of the probability Tree

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, 10)

eAttrs <- list()

q <- edgeNames(rEG)

PROBABILITY VALUES

Add the probability values to the the branch lines

eAttrs$label <- c(toString(a1), toString(a2), toString(a3), toString(bGivena1), toString(notbGivena1), toString(bGivena2), toString(notbGivena2), toString(bGivena3), toString(notbGivena3) )

names(eAttrs$label) <- c( q[1], q[2], q[3], q[4], q[5], q[6], q[7], q[8], q[9] ) edgeAttrs <- eAttrs

COLOR

Set the color, etc, of the tree

attributes <- list(node = list(label = “foo”, fillcolor = “lightgreen”, fontsize = “15” ), edge = list(color = “red”), graph = list(rankdir = “LR”) )

PLOT

Plot the probability tree using Rgraphvis

plot (rEG, edgeAttrs = eAttrs, attrs=attributes) nodes(rEG) edges(rEG)

PROBABILITY (labels)

#Add the probability values to the leaves of A&B, A&B’, A’&B, A’&B’

text(500,470, a1, cex = .8) text(500,385, a1ANDnotb, cex = .8) text(500,300, a2, cex = .8) text(500,220 , a2ANDnotb, cex = .8) text(500,130 , a3, cex = .8) text(500,40 , a3ANDnotb, cex = .8) text(340,460, “(B | A1)”, cex = .8) text(340,370, “(B | A1’)”, cex = .8) text(340,300, “(B | A2)”, cex = .8) text(340,220, “(B | A2’)”, cex = .8) text(340,110, “(B | A3)”, cex = .8) text(340,60, “(B | A3’)”, cex = .8)

#Write a table in the lower left of the probablites of A and B

text(80,440, paste(“P(A1|B):” ,round(a1Givenb, digits = 2)), cex = .9, col = “blue”) text(80,415, paste(“P(A2|B):” ,round(a2Givenb, digits = 2)), cex = .9, col = “blue”) text(80,3, paste(“P(A3|B):” ,round(a3Givenb, digits = 2)), cex = .9, col = “blue”)