nutterb / HydeNet

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

Passing multiple model objects to setNode (+ Issue #6) #7

Closed jdutch27 closed 9 years ago

jdutch27 commented 9 years ago

In Issue #6 (get node distn from model object) I assumed only a single model object.

Maybe the modelObjects parameter should be a list of model objects instead of a single model object.

Here's what I think the user should be able to do.

mod.pe <- glm(pe ~ wells, family="binomial", data=d1) mod.d.dimer <- lm(d.dimer ~ pregnant_pe, data=d2) mod.angio <- glm(angio ~ pe, family="binomial", data=d1) mod.treat <- glm(treat~ d.dimer_angio, family="binomial", data=d3) mod.death <- glm(death ~ pe*treat, family="binomial", data=d2)

my.models <- list(mod.pe, mod.d.dimer, mod.angio, mod.treat, mod.death)

net <- HydeNetwork(~ wells

net <- setNode(net, modelObjects = my.models) net <- setNode(net, wells, "dnorm", mu=5, tau=1/(1.5^2)) net <- setNode(net, pregnant, "dbern", p=0.10)

**Even better:

my.models <- c(my.models, lm(wells ~ 1, data=d2), glm(pregnant ~ 1, family="binomial", data=d1)) net <- HydeNetwork(modelObjects = my.models)

nutterb commented 9 years ago

I think I might be more comfortable with this as a separate function. setNode is very clearly structured for dealing with a single node, a decision I made because I assumed most users would work with one node at a time.

This proposal seems like the user is providing the information as several nodes at once. It's a great idea, and can be done, but I might suggest something more like

net <- setNodeModels(lm(wells ~ 1, data=d2),
    glm(pregnant ~ 1, family=binomial, data=d1))

This may require an additional element for each node, if we are going to accept the possibility of differing data objects for each model. But if net$nodeData$[node_name] = NULL, it could then look to net$data.

nutterb commented 9 years ago

Agreed to have separate functions.

jdutch27 commented 9 years ago

See Issue #20 .

We may consider doing the above but for single nodes, using an adaptation of modelToNode().

nutterb commented 9 years ago

setNodeModels is now included.