Comments (5)
Here's another example, one in which I'm thinking about putting into the vignette. It models the first roll in a craps game. If you roll a 2, 3, or 12, you lose. If you roll a 7 or 11, you win. Anything else and the "point" gets set and the "shooter" (the person rolling the dice) rolls again.
craps <- hydeNetwork(~ d1 + d2 + outcome | d1*d2)
craps <- setNode(craps, d1, nodeType="dcat", pi = vectorProbs(p = rep(1/6,6), d1))
craps <- setNode(craps, d2, nodeType="dcat", pi = vectorProbs(p = rep(1/6,6), d2))
craps <- setNode(craps, outcome, ????????????)
craps
from hydenet.
Here's another wrinkle:
g <- hydeNetwork(~ disease | comorbidityScore
+ test1 | disease
+ test2 | disease
+ surgery | test1*test2*insurance
+ surgicalComp | comorbidityScore*disease*surgery
+ death | disease*treatment*surgicalComp)
Everything gets populated in the usual way except for node 'surgicalComp'. This is a sort of combined logical & random node. If treatment == 0 then surgicalComp = 0. If treatment == 1, then surgicalComp ~ some kind of logistic regression function of comorbidityScore.
from hydenet.
I think I may have thought of a solution to this by adding an extra "hypothetical" node. Not ideal, but at least it drives this feature down the priority list:
g <- hydeNetwork(~ disease | comorbidityScore
+ test1 | disease
+ test2 | disease
+ surgery | test1*test2*insurance #stochastic Bernoulli
+ hypotheticalSurgicalComp | comorbidityScore #stochastic Bernoulli (based on logistic reg.)
+ surgicalComp | surgery*hypotheticalSurgicalComp #deterministic node
+ death | disease*treatment*surgicalComp)
Node hypotheticalSurgicalComp models hypothetical outcome (0 or 1)
If surgery was actually performed (surgery==1), then surgicalComp is equal to node hypotheticalSurgicalComp; otherwise, surgicalComp = 0.
from hydenet.
I used the craps example to make sure that the practical implementation could work. I'll work out an example with the PE data that might be more useful (and use fewer determ
nodes). In doing so, I may start another vignette that focuses on the conditional logic node.
#* Define the probability distributions for rolling two dice
rolls <- expand.grid(r1 = 1:6,
r2 = 1:6)
rolls$d1 <- with(rolls, r1 + r2)
rolls$d2 <- with(rolls, r1 + r2)
#* Define the network
craps <- HydeNetwork(~ d1 +
roll_again | d1 +
d2 | roll_again +
eval_roll | d2 * roll_again +
result | eval_roll)
plot(craps)
craps <- setNode(craps, d1, "dcat",
pi=writeJagsFormula(xtabs(~ d1, data=rolls)))
craps <- setNode(craps, d2, "dcat",
pi=writeJagsFormula(xtabs(~ d2, data=rolls)))
craps <- setNode(craps, roll_again, "determ",
define = "ifelse(d1 == 2 || d1 == 3 || d1 == 7 || d1 == 11 || d1 == 12, 0, 1)",
validate=FALSE)
craps <- setNode(craps, eval_roll, "determ",
define = "ifelse(roll_again == 0, d1, d2)",
validate=FALSE)
craps <- setNode(craps, result, "determ",
define = "ifelse(eval_roll == 7 || eval_roll == 11, 1, 0)",
validate=FALSE)
compiledCraps <- compileJagsModel(craps)
codaCraps <- coda.samples(compiledCraps$jags,
craps$nodes,
n.iter=1000)
#* Probability of winning if we observe a 6 on the first roll
compiledCraps <- compileJagsModel(craps, data=list(d1=6))
codaCraps <- coda.samples(compiledCraps$jags,
"result",
n.iter=1000)
from hydenet.
This is fun. I like your model. This should definitely be in the docs!
from hydenet.
Related Issues (20)
- Change JAGS parameter names to R parameter names HOT 2
- Change HydePosterior to HydeSim
- Update documentation in `setNode`
- setNode dbern bug HOT 4
- Error when data is tibble HOT 3
- Inaccurate HydeSim() predictions with discrete nodes
- Truncated normal distribution HOT 1
- `setNode` doesn't have a `nodeData` argument.
- `bindPosterior` should retain an index for chain number HOT 4
- Store network images in vignettes as PNGs HOT 5
- Formula checking error HOT 4
- [!] logit() and the VGAM package HOT 4
- Stan Integration
- ArgumentCheck error in setNode() HOT 1
- Changing graph layout
- Adding observed nodes to compileDecisionModel() HOT 3
- Changes in upcoming v0.8 release of `DiagrammeR` package will require changes in `plot.HydeNetwork` HOT 3
- Relaxing some decision/utility node constraints HOT 6
- policyMatrixValues() returns null HOT 1
- Categorical interactions are not handled correctly
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hydenet.