Created
April 5, 2012 12:34
-
-
Save tdhopper/2310747 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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