dariomasante / bnspatial

An R package for the spatial implementation of Bayesian Network in R and more
GNU Lesser General Public License v3.0
26 stars 6 forks source link

mapping the results of a bayesian decision network #4

Closed e3cleary closed 4 years ago

e3cleary commented 7 years ago

Can anyone help me with some information on how to generate a predictive risk map based on the results of a bayesian network generated in R using bnlearn? BN spatial requires a .net bn file so I can't use that. I've also tried spatial.ly and ggplot but can't get them to work either. I'm fairly new to R so I'm still trying to get my head around a lot of the coding/packages. My Bayesian network is a directed graph related to a binary outcome variable, with discretised explanatory variable, the format of which are both vector and raster data. I have tried generating a map from a model using raster files only but am still running into problems. Any help would be most appreciated.

dariomasante commented 7 years ago

You can actually use a network generated with bnlearn easily. Look at ?loadNetwork

Bayesian networks from the package bnlearn can be imported via the function as.grain, from package bnlearn.

So basically you must convert your bnlearn network into an object of class grain beforehand, then you can use that directly in bnspatial. I may amend loadNetwork function in the near future, to avoid this additional step. In the help I attributed wrongly the function as.grain to the package gRain, while it belongs to bnlearn package! The loadNetwork function is wrapped into main function bnspatial, so you can feed the latter with the grain BN directly.

e3cleary commented 7 years ago

Hi. Thank you for your reply. Great! I'll try that and see if I can get it to work.

Rioshi commented 7 years ago

Hello, is it possible use a bayesian network generated in other package...ejm

Rioshi commented 7 years ago

HydeNet ?

dariomasante commented 7 years ago

Hi, only supported BN objects are those of class grain (from gRain package) so far. You can convert BN from bnlearn package with its as.grain function as well. The only other format supported is .net, which can be created outside R using either GeNIe, Hugin or possibly Netica. With a bit of patience, one could write a function to build a grain network from a HydeNet network though. Decision and utility nodes are not supported as such, but workarounds for both are possible (at least in the context relevant to bnspatial).

Rioshi commented 7 years ago

tnks (Y)

e3cleary commented 6 years ago

Hi,

I'm using bnspatial to generate a predictive risk map based on the results of a Bayesian network model. At the moment, for a model with three explanatory variables directly connected to the outcome variable, but not to each other, I'm able to plot a map using the command plot(bn$Entropy) no problem. However, when I connect two of the explanatory variables to each other as well as to the outcome variable, I'm getting this error message: Error in sort.list(y) : 'x' must be atomic for 'sort.list' Have you called 'sort' on a list? Does anyone have any idea why this might be and how I can fix it? Thanks.

dariomasante commented 6 years ago

It's hard to solve the problem without a reproducible example, please provide one. For what I understand you're trying to connect two nodes to each other and this is not allowed (bayesian networks are also known as Directed acyclic graph for this specific reason) even though for some reasons you can draw the links. In any case, I suggest first to update the package to the latest version and check again (some bugs were amended in it) then provide an example.

dariomasante commented 6 years ago

As the warning suggests, there is a mismatch between the definition of class boundaries and the actual values you have. This is allowed though, just a warning.

2017-12-06 13:33 GMT+01:00 e3cleary notifications@github.com:

Also getting this error message when I add in one extra explanatory variable to the network, again all explanatory variables only connected to the outcome variable.

Warning message: In .makeClassBoundaries(data = data, classBoundaries = classBoundaries, : One or more classes fall entirely out of data range. Check "classBoundaries".

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/dariomasante/bnspatial/issues/4#issuecomment-349626106, or mute the thread https://github.com/notifications/unsubscribe-auth/AQqkzYvMyKPoWonh36Mxi2BsXwBXeCPVks5s9omBgaJpZM4N6t7z .

crojas76 commented 2 years ago

Hello, When i try to run the example of bnspatial package. It shows this message. Read 9 items Error in value[3L] :
File not found!

Can you help please help me with this?

dariomasante commented 2 years ago

Hello, When i try to run the example of bnspatial package. It shows this message. Read 9 items Error in value[3L] : File not found!

Can you help please help me with this? Hi, what example, exactly, are you trying to run? Please clarify