"mostProbable() is backward compatible with `ex0.dag.data`"
"mostProbable() is backward compatible with `ex1.dag.data`"
# this is ok, because mp.dag is provided to 'dag=', eventhough it actually is an object.
"'data.df' is missing but must be provided"
# if mp.dag is provided as dag, even it is an object, we need data.df and data.dists.
"mostProbable() is backward compatible with `ex3.dag.data`"
"mostProbable() simple, historic numeric test"

mostProbable() is backward compatible with `ex0.dag.data`

mostProbable() is backward compatible with `ex1.dag.data`

dist <- list(a="gaussian", b="gaussian", c="gaussian", d="gaussian", e="binomial", f="multinomial")
#Plot from a formula and markov blanket for multinomial node
b <- 2 + a + rnorm(n = N, mean = 5, sd = 1)
mycache.mle <- buildScoreCache(data.df = mydf,
dag <- mostProbable(score.cache = mycache.mle, verbose = FALSE)
plt_dag <- plotAbn(dag=dag, data.dists = mydists)
data.param.adjMat <- matrix(data=c(0, 0, 1, 0), nrow=2L, byrow=TRUE, dimnames = list(NULL, c("a", "b")))
# expect_equal(plt_dag@adjMat, data.param.adjMat) # TODO: For some reason, this does not work on CRAN
dist <- list(a="gaussian", b="gaussian", c="gaussian", d="gaussian", e="binomial", f="binomial")
edge.strength <- matrix(c(0,0.5,0.5,0.7,0.1,0,   #Define a matrix formulation
colnames(edge.strength) <- rownames(edge.strength) <- names(dist)  #Naming of the matrix
test_that("Plot from a formula works", {
dag.mat <- formula_abn(f = ~a|b:c:e+b|c:d:f+e|f, name = letters[1:6])
plt <- plotAbn(dag = ~a|b:c:e+b|c:d:f+e|f, data.dist = dist, node.fillcolor.list= "e")
plt <- plotAbn(dag = ~a|b:c:e+b|c:d:f+e|f, data.dist = dist, node.fillcolor.list= "e", markov.blanket.node = "b")
plt <- plotAbn(dag = ~a|b:c:e+b|c:d:f+e|f, data.dist = dist, node.shape='diamond')
plt <- plotAbn(dag = ~a|b:c:e+b|c:d:f+e|f, data.dist = dist, node.shape=c('diamond','box'))
plt <- plotAbn(dag = ~a|b:c:e+b|c:d:f+e|f, data.dists = dist, markov.blanket.node = "e")
true_mb <- mb(dag= ~a|b:c:e+b|c:d:f+e|f, data.dists = dist, node = "e")
expect_equal(length(unique(plt_fill[true_mb])), 1) # check for one color among those nodes from true_mb
idx <- which(plt_fill %in% plt_fill[true_mb]) # get indexes from true_mb nodes
expect_false(any(names(plt_fill[-idx]) %in% true_mb)) # None of the other nodes (that are in true_mb) should be in true_mb
plt <- plotAbn(dag = ~a|b:c:e+b|c:d:f+e|f, data.dists = dist, markov.blanket.node = "c")
true_mb <- mb(dag= ~a|b:c:e+b|c:d:f+e|f, data.dists = dist, node = "c")
plt <- plotAbn(dag = ~a|b:c:e+b|c:d:f+e|f, data.dists = dist, markov.blanket.node = c("d"))
true_mb <- mb(dag= ~a|b:c:e+b|c:d:f+e|f, data.dists = dist, node = "d")
plt <- plotAbn(dag = ~a|b:c:e+b|c:d:f+e|f, data.dists = dist, markov.blanket.node = c("d","f"))
true_mb <- mb(dag= ~a|b:c:e+b|c:d:f+e|f, data.dists = dist, node = c("d","f"))
expect_equal(length(unique(plt_fill[true_mb])), 2) # check for one color among those nodes from true_mb
plt <- plotAbn(edge.strength, edge.strength=edge.strength, data.dist = dist) # TODO: think about a better test for edgestrength
expect_error(plotAbn(edge.strength, edge.strength=edge.strength, data.dist = dist,
fitted.values=vals[vals>0]), "argument is of length zero") # TODO: consider to make this error more meaningful.
expect_error(plotAbn(tmp, edge.strength=-edge.strength-4, data.dist = dist),
expect_no_error(plotAbn(tmp, edge.strength=edge.strength, data.dist = dist)) # zeros allowd
expect_error(plotAbn(edge.strength, edge.strength=tmp, data.dist = dist),"'edge.strength' does not match dag")
skip("Plot classic view is deprecated.")
tmp <- plotAbn(dag = edge.strength, edge.strength=edge.strength, data.dist = dist)
slot(tmp, "renderInfo", check=FALSE) <- NULL
mydists <- list(b1="binomial", b2="binomial", b3="binomial", g1="gaussian",
mydag.empty <- matrix(0, nrow=7, ncol=7)
colnames(mydag.empty) <- rownames(mydag.empty) <- names(mydat)
myres <- fitAbn(dag = ~b1|b2+b2|p4+g1+g1|p2+b3|g1+b4|b1+p4|g1, data.df = mydat, data.dists = mydists)
g <- plotAbn(myres$abnDag$dag, fitted.values = myres$modes, data.dists = mydists, edge.direction = 'pc')
expect_false(any(unique(g@renderInfo@edges$label) %in% c(" "))) # TODO: consider to relax to only some edges have labels.
myres <- fitAbn(dag = ~b1|b2+b2|p4+g1+g1|p2+b3|g1+b4|b1:g1+p4|g1:b3:p2, data.df = mydat, data.dists = mydists)
g <- plotAbn(myres$abnDag$dag, fitted.values = myres$modes, data.dists = mydists, edge.direction = 'pc') # TODO: Think about more specific test
mydists1 <- list(m1="multinomial", b3="binomial", g1="gaussian",
myres1 <- fitAbn(dag = ~m1|b3:g1:b4+b3|p2:p4+p2|p4, data.df = mydat1, data.dists = mydists1, method='mle')
expect_no_error(plotAbn(dag = ~m1|b3:g1:b4+b3|p2:p4+p2|p4, data.dist=mydists1, node.shape=rep('box',4)))