Learn R Programming

gRain (version 0.8.1)

grain: Graphical Independence Network

Description

The 'grain' builds a graphical independence network.

Usage

grain(x, data, control=list(), smooth=0, details=0, ...)

Arguments

x
An argument to build an independence network from.
data
An optional data set (currently must be an array/table)
control
A list defining controls, see 'details' below.
smooth
A (usuall small) number to add to the counts of a table if the grain is built from a graph plus a dataset.
details
Debugging information.
...
Additional arguments, currently not used.

Value

  • An object of class "grain"

Details

If 'smooth' is non-zero then entries of 'values' which a zero are replaced by the value of 'smooth' - BEFORE any normalization takes place.

See Also

cptable, setFinding, getFinding, pFinding, retractFinding

Examples

Run this code
yn <- c("yes","no")
a    <- cptable(~asia, values=c(1,99),levels=yn)
t.a  <- cptable(~tub+asia, values=c(5,95,1,99),levels=yn)
s    <- cptable(~smoke, values=c(5,5), levels=yn)
l.s  <- cptable(~lung+smoke, values=c(1,9,1,99), levels=yn)
b.s  <- cptable(~bronc+smoke, values=c(6,4,3,7), levels=yn)
e.lt <- cptable(~either+lung+tub,values=c(1,0,1,0,1,0,0,1),levels=yn)
x.e  <- cptable(~xray+either, values=c(98,2,5,95), levels=yn)
d.be <- cptable(~dysp+bronc+either, values=c(9,1,7,3,8,2,1,9), levels=yn)


plist <- compileCPT(list(a, t.a, s, l.s, b.s, e.lt, x.e, d.be))
pn <- grain(plist)
pn

summary(pn)
plot(pn)data(HairEyeColor)
d   <- HairEyeColor
dag <- dagList(list(~Hair, ~Eye+Hair, ~Sex+Hair))
class(dag)
ug <- ugList(list(~Eye+Hair, ~Sex+Hair))
class(ug)b1  <- grain(dag,d)
class(b1)b3  <- grain(ug,d)
class(b3)plist <- compileCPT(list(a, t.a))
pn <- grain(plist)
querygrain(pn)plist <- compileCPT(list(a, t.a, s))
pn <- grain(plist)
querygrain(pn)

Run the code above in your browser using DataLab