Formula checking error
Closed this issue · 4 comments
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
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.
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
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
net <- setNode(network = net, node = pregnant,+ death | pe*treat)
net <- setNode(net, wells,nodeType = "dbern", p=.4)
nodeType = "dnorm",
VP <- vectorProbs(p = c(.3, .6, .1), wells)mu = 5, tau = 1 / (1.5^2))
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
writeNetworkModel(net, pretty=TRUE)nodeFormula = d.dimer ~ 210 + 29_pregnant + 68_pe)
Error in formula.default(object, env = baseenv()) : invalid formula
—
Reply to this email directly or view it on GitHub.
Found it. It was an indexing error. I was using [
instead of [[
.