lm integration {bnlearn} R Documentation

Produce lm objects from Bayesian networks

Description

Take a bn object or bn.fit object encoding a Gaussian network and refit all the local distributions using lm(). This makes it possible to use all the functions provided by R for lm objects (summary, anova, etc.) to investigate the network.

Usage

## S3 method for class 'bn'
as.lm(x, data, ...)
## S3 method for class 'bn.fit'
as.lm(x, data, ...)
## S3 method for class 'bn.fit.gnode'
as.lm(x, data, ...)

Arguments

x

an object of class bn, bn.fit or bn.fit.gnode.

data

a data frame containing the variables in the model.

...

additional arguments, currently ignored.

Value

If x is an object of class bn or bn.fit, as.lm() returns a list of lm objects, one for each node in x. If x is an object of class bn or bn.fit.gnode, as.lm() returns a single lm object.

Author(s)

Marco

Examples

dag = hc(gaussian.test)
fitted = bn.fit(dag, gaussian.test)
as.lm(dag, gaussian.test)
as.lm(fitted, gaussian.test)
as.lm(fitted$F, gaussian.test)