# NOT RUN {
#################################################################
## Example 1
#################################################################
mydat <- ex0.dag.data[,c("b1","b2","g1","g2","b3","g3")] ## take a subset of cols
## setup distribution list for each node
mydists <- list(b1="binomial", b2="binomial", g1="gaussian",
g2="gaussian", b3="binomial", g3="gaussian")
# Structural constrains
# ban arc from b2 to b1
# always retain arc from g2 to g1
## parent limits
max.par <- list("b1"=2, "b2"=2, "g1"=2, "g2"=2, "b3"=2, "g3"=2)
## now build cache accordingly to the structural constrains
res.c <- buildscorecache(data.df=mydat, data.dists=mydists,
dag.banned= ~b1|b2, dag.retained= ~g1|g2, max.parents=max.par)
## repeat but using R-INLA. The mlik's should be virtually identical.
## now build cache
res.inla <- buildscorecache(data.df=mydat, data.dists=mydists,
dag.banned= ~b1|b2, dag.retained= ~g1|g2, max.parents=max.par,
max.mode.error=100)
## plot comparison - very similar
plot(res.c$mlik, res.inla$mlik, pch="+")
abline(0, 1)
#################################################################
## Example 2 - much bigger problem using glm - may take a while
#################################################################
mydat <- ex2.dag.data ## this data comes with abn see ?ex2.dag.data
## setup distribution list for each node
mydists <- list(b1="binomial", g1="gaussian", p1="poisson",
b2="binomial", g2="gaussian", p2="poisson",
b3="binomial", g3="gaussian", p3="poisson",
b4="binomial", g4="gaussian", p4="poisson",
b5="binomial", g5="gaussian", p5="poisson",
b6="binomial", g6="gaussian", p6="poisson")
## no explicit ban or retain restrictions set so dont need to supply ban
## or retain matrices
## now build cache using internal code just for nodes 1,2 and 3
## e.g. "b1", "p1" and "g1"
mycache.c <- buildscorecache(data.df=mydat, data.dists=mydists,
max.parents=2, which.nodes=c(1:3))
###################################################################
## Example 3 - grouped data - random effects example e.g. glmm
###################################################################
mydat <- ex3.dag.data ## this data comes with abn see ?ex3.dag.data
mydists <- list(b1="binomial", b2="binomial", b3="binomial",
b4="binomial", b5="binomial", b6="binomial", b7="binomial",
b8="binomial", b9="binomial", b10="binomial",b11="binomial",
b12="binomial", b13="binomial" )
max.par <- 2
## in this example INLA is used as default since these are glmm nodes
## when running this at node-parent combination 71 the default accuracy check on the
## INLA modes is exceeded (default is a max. of 10 percent difference from
## modes estimated using internal code) and a message is given that internal code
## will be used in place of INLA's results.
mycache <- buildscorecache(data.df=mydat, data.dists=mydists, group.var="group",
cor.vars=c("b1","b2","b3","b4","b5","b6","b7",
"b8","b9","b10","b11","b12","b13"),
max.parents=max.par, which.nodes=c(1))
# }
# NOT RUN {
mydat <- ex0.dag.data[,c("b1","b2","g1","g2","b3","g3")] ## take a subset of cols
## setup distribution list for each node
mydists <- list(b1="binomial", b2="binomial", g1="gaussian",
g2="gaussian", b3="binomial", g3="gaussian")
## now build cache of scores (goodness of fits for each node)
res.mle <- buildscorecache(data.df=mydat, data.dists=mydists,
max.parents=3, method="mle")
res.abn <- buildscorecache(data.df=mydat, data.dists=mydists,
max.parents=3, method="Bayes")
#plot(-res.mle$bic, res.abn$mlik)
# }
Run the code above in your browser using DataLab