## example 1
## use built-in simulated data set
mydat<-ex1.dag.data;## this data comes with abn see ?ex1.dag.data
## setup distribution list for each node
mydists<-list(b1="binomial",
p1="poisson",
g1="gaussian",
b2="binomial",
p2="poisson",
b3="binomial",
g2="gaussian",
b4="binomial",
b5="binomial",
g3="gaussian"
);
#use simple banlist with no constraints
ban<-matrix(c(
# 1 2 3 4 5 6
0,0,0,0,0,0,0,0,0,0, # 1
0,0,0,0,0,0,0,0,0,0, # 2
0,0,0,0,0,0,0,0,0,0, # 3
0,0,0,0,0,0,0,0,0,0, # 4
0,0,0,0,0,0,0,0,0,0, # 5
0,0,0,0,0,0,0,0,0,0, # 6
0,0,0,0,0,0,0,0,0,0, # 7
0,0,0,0,0,0,0,0,0,0, # 8
0,0,0,0,0,0,0,0,0,0, # 9
0,0,0,0,0,0,0,0,0,0 # 10
),byrow=TRUE,ncol=10);
colnames(ban)<-rownames(ban)<-names(mydat); #names must be set
retain<-matrix(c(
# 1 2 3 4 5 6
0,0,0,0,0,0,0,0,0,0, # 1
0,0,0,0,0,0,0,0,0,0, # 2
0,0,0,0,0,0,0,0,0,0, # 3
0,0,0,0,0,0,0,0,0,0, # 4
0,0,0,0,0,0,0,0,0,0, # 5
0,0,0,0,0,0,0,0,0,0, # 6
0,0,0,0,0,0,0,0,0,0, # 7
0,0,0,0,0,0,0,0,0,0, # 8
0,0,0,0,0,0,0,0,0,0, # 9
0,0,0,0,0,0,0,0,0,0 # 10
),byrow=TRUE,ncol=10);
colnames(retain)<-rownames(retain)<-names(mydat); #names must be set
## not run because may take some minutes for buildscorecache()
## parent limits
max.par<-list("b1"=4,"p1"=4,"g1"=4,"b2"=4,"p2"=4,"b3"=4,"g2"=4,"b4"=4,"b5"=4,"g3"=4);
## now build cache
mycache<-buildscorecache(data.df=mydat,data.dists=mydists,
dag.banned=ban, dag.retained=retain,max.parents=max.par);
# now peform 1000 greedy searches
heur.res<-search.hillclimber(score.cache=mycache,num.searches=1000,seed=0,verbose=FALSE,
timing.on=FALSE);
# repeat but this time have the majority consensus network plotted as the searches progress
heur.res2<-search.hillclimber(score.cache=mycache,num.searches=1000,seed=0,verbose=FALSE,
trace=TRUE,timing.on=FALSE);
## for publication quality output for the consensus network use graphviz direct
tographviz(dag.m=heur.res$consensus,data.df=mydat,data.dists=mydists,outfile="graphcon.dot");
## and then process using graphviz tools e.g. on linux
system("dot -Tpdf -o graphcon.pdf graphcon.dot");
system("evince graphcon.pdf");
## note the .dot file created can be easily edited manually to provide custom shapes, colours etc.
## example 2 - glmm example - but no difference here as the format of the score cache is identical
mydat<-ex3.dag.data[,c(1:5,14)];## this data comes with abn see ?ex1.dag.data
mydists<-list(b1="binomial",
b2="binomial",
b3="binomial",
b4="binomial",
b5="binomial"
);
max.par<-3;
mycache.mixed<-buildscorecache(data.df=mydat,data.dists=mydists,group.var="group",
cor.vars=c("b1","b2","b3","b4","b5"),
max.parents=max.par, which.nodes=c(1:5));
# now peform 1000 greedy searches
heur.res<-search.hillclimber(score.cache=mycache.mixed,num.searches=1000,seed=0,verbose=FALSE,
timing.on=FALSE);
# repeat but this time have the majority consensus network plotted as the searches progress
heur.res<-search.hillclimber(score.cache=mycache.mixed,num.searches=1000,seed=0,verbose=FALSE,
trace=TRUE,timing.on=FALSE);
## for publication quality out for the consensus network may be better to use graphviz direct
tographviz(dag.m=heur.res$consensus,data.df=mydat,data.dists=mydists,group.var="group",
outfile="graphcon.dot");
## and then process using graphviz tools e.g. on linux
system("dot -Tpdf -o graphcon.pdf graphcon.dot");
system("evince graphcon.pdf");Run the code above in your browser using DataLab