isPnodeContinuous: Functions for handling continuous nodes.

isPnodeContinuousR Documentation

Functions for handling continuous nodes.

Description

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.

Usage

isPnodeContinuous(node)
PnodeStateBounds(node)
PnodeStateBounds(node) <- value

Arguments

node

A Pnode object.

value

A k by 2 numeric matrix giving the upper and lower bound for each state.

Details

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.

Value

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.

Note

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.

The setter function is very strict about the upper and lower bounds matching. Even a mismatch at the least significant digit will cause a problem.

Author(s)

Russell Almond

See Also

Pnode, PnodeStateValues, PnodeParentTvals

Examples


## 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"))
PnodeStateValues(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!

DeleteNetwork(tNet)
stopSession(sess)


## End(Not run)

ralmond/Peanut documentation built on Sept. 19, 2023, 8:27 a.m.