| get_approx_posterior | R Documentation |
get_approx_posterior() returns an approximation to the posterior probability distribution
of a target variable given a set of observed variables. The inference process is based on sample generation. See details.
get_approx_posterior(
bn,
target,
evidence = NULL,
size = 100,
parallel = FALSE,
...
)
bn |
An object of class |
target |
A character string equal to the name of the variable of interest. |
evidence |
A |
size |
A non-negative integer giving the number of random samples to generate from |
parallel |
|
... |
Optional arguments passed on to the |
If any node is observed, i.e., argument evidence is not NULL,
samples are generated from the Bayesian network using the likelihood weighting algorithm.
Otherwise, i.e., no node is observed, samples are generated using the forward sampling algorithm.
A list of two elements: 1) the posterior probability distribution of the target variable, and
2) a data.frame with the generated sample, whose weights are attached as an attribute called weights (if evidence is not NULL).
Henrion, M. (1988). Propagating uncertainty in Bayesian networks by probabilistic logic sampling. In Machine Intelligence and Pattern Recognition (Vol. 5, pp. 149-163). North-Holland.
## Dataset
data("ecoli", package = "MoTBFs")
data <- ecoli[,-c(1,9)]
## Get directed acyclic graph
dag <- LearningHC(data)
## Learn bayesian network
bn <- motbf.fit(dag, data = data, numIntervals = 4, POTENTIAL_TYPE = "MOP")
## Specify the evidence set and target variable
obs <- data.frame(lip = "0.48", alm1 = 0.55, gvh = 1, stringsAsFactors=FALSE)
node <- "alm2"
## Get the posterior distribution of 'node' given "evidence" and the generated sample
get_approx_posterior(bn, target = node, evidence = obs, size = 10, maxParam = 15)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.