Code Monkey home page Code Monkey logo

Comments (5)

nutterb avatar nutterb commented on August 17, 2024

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.

jdutch27 avatar jdutch27 commented on August 17, 2024

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.

jdutch27 avatar jdutch27 commented on August 17, 2024

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.

nutterb avatar nutterb commented on August 17, 2024

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.

jdutch27 avatar jdutch27 commented on August 17, 2024

This is fun. I like your model. This should definitely be in the docs!

from hydenet.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.