nutterb / HydeNet

Hybrid Decision Networks in R
Other
23 stars 3 forks source link

writeJagsModel(); writeJagsFormula.XXXX() #8

Closed jdutch27 closed 9 years ago

jdutch27 commented 9 years ago

These functions seem to be buggy.

g <- glm(treat ~ d.dimer*angio, data=PE, family="binomial") writeJagsFormula(g) Error: could not find function "writeJagsFormula" Hyde::writeJagsFormula(g) Error: 'writeJagsFormula' is not an exported object from 'namespace:Hyde' Hyde::writeJagsFormula.glm(g) [1] "treat ~ 1/(1 + exp(-6.28559524027548))"

I think just a little bit of work on the methods is what is needed? The function works when you explicitly tell it you have a glm object.

nutterb commented 9 years ago

We'll need to discuss this. I did not intend for these to be called by the user, so they work seamlessly when called within Hyde, but not so well in the Global Environment.

The following produces what you are looking for

g <- glm(treat ~ d.dimer*angio, data=PE, family="binomial")
Hyde:::writeJagsFormula(g)

But the intended behavior would be

setNode(net, treat, 
        nodeFitter='glm',
        fitterArgs = list(family='binomial'),
        p = fromFormula())

After the node is properly defined, writeNetworkModel will call writejagsFormula if it is needed and it will all be handled internally.

If you want, we can export these functions and make them available to the user, but I am not sure of the value of doing so (so you'll have to persuade me).

nutterb commented 9 years ago

These two statements are equivalent

equation <- "-6.3 + 0.02*d.dimer + 2.9*angio - 0.005*d.dimer*angio"
net <- setNode(net, treat, nodeType="dbern",
               p=paste("ilogit(", equation, ")"), 
               validate=FALSE)
equation <- "-6.3 + 0.02*d.dimer + 2.9*angio - 0.005*d.dimer*angio"
net <- setNode(net, treat, nodeType="dbern",
              nodeFormula=treat ~ ilogit(-6.3 + 0.02*d.dimer + 2.9*angio - 0.005*d.dimer*angio),
              p=fromFormula())