Hello fellow bnlearn users.
I am trying to fit a bayesian networt of just 3 variables, but R throws an error message. I sadly don't understand why, as I'm a still a beginner. I took the time to make a simple reproducible example of the problem I experience. (The dataframe I work with has obviously more variables and rows, but I think I cornered the key problem in my dummy set.)
the code:
library(bnlearn)
#Creation of the dummy set
Learning.set3=matrix(0,5,3)
Learning.set3[,c(1)]=c(3,5,1,8,10)
Learning.set3[,c(2)]=c(2,6,4,9,8)
Learning.set3[,c(3)]=c(0,0,0,1,1)
Learning.set3=as.data.frame(Learning.set3)
Learning.set3[,c(3)]=as.factor(Learning.set3[,c(3)])
colnames(Learning.set3)=c("Cont1","Cont2","Fac1")
#Making an empty network with the data
b.network=empty.graph(colnames(Learning.set3[1:ncol(Learning.set3)]))
#Structure matrix
struct.mat=matrix(0,length(colnames(Learning.set3)),length(colnames(Learning.set3)))
colnames(struct.mat)[1:3]=colnames(Learning.set3)[1:ncol(Learning.set3)]
rownames(struct.mat)=colnames(struct.mat)
struct.mat[1,2:nrow(struct.mat)]=1
bnlearn::amat(b.network)=struct.mat
#Fitting
haha2=bn.fit(b.network,Learning.set3[,c(1:ncol(Learning.set3))])Here's the error it throws: Error in check.arcs.against.assumptions(bn$arcs, data, "mi-cg") : arc Cont1 -> Fac1 violates the assumptions of the model.
So for some reason, I'm unable to create a link from a continuous variable to the categorical one. Does anyone know the reason behind this?
I have no trouble creating links from a categorical to a continuous variable
BR