Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Making setNode() and modelToNode() play together #20

Closed
jdutch27 opened this issue Mar 2, 2015 · 3 comments
Closed

Making setNode() and modelToNode() play together #20

jdutch27 opened this issue Mar 2, 2015 · 3 comments

Comments

@jdutch27
Copy link
Collaborator

jdutch27 commented Mar 2, 2015

HydeNetwork.list() is awesome.

It would be equally beneficial to be able to apply modelToNode() for individual nodes. I think this is as simple as making a network object argument to the modelToNode methods (set to NULL). By default the function will work as-is, i.e., as called from HydeNetwork.list(). But if the user feeds a network object to the method, it will:

  1. check that indeed the argument is of class 'HydeNetwork'
  2. check that the name of the response variable in the 'model' argument is actually the name of a node in the network
  3. check all.equal(sort(unique(names_of_variables_in_regression_equation))), sort(unique(names_of_parents_in_network_object)))
  4. set all the list elements for that node within the HydeNetwork object and return an updated object.

Thoughts on its usefulness?

@nutterb
Copy link
Owner

nutterb commented Mar 2, 2015

Rather than putting this into setNode, I wrote setNodeModels. This will accept one or more model objects and apply the settings to the appropriate nodes in one pass.

As discussed in issue #7, setNode is pretty inflexibly written to deal with one node at a time, and to extend it to take a single model object and work properly is probably a fairly sizable headache. This is probably a smoother approach.

@nutterb nutterb closed this as completed Mar 2, 2015
@jdutch27 jdutch27 reopened this Apr 3, 2015
@jdutch27
Copy link
Collaborator Author

jdutch27 commented Apr 3, 2015

There is an issue with (I think) modelToNode(). The output of writeNetworkModel in my "bag of models" example seems to be incorrect. All of the distributions in the JAGS code have " ~ " in the parameters. For example, the second "wells ~" should not be in the following expression: "wells ~ dnorm(wells ~ 3.79, 0.63)"

g1 <- lm(wells ~ 1, data=PE)
g2 <- glm(pe ~ wells, data=PE, family="binomial")
g3 <- lm(d.dimer ~ pe + pregnant, data=PE)
g4 <- xtabs(~ pregnant, data=PE)
g5 <- glm(angio ~ pe, data=PE, family="binomial")
g6 <- glm(treat ~ d.dimer + angio, data=PE, family="binomial")
g7 <- glm(death ~ pe + treat, data=PE, family="binomial")

bagOfModels <- list(g1,g2,g3,g4,g5,g6,g7)

bagNet <- HydeNetwork(bagOfModels)
writeNetworkModel(bagNet, pretty=TRUE)

model{

wells ~ dnorm(wells ~ 3.7941999999999, 0.630504251834359)

pe ~ dbern(pe ~ ilogit(-3.90355 + 0.5757*wells))

d.dimer ~ dnorm(d.dimer ~ 210.24251 + 68.37938_(pe==2) + 29.29496_(pregnant==2), 0.0334725036145318)

pi.pregnant[1] <- 0.9014; pi.pregnant[2] <- 0.0986

pregnant ~ dcat(pi.pregnant)

angio ~ dbern(angio ~ ilogit(-2.22585 + 3.28411*(pe==2)))

treat ~ dbern(treat ~ ilogit(-5.89316 + 0.01994_d.dimer + 1.73354_(angio==2)))

death ~ dbern(death ~ ilogit(-4.18763 + 5.48082_(pe==2) + -1.93576_(treat==2)))

}

@nutterb
Copy link
Owner

nutterb commented Apr 24, 2015

This has been resolved.

@nutterb nutterb closed this as completed Apr 24, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants