In the Grade Network that we looked at in the notes, what happens to the probability of Diffculty of Course when you present the evidence that the received recommendation let- ter was good? In addition, now present the evidence that both SAT scores were good and the letter of recommendation was good, What is the probability of the Diffculty of Course now? You should use the gRain package in R to build your network and perform these calculations. You may need to install RBGL package from BioConductor in R to get gRain working. See http://www.bioconductor.org/packages/release/bioc/html/RBGL.html for instructions on RBGL. Please submit your assignment as an R markdown document.
require(gRain)
## Loading required package: gRain
## Warning: package 'gRain' was built under R version 3.3.3
## Loading required package: gRbase
## Warning: package 'gRbase' was built under R version 3.3.3
#Now to set the variables going off of the chart on page 3 of our notes
level_ny <- c("no", "yes")
level_lh <- c("low", "high")
#now to set the provided probabilities for wach category
d <- cptable(~difficulty, values = c(.3, .7), levels = level_ny)
i <- cptable(~intelligence, values = c(.8, .2), levels = level_lh)
s <- cptable(~SAT|intelligence, values = c(.9, .2, .1, .8), levels = level_lh)
g <- cptable(~grade|difficulty:intelligence, values = c(.6, .4, .8, .2, .1, .99, .1, .9), levels = level_lh)
l <- cptable(~letter|grade, values = c(.9, .01, .05, .95), levels = level_lh)
plist <- compileCPT(list(d, i, s, g, l))
#as a check I want to ake sure that my input correlates to what is provided in the reading
plist$difficulty
## difficulty
## no yes
## 0.3 0.7
## attr(,"class")
## [1] "parray" "array"
plist$intelligence
## intelligence
## low high
## 0.8 0.2
## attr(,"class")
## [1] "parray" "array"
plist$SAT
## intelligence
## SAT low high
## low 0.8181818 0.1111111
## high 0.1818182 0.8888889
## attr(,"class")
## [1] "parray" "array"
plist$grade
## , , intelligence = low
##
## difficulty
## grade no yes
## low 0.6 0.8
## high 0.4 0.2
##
## , , intelligence = high
##
## difficulty
## grade no yes
## low 0.09174312 0.1
## high 0.90825688 0.9
##
## attr(,"class")
## [1] "parray" "array"
plist$letter
## grade
## letter low high
## low 0.98901099 0.05
## high 0.01098901 0.95
## attr(,"class")
## [1] "parray" "array"
Now that we have our variables as it is in the output is similar to and probablities set we can find the requested probabilities.
grain_list <- grain(plist)
querygrain(grain_list, c(nodes = "difficulty", "intelligence", "SAT", "grade", "letter", type = "marginal"))
## $difficulty
## difficulty
## no yes
## 0.3 0.7
##
## $intelligence
## intelligence
## low high
## 0.8 0.2
##
## $grade
## grade
## low high
## 0.6115046 0.3884954
##
## $SAT
## SAT
## low high
## 0.6767677 0.3232323
##
## $letter
## letter
## low high
## 0.6242095 0.3757905
prob_diff <- setEvidence(grain_list, nodes = "letter", states = "high")
querygrain(prob_diff, nodes = "difficulty", type = "marginal")
## $difficulty
## difficulty
## no yes
## 0.3848249 0.6151751
+ Given the evidence above, we see that the probability of a class being difficult decreases to .61 while the probability of a class not being difficult increases to .39
prob_sat <- setEvidence(grain_list, nodes = c("SAT", "letter"), states = c("high", "high"))
querygrain(prob_sat, nodes = "difficulty", type = "marginal")
## $difficulty
## difficulty
## no yes
## 0.3317626 0.6682374
+ Given the above, the probability of a difficult class increased to .67 and decreased to .32