Skip to content

Instantly share code, notes, and snippets.

@tdhopper
Created April 5, 2012 12:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tdhopper/2310747 to your computer and use it in GitHub Desktop.
Save tdhopper/2310747 to your computer and use it in GitHub Desktop.
#install.packages("catnet",71)
library(catnet)
## Build network
cnet <- cnNew(nodes = c("S", "L", "F", "T", "C"), cats = list(c("winter", "spring", "summer","fall"),
c("NA","SA"), c("salmon","bass"), c("wide","thin"), c("light","medium","dark")),
parents = list(NULL, NULL, c(1,2),c(3),c(3)), probs =
list(
c(.1,.2,.5,.2),
c(0.6, 0.4),
list(list(c(0.5,0.5),c(0.7,0.3)),list(c(0.6,0.4),c(0.8,0.2)),list(c(0.4,0.6),c(0.1,0.9)),list(c(0.2,0.8),c(0.3,0.7))),
list(c(0.3,0.7),c(0.6,0.4)),
list(c(0.6,0.2,0.2),c(0.2,0.3,0.5))
)
)
## Distributions
cnProb(cnet)
## Marginal Distribution for type of fish
cnNodeMarginalProb(cnet, node=3)
## Marginal Distribution for thickness
cnNodeMarginalProb(cnet, node=4)
##
cnNodeMarginalProb(cnet, node=5)
## Posterior probability distribution of the season given L=NA and C=dark?
cnCondProb(cnet, x=c("S"="winter"), y=c("L"="NA","C"="dark"))
cnCondProb(cnet, x=c("S"="spring"), y=c("L"="NA","C"="dark"))
cnCondProb(cnet, x=c("S"="summer"), y=c("L"="NA","C"="dark"))
cnCondProb(cnet, x=c("S"="fall"), y=c("L"="NA","C"="dark"))
cnCondProb(cnet, x=c("S"="winter"), y=c("C"="dark"))
cnCondProb(cnet, x=c("S"="spring"), y=c("C"="dark"))
cnCondProb(cnet, x=c("S"="summer"), y=c("C"="dark"))
cnCondProb(cnet, x=c("S"="fall"), y=c("C"="dark"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment