network {deal}R Documentation

Bayesian network data structure

Description

A Bayesian network is represented as an object of class network. Methods for printing and plotting are defined.

Usage

network(df,specifygraph=FALSE,inspectprob=FALSE,
        doprob=TRUE,yr=c(0,350),xr=yr) 
print(x,filename=NA,condposterior=FALSE,
                          condprior=FALSE,...) 
plot (x,arrowlength=.25,
                        notext=FALSE,
                        sscale=7,showban=TRUE,yr=c(0,350),xr=yr,
                        unitscale=20,cexscale=8,...)

prob.network (x,df)

banlist(x)
"banlist<-"(x,value)

Arguments

df a data frame, where the columns define the variables. A continuous variable should have type numeric and discrete varibles should have type factor.
specifygraph a logical. If TRUE, provides a call to drawnetwork to interactively specify a directed acyclic graph and possibly a ban list (see below).
inspectprob a logical. If TRUE, provides a plot of the graph and possibility to inspect the calculated probability distribution by clicking on the nodes.
doprob a logical. If TRUE, do not calculate a probability distribution. Used for example in simulation.
x an object of class network.
filename a string or NA. If not NA, output is printed to a file.
condprior a logical. If TRUE, the conditional prior is printed, see conditional.
condposterior a logical. If TRUE, the conditional posterior is printed, see learn.
sscale a numeric. The nodes are initially placed on a circle with radius sscale.
unitscale a numeric. Scale parameter for chopping off arrow heads.
cexscale a numeric. Scale parameter to set the size of the nodes.
arrowlength a numeric containing the length of the arrow heads.
xr a numeric vector with two components containing the range on x-axis.
yr a numeric vector with two components containing the range on y-axis.
notext a logical. If TRUE, no text is displayed in the nodes on the plot.
showban a logical. If TRUE, banned arrows are shown in red.
... additional plot arguments, passed to plot.node.
value a numeric matrix with two columns. Each row contains the indices i -> j of arrows that may not be allowed in the directed acyclic graph.

Value

An object of class network, which is a list with the following elements (properties),

nodes a list of objects of class node. If doprob is TRUE, the nodes are given the property prob which is the initial probability distribution used by jointprior.
n an integer containing the number of nodes in the network.
discrete a numeric vector of indices of discrete nodes.
continuous a numeric vector of indices of continuous nodes.
banlist a numeric matrix with two columns. Each row contains the indices i -> j of arrows that may not be allowed in the directed acyclic graph.
score a numeric added by learn and is the log network score.
relscore a numeric added by nwfsort and is the relative network score – compared with the best network in a network family.

Author(s)

Susanne Gammelgaard Bøttcher alma@math.auc.dk,
Claus Dethlefsen dethlef@math.auc.dk.

References

Further information about deal can be found at:
http://www.math.auc.dk/novo/deal.

See Also

networkfamily, node, simulation, learn, drawnetwork, jointprior, heuristic, nwequal

Examples

A <- factor(rep(c("A1","A2"),50))
B <- factor(rep(rep(c("B1","B2"),25),2))
thisnet <- network( data.frame(A,B) )

set.seed(109)
sex     <- gl(2,4,label=c("male","female"))
age     <- gl(2,2,8)
yield   <- rnorm(length(sex))
weight  <- rnorm(length(sex))
mydata  <- data.frame(sex,age,yield,weight)
mynw    <- network(mydata)

# adjust prior probability distribution
mynw$nodes$sex$prob[1:2]   <- c(0.4,0.6)
mynw$nodes$age$prob[1:2]   <- c(0.6,0.4)
mynw$nodes$yield$prob[1:2] <- c(2,0)
mynw$nodes$weight$prob[1:2]<- c(1,0)

print(mynw)
plot(mynw)

prior <- jointprior(mynw)
mynw  <- learn(mynw,mydata,prior)$nw
thebest <- autosearch(mynw,mydata,prior)$nw

print(mynw,condposterior=TRUE)

savenet(mynw,"yield.net")

[Package Contents]