isPnodeContinuous {Peanut} | R Documentation |
Continuous nodes are handled slightly differently from discrete
nodes. The function isPnodeContinuous
returns a logical value
indicating whether or not the node is continuous.
Continuous nodes can behave like discrete nodes (for the purposes of
building conditional probability tables, see BuildTable
)
if states are created from ranges of values. The function
PnodeStateBounds
accesses those ranges.
isPnodeContinuous(node) PnodeStateBounds(node) PnodeStateBounds(node) <- value
node |
A |
value |
A k by 2 numeric matrix giving the upper and lower bound for each state. |
Continuous, in this case, covers nodes whose possible states are numeric, either integer or real. The current model supports these nodes in a discrete Bayesian network by discretizing them. In particular, the range is broken up into a number of non-overlapping regions, each region corresponding to a state.
For example, consider a variable which is a count, and the analyst wants to consider the values 0, 1, 2 or 3, and 4 or more. This can be done by setting bounds on these states:
"Zero" | -0.5 | 0.5 |
"One" | 0.5 | 1.5 |
"TwoThree" | 1.5 | 3.5 |
"FourPlus" | 3.5 | Inf |
This matrix is the NodeStateBounds
for the node. Note that the
second column is the same as the first (offset by one). Note also
that infinite (Inf
and -Inf
) values are allowed.
Setting the state bounds to a matrix with k rows, will make the variable behave as if it has k states.
The function isPnodeContinuous
returns a logical value.
The function PnodeStateBounds
returns a k by 2 numeric
matrix giving the upper and lower bounds. Note that if bounds have
not been set for the node, then it will return a matrix with 0 rows.
This is rather strongly tied to how Netica treats continuous variables. A different mechism might be necessary as Peanut is expanded to cover more implementations.
Right now, the value is the midpoint of the interval. This cause problems when converting to T-values.
Russell Almond
Pnode
, PnodeStateValues
,
PnodeParentTvals
## Not run: library(PNetica) ## Requires implementation sess <- NeticaSession() startSession(sess) tNet <- CreateNetwork("TestNet",session=sess) theta1 <- NewDiscreteNode(tNet,"theta1", c("VH","High","Mid","Low","VL")) NodeLevels(theta1) <- effectiveThetas(NodeNumStates(theta1)) stopifnot (!isPnodeContinuous(theta1)) ## This gives an error out <- try(PnodeStateBounds(theta1)) stopifnot (is(out,'try-error')) theta0 <- NewContinuousNode(tNet,"theta0") stopifnot(nrow(PnodeStateBounds(theta0)) == 0L) norm5 <- matrix(c(qnorm(c(.001,.2,.4,.6,.8)), qnorm(c(.2,.4,.6,.8,.999))),5,2, dimnames=list(c("VH","High","Mid","Low","VL"), c("LowerBound","UpperBound"))) PnodeStateBounds(theta0) <- norm5 PnodeStates(theta0) PnodeStateBounds(theta0) PnodeStateValues(theta0) ## Note these are medians not mean wrt normal! ## End(Not run)