Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

network

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) 
## S3 method for class 'network'
print(x,filename=NA,condposterior=FALSE,
                          condprior=FALSE,...) 
## S3 method for class 'network'
 plot(x,arrowlength=.25,
                        notext=FALSE,
                        sscale=7,showban=TRUE,yr=c(0,350),xr=yr,
                        unitscale=20,cexscale=8,...)

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 rnetwork.

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

The netork creator function returns 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 Bottcher,
Claus Dethlefsen rpackage.deal@gmail.com.

See Also

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
localprob(mynw,"sex")   <- c(0.4,0.6)
localprob(mynw,"age")   <- c(0.6,0.4)
localprob(mynw,"yield") <- c(2,0)
localprob(mynw,"weight")<- c(1,0)

print(mynw)
plot(mynw)

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

print(mynw,condposterior=TRUE)

## Not run: savenet(mynw,file("yield.net"))

deal

Learning Bayesian Networks with Mixed Variables

v1.2-39
GPL (>= 2)
Authors
Susanne Gammelgaard Bottcher, Claus Dethlefsen.
Initial release
2018-10-20

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.