nutterb / HydeNet

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

Formula checking error #86

Closed jarrod-dalton closed 8 years ago

jarrod-dalton commented 8 years ago

Re-running the example in the Working with HydeNet Objects vignette, I get an error with writeNetworkModel():

net <- HydeNetwork(~ wells
                   + pe | wells
                   + d.dimer | pregnant*pe
                   + angio | pe
                   + treat | d.dimer*angio
                   + death | pe*treat)

net <- setNode(net, d.dimer, nodeType="dnorm",
               mu=fromFormula(), tau=1/30,  #sigma^2 = 30
               nodeFormula = d.dimer ~ 210 + 29*pregnant + 68*pe)
net
writeNetworkModel(net, pretty=TRUE)
Error in formula.default(object, env = baseenv()) : invalid formula
nutterb commented 8 years ago

I would expect this would cast an error. When you look at the printed output of net, most of the parameters are "Unspecified," probably because there is no data attached to the network. Are you by chance running the code in interactive mode? Keep in mind that many of the code chunks in that vignette are tagged with the option eval = FALSE.

All that said, perhaps this could use a better error message.

jarrod-dalton commented 8 years ago

Hmmm. I don't think that's it. When I specify some root nodes via either JAGS code or directly setting distribution parameters, writeNetworkModel() seems to be happy (even despite some nodes remaining unspecified).

> net <- HydeNetwork(~ wells
+                    + pe | wells
+                    + d.dimer | pregnant*pe
+                    + angio | pe
+                    + treat | d.dimer*angio
+                    + death | pe*treat)
> net <- setNode(network = net, node = pregnant,
+                nodeType = "dbern", p=.4)
> net <- setNode(net, wells,
+                nodeType = "dnorm", 
+                mu = 5, tau = 1 / (1.5^2))
> VP  <- vectorProbs(p = c(.3, .6, .1), wells)
> net <- setNode(net, wells, nodeType = "dcat", pi = VP)
setNode(net, wells, nodeType = "dcat", pi = VP)
1: Validation has been ignored for parameters defined with character strings
> writeNetworkModel(net, pretty=TRUE)
model{
   pi.wells[1] <- 0.3; pi.wells[2] <- 0.6; pi.wells[3] <- 0.1
wells ~ dcat(pi.wells)
   pe ~ dnorm(Unspecified, Unspecified)
   d.dimer ~ dnorm(Unspecified, Unspecified)
   pregnant ~ dbern(0.4)
   angio ~ dnorm(Unspecified, Unspecified)
   treat ~ dnorm(Unspecified, Unspecified)
   death ~ dnorm(Unspecified, Unspecified)
}

Something is off in the processing of the nodeFormula argument in the setNode call for d.dimer:

> net <- setNode(net, d.dimer, nodeType="dnorm",
+                mu=fromFormula(), tau=1/30,  #sigma^2 = 30
+                nodeFormula = d.dimer ~ 210 + 29*pregnant + 68*pe)
> writeNetworkModel(net, pretty=TRUE)
Error in formula.default(object, env = baseenv()) : invalid formula
nutterb commented 8 years ago

We generate JAGS code for unspecified models? I didn't remember that. I'll take a further look tonight when I get home. Benjamin

Sent via the Samsung GALAXY S® 5, an AT&T 4G LTE smartphone

-------- Original message -------- From: jarrod-dalton notifications@github.com Date: 08/25/2015 07:15 (GMT-05:00) To: nutterb/HydeNet HydeNet@noreply.github.com Cc: Benjamin benjamin.nutter@gmail.com Subject: Re: [HydeNet] Formula checking error (#86)

Hmmm. I don't think that's it. When I specify some root nodes via either JAGS code or directly setting distribution parameters, writeNetworkModel() seems to be happy (even despite some nodes remaining unspecified).

net <- HydeNetwork(~ wells

    • pe | wells
    • d.dimer | pregnant*pe
    • angio | pe
    • treat | d.dimer*angio
    • death | pe*treat) net <- setNode(network = net, node = pregnant,
  • nodeType = "dbern", p=.4) net <- setNode(net, wells,
  • nodeType = "dnorm",
  • mu = 5, tau = 1 / (1.5^2)) VP <- vectorProbs(p = c(.3, .6, .1), wells) net <- setNode(net, wells, nodeType = "dcat", pi = VP)

setNode(net, wells, nodeType = "dcat", pi = VP) 1: Validation has been ignored for parameters defined with character strings

writeNetworkModel(net, pretty=TRUE)

model{ pi.wells[1] <- 0.3; pi.wells[2] <- 0.6; pi.wells[3] <- 0.1 wells ~ dcat(pi.wells) pe ~ dnorm(Unspecified, Unspecified) d.dimer ~ dnorm(Unspecified, Unspecified) pregnant ~ dbern(0.4) angio ~ dnorm(Unspecified, Unspecified) treat ~ dnorm(Unspecified, Unspecified) death ~ dnorm(Unspecified, Unspecified) }

Something is off in the processing of the nodeFormula argument in the setNode call for d.dimer:

net <- setNode(net, d.dimer, nodeType="dnorm",

  • mu=fromFormula(), tau=1/30, #sigma^2 = 30
  • nodeFormula = d.dimer ~ 210 + 29_pregnant + 68_pe) writeNetworkModel(net, pretty=TRUE)

Error in formula.default(object, env = baseenv()) : invalid formula

— Reply to this email directly or view it on GitHub.

nutterb commented 8 years ago

Found it. It was an indexing error. I was using [ instead of [[.