gmInstance {gRain} | R Documentation |
The 'newgmInstance' builds a graphical independence network.
newgmInstance(x, gmData, description="ProbNet", control=list(), trace=0,...)
x |
An argument to build an independence network from. |
gmData |
A gmData object (see Examples below) |
description |
A text describing the network |
control |
A list defining controls, see 'details' below. |
trace |
Debugging information. |
... |
Additional arguments, currently not used. |
If 'smooth' is non-zero then entries of 'values' which a zero are replaced by the value of 'smooth' - BEFORE any normalization takes place.
An object of class "gmInstance"
Søren Højsgaard, sorenh@agrsci.dk
## Asia (chest clinique) example - using a gmData object ## chestNames <- c("asia", "smoke", "tub", "lung", "bronc", "either", "xray", "dysp") gmd <- newgmData(chestNames,valueLabels=c("yes","no")) summary(gmd) p.a <-cpt('asia', values=c(0.01,0.99),gmData=gmd) p.t.a <-cpt('tub',pa='asia', values=c(0.05,0.95,0.01,0.99),gmData=gmd) p.s <-cpt('smoke', values=c(0.5,0.5), gmData=gmd) p.l.s <-cpt('lung',pa='smoke', values=c(0.1,0.9,0.01,0.99), gmData=gmd) p.b.s <-cpt('bronc',pa='smoke', values=c(0.6,0.4,0.3,0.7), gmData=gmd) p.e.lt <-cpt('either',pa=c('lung','tub'),values=c(1,0,1,0,1,0,0,1),gmData=gmd) p.x.e <-cpt('xray',pa='either', values=c(0.98,0.02,0.05,0.95), gmData=gmd) p.d.be <-cpt('dysp',pa=c('bronc','either'), values=c(0.9,0.1,0.7,0.3,0.8,0.2,0.1,0.9), gmData=gmd) cptlist <- list(p.a, p.t.a, p.s, p.l.s, p.b.s, p.e.lt, p.x.e, p.d.be) cptlist[[1]] cptlist[[2]] bn <- newgmInstance(cptspec(cptlist), gmd) bn summary(bn) plot(bn) ## Asia (chest clinique) example - without using a gmData object ## yn <- c("yes","no") a <- cpt(~asia, values=c(1,99),levels=yn) t.a <- cpt(~tub+asia, values=c(5,95,1,99),levels=yn) s <- cpt(~smoke, values=c(5,5), levels=yn) l.s <- cpt(~lung+smoke, values=c(1,9,1,99), levels=yn) b.s <- cpt(~bronc+smoke, values=c(6,4,3,7), levels=yn) e.lt <- cpt(~either+lung+tub,values=c(1,0,1,0,1,0,0,1),levels=yn) x.e <- cpt(~xray+either, values=c(98,2,5,95), levels=yn) d.be <- cpt(~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 <- newgmInstance(plist) pn summary(pn) plot(pn) ## Create network from gmData (with data) and graph specification. ## There are different ways: ## data(HairEyeColor) d <- as.gmData(HairEyeColor) dag <- newdagsh(list(~Hair, ~Eye+Hair, ~Sex+Hair)) class(dag) ug <- newugsh(list(~Eye+Hair, ~Sex+Hair)) class(ug) ## 1) Create directly from dag b1 <- newgmInstance(dag,d) class(b1) ## 2) Extract cpt's for dag from gmData and build network from cpt's x<-dag2cptspec(dag,d) class(x) b2 <- newgmInstance(x,d) class(b2) ## 3) Build model from undirected (decomposable) graph b3 <- newgmInstance(ug,d) class(b3)