grain {gRain}R Documentation

Graphical Independence Network

Description

The 'grain' builds a graphical independence network.

Usage

grain(x, data, description="grain",  control=list(), trace=0, ...) 

Arguments

x An argument to build an independence network from.
data An optional data set (currently must be an array/table)
description A text describing the network
control A list defining controls, see 'details' below.
trace Debugging information.
... Additional arguments, currently not used.

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.

Value

An object of class "grain"

Author(s)

Søren Højsgaard, sorenh@agrsci.dk

See Also

cptable, setFinding, getFinding, pFinding, retractFinding, gmData

Examples


## Asia (chest clinique) example 
##
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 <- cptspec(list(a, t.a, s, l.s, b.s, e.lt, x.e, d.be))
pn <- grain(plist)
pn

summary(pn)
plot(pn)

## Create network from gmData (with data) and graph specification.
## There are different ways:
##
data(HairEyeColor)
d   <- HairEyeColor
dag <- dagList(list(~Hair, ~Eye+Hair, ~Sex+Hair))
class(dag)
ug <- ugList(list(~Eye+Hair, ~Sex+Hair))
class(ug)

## Create directly from dag
##
b1  <- grain(dag,d)
class(b1)

## 3) Build model from undirected (decomposable) graph
b3  <- grain(ug,d)
class(b3)

## Simple example - one clique only in triangulated graph
##
plist <- cptspec(list(a, t.a))
pn <- grain(plist)
querygrain(pn)

## Simple example - disconnected network
##
plist <- cptspec(list(a, t.a, s))
pn <- grain(plist)
querygrain(pn)


[Package gRain version 0.7.0 Index]