Learn R Programming

bnlearn (version 4.6.1)

rbn: Simulate random samples from a given Bayesian network

Description

Simulate random samples from a given Bayesian network.

Usage

# S3 method for bn
rbn(x, n = 1, data, fit = "mle", …, debug = FALSE)
# S3 method for bn.fit
rbn(x, n = 1, …, debug = FALSE)

Arguments

x

an object of class bn or bn.fit.

n

a positive integer giving the number of observations to generate.

data

a data frame containing the data the Bayesian network was learned from.

fit

a character string, the label of the method used to fit the parameters of the newtork. See bn.fit for details.

...

additional arguments for the parameter estimation prcoedure, see again bn.fit for details.

debug

a boolean value. If TRUE a lot of debugging output is printed; otherwise the function is completely silent.

Value

A data frame with the same structure (column names and data types) of the data argument (if x is an object of class bn) or with the same structure as the data originally used to to fit the parameters of the Bayesian network (if x is an object of class bn.fit).

Details

rbn() implements forward/logic sampling: values for the root nodes are sampled from their (unconditional) distribution, then those of their children conditional on the respective parent sets. This is done iteratively until values have been sampled for all nodes.

If x contains NA parameter estimates (because of unobserved discrete parents configurations in the data the parameters were learned from), rbn will produce samples that contain NAs when those parents configurations appear in the simulated samples. See bn.fit for details on how to make sure bn.fit objects contain no NA parameter estimates.

References

Korb K, Nicholson AE (2010). Bayesian Artificial Intelligence. Chapman & Hall/CRC, 2nd edition.

See Also

bn.boot, bn.cv.

Examples

Run this code
# NOT RUN {
data(learning.test)
res = gs(learning.test)
res = set.arc(res, "A", "B")
par(mfrow = c(1,2))
plot(res)
sim = rbn(res, 500, learning.test)
plot(gs(sim))
# }

Run the code above in your browser using DataLab