
A Bayesian network is represented as an object of class
network
. Methods for printing and plotting are defined.
network(df,specifygraph=FALSE,inspectprob=FALSE,
doprob=TRUE,yr=c(0,350),xr=yr)
# S3 method for network
print(x,filename=NA,condposterior=FALSE,
condprior=FALSE,...)
# S3 method for network
plot (x,arrowlength=.25,
notext=FALSE,
sscale=7,showban=TRUE,yr=c(0,350),xr=yr,
unitscale=20,cexscale=8,...)
The netork
creator function returns an object of class
network
, which is a list with the following
elements (properties),
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
.
an integer containing the number of nodes in the network.
a numeric vector of indices of discrete nodes.
a numeric vector of indices of continuous nodes.
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.
a numeric added by learn
and is the log network
score.
a numeric added by nwfsort
and is the relative
network score -- compared with the best network in a network family.
a data frame, where the columns define the variables. A
continuous variable should have type numeric
and discrete varibles
should have type factor
.
a logical. If TRUE
, provides a call to
drawnetwork
to interactively specify a directed
acyclic graph and possibly a ban list (see below).
a logical. If TRUE
, provides a plot of the
graph and possibility to inspect the calculated probability
distribution by clicking on the nodes.
a logical. If TRUE
, do not calculate a
probability distribution. Used
for example in rnetwork
.
an object of class network
.
a string or NA
. If not NA
, output is
printed to a file.
a logical. If TRUE
, the conditional prior is
printed, see conditional
.
a logical. If TRUE
, the conditional posterior is
printed, see learn
.
a numeric. The nodes are initially placed on a circle
with radius sscale
.
a numeric. Scale parameter for chopping off arrow heads.
a numeric. Scale parameter to set the size of the nodes.
a numeric containing the length of the arrow heads.
a numeric vector with two components containing the range on x-axis.
a numeric vector with two components containing the range on y-axis.
a logical. If TRUE
, no text is displayed in the nodes on the plot.
a logical. If TRUE
, banned arrows are shown in red.
additional plot arguments, passed to plot.node
.
Susanne Gammelgaard Bottcher,
Claus Dethlefsen rpackage.deal@gmail.com.
networkfamily
,
node
,
rnetwork
,
learn
,
drawnetwork
,
jointprior
,
heuristic
,
nwequal
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)
if (FALSE) savenet(mynw,file("yield.net"))
Run the code above in your browser using DataLab