Create a predict function for use of a bnlearn Bayesian network in the search algorithms.
bnlearn_predict_wrapper.Rd
Create a predict function for use of a bnlearn Bayesian network in the search algorithms.
Arguments
- bn
Fitted Bayesian network
- node
Name of target node to be predicted
- method
Same options as in parameter 'method' in predict function of bnlearn
- threshold
Minimum value of posterior probability of the MLE to be the output of the algorithm. If parameter 'default' is null, the MLE will be the output even if it doesn't surpass the threshold.
- default
Default predicted target value when threshold isn't exceeded by the MLE
- n
Same options as in parameter 'n' in predict function of bnlearn
Examples
library(bnlearn)
set.seed(40)
download.file("https://www.bnlearn.com/bnrepository/child/child.rda",
"child.rda", "auto",
quiet = TRUE
)
load("child.rda") # Load CHILD Bayesian Network
evidence <- data.frame(
LVHReport = factor(x = "yes", levels = dimnames(bn$LVHreport$prob)[[1]]),
LowerBodyO2 = factor(x = "5-12", levels = dimnames(bn$LowerBodyO2$prob)[[1]]),
CO2Report = factor(x = "<7.5", levels = dimnames(bn$CO2Report$prob)[[1]]),
XrayReport = factor(x = "Oligaemic", levels = dimnames(bn$XrayReport$prob)[[1]])
)
outcome <- predict(
object = bn, node = bn$Disease$node, data = evidence,
method = "bayes-lw"
)
expected <- factor("PAIVS", levels = levels(outcome))
predict_f <- bnlearn_predict_wrapper(bn, bn$Disease$node, "bayes-lw",
threshold = 0.20, default = "TGA"
)
print(bfs_sfx(predict_f, evidence, outcome, expected))
#> [[1]]
#> [[1]]$LVHReport
#> [1] yes
#> Levels: yes no
#>
#> [[1]]$XrayReport
#> [1] Oligaemic
#> Levels: Normal Oligaemic Plethoric Grd_Glass Asy/Patchy
#>
#>