Learn R Programming

gRain (version 1.3-0)

repeatPattern: Create repeated patterns in Bayesian networks

Description

Repeated patterns is a useful model specification short cut for Bayesian networks

Usage

repeatPattern(plist, instances, unlist = TRUE)

Arguments

plist

A list of conditional probability tables. The variable names must have the form name[i] and the i will be substituted by the values given in instances below.

instances

A vector of distinct integers

unlist

If FALSE the result is a list in which each element is a copy of plist in which name[i] are substituted. If TRUE the result is the result of applying unlist().

References

S<U+00F8>ren H<U+00F8>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/.

See Also

grain, compileCPT

Examples

Run this code
# NOT RUN {
## Specify hidden markov models. 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,1), levels=yn)

## Specify transition density
x.x <- cptable(~x[i]|x[i-1], values=c(1,99,2,98),levels=yn)

## Specify emissiob density
y.x <- cptable(~y[i]|x[i],   values=c(1,99,2,98),levels=yn)

## The pattern to be repeated
pp <- list(x.x, y.x)

## Repeat pattern and create network
ppp <- repeatPattern(pp, instances=1:10)
qqq <- compileCPT(c(list(x.0),ppp))
rrr <- grain(qqq)



# }

Run the code above in your browser using DataLab