View source: R/cptable_create.R
cpt | R Documentation |
Creates conditional probability tables of the form p(v|pa(v)).
cpt(names, levels, values, normalize = "first", smooth = 0)
cptable(vpar, levels = NULL, values = NULL, normalize = TRUE, smooth = 0)
names |
Specifications of the names in P(v|pa1,...pak). See section 'details' for information about the form of the argument. |
levels |
|
values |
Probabilities; recycled if necessary. Regarding the order, please see section 'details' and the examples. |
normalize |
See 'details' below. |
smooth |
Should values be smoothed, see 'Details' below. |
vpar |
node an its parents |
cptable
is simply a wrapper for cpt
and the functions can hence
be used synonymously.
If smooth
is non–zero, then this value is added to all cells before
normalization takes place.
Regarding the form of the argument names
: To specify
P(a|b,c)
one may write ~a|b:c
, ~a:b:c
,
~a|b+c
, ~a+b+c
or c("a","b","c")
. Internally,
the last form is used. Notice that the +
and :
operator are used as a separators only. The order of the variables IS
important so the operators DO NOT commute.
The first variable in levels
varies fastest.
An array.
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. https://www.jstatsoft.org/v46/i10/.
andtable
, ortable
,
extract_cpt
, compileCPT
,
extract_cpt
, compilePOT
,
grain
## See the wet grass example at
## https://en.wikipedia.org/wiki/Bayesian_network
yn <- c("yes", "no")
ssp <- list(R=yn, S=yn, G=yn) # state space
## Different forms
t1 <- cpt(c("S", "R"), levels=ssp, values=c(.01, .99, .4, .6))
t2 <- cpt(~S:R, levels=ssp, values=c(.01, .99, .4, .6))
t3 <- cpt(~S:R, levels=c(2, 2), values=c(.01, .99, .4, .6))
t4 <- cpt(~S:R, levels=yn, values=c(.01, .99, .4, .6))
t1; t2; t3; t4
varNames(t1)
valueLabels(t1)
## Wet grass example
ssp <- list(R=yn, S=yn, G=yn) # state space
p.R <- cpt(~R, levels=ssp, values=c(.2, .8))
p.S_R <- cpt(~S:R, levels=ssp, values=c(.01, .99, .4, .6))
p.G_SR <- cpt(~G:S:R, levels=ssp, values=c(.99, .01, .8, .2, .9, .1, 0, 1))
wet.cpt <- compileCPT(p.R, p.S_R, p.G_SR)
wet.cpt
wet.cpt$S # etc
# A Bayesian network is created with:
wet.bn <- grain(wet.cpt)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.