1

I'm quite green regarding bayesian networks and bnlearn. I apologize in advance.

I'm working on a database given by my PhD supervisor. When I'm exporting it from spss I get a different network to that exported from csv. Is this usual? It's the same data... The difference is in the inbetween step of transforming it from .sav to .csv through spss...

The major problem is that when I'm using the .sav exported data, somehow I keep getting this error message that my variables aren't discrete (they've been recoded into categorical variables, so I don't get where this comes from). Hence, they can't be used in samIam.

This is the error: "Error in write.net(rehosp.hc.fit, file = "rehosp.hc.learned.net") : only discrete Bayesian networks can be exported into DSC format."

And here goes the code:

require (bnlearn)
library(haven)
path <- file.path("C:/.../path_to_file/...", "database.sav")
rehosp.data <- read_sav(path)
print(str(rehosp.data))
rehosp.hc.net <- hc(rehosp.data, debug=TRUE)
plot(rehosp.hc.net)
rehosp.hc.fit <- bn.fit(rehosp.hc.net, rehosp.data)
write.net(rehosp.hc.fit, file="filename")

Could use some guidance.

Thanks!

msap
  • 11
  • 2
  • It will probably be helpful if you can copy the whole error message into your question – OriolAbril May 19 '18 at 00:40
  • Thanks. Just posted it. – msap May 19 '18 at 09:27
  • Hi, msap. I find your question a little unclear, particularly *exported from csv*. Can you describe the steps you are doing please. Is it correct that your data is in a spss file, and you are trying to get that read in to R, to use bnlearn? or? thanks – user20650 May 19 '18 at 12:34
  • That's exactly right. My data is in a spss file. When I import it to R to use bnlearn, I get a different network from when importing it in a .csv file. I used spss to export it to csv. Besides, when using the .sav file I get that error. – msap May 19 '18 at 15:31
  • Hi, msap, thanks for the update. The fact that you get different nets, will be due to some variables being read in as discrete, and some as continuous, depending on if you use cvs or sav (Try and compare the structures from each read in method.). Even if a variable is binary (0/1) you need to change this to a factor or else bnlearn will treat it as continuous (a Gaussian node). The error from write.net suggests the data is continuous or mixed, but if you know they should all be discrete you need to explicitly convert the variables to factors... – user20650 May 19 '18 at 21:30
  • ... can you edit your question with the results of `str(rehosp.data)` please. – user20650 May 19 '18 at 21:31

0 Answers0