Description Usage Arguments Author(s) References See Also Examples
View source: R/repeat_pattern.R
Repeated patterns is a useful model specification short cut for Bayesian networks
1 | repeatPattern(plist, instances, unlist = TRUE)
|
plist |
A list of conditional probability tables. The variable
names must have the form |
instances |
A vector of distinct integers |
unlist |
If |
Søren Højsgaard, sorenh@math.aau.dk
Søren Højsgaard (2012). Graphical Independence Networks with the gRain Package for R. Journal of Statistical Software, 46(10), 1-26. http://www.jstatsoft.org/v46/i10/.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | ## Example: Markov chain
yn <- c("yes", "no")
## Specify p(x0)
x.0 <- cptable(~x0, values=c(1, 9), levels=yn)
## Specify transition density
x.x <- cptable(~x[i]|x[i-1], values=c(1, 99, 2, 98), levels=yn)
## Pattern to be repeated
pat <- list(x.x)
rep.pat <- repeatPattern(pat, instances=1:5)
cpt <- compileCPT(c(list(x.0), rep.pat))
mc <- grain(cpt)
if (interactive()) iplot(mc)
## Example: Hidden markov model: The x[i]'s are unobserved, the
## y[i]'s can be observed.
yn <- c("yes", "no")
## Specify p(x0)
x.0 <- cptable(~x0, values=c(1, 9), levels=yn)
## Specify transition density
x.x <- cptable(~x[i]|x[i-1], values=c(1, 99, 2, 98), levels=yn)
## Specify emission density
y.x <- cptable(~y[i]|x[i], values=c(10, 90, 20, 80), levels=yn)
## The pattern to be repeated
pat <- list(x.x, y.x)
## Repeat pattern and create network
rep.pat <- repeatPattern(pat, instances=1:5)
cpt <- compileCPT(c(list(x.0), rep.pat))
hmm <- grain(cpt)
hmm
if (interactive()) iplot(hmm)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.