PnodeStates: Accessor for states of a parameterized node.

PnodeStatesR Documentation

Accessor for states of a parameterized node.

Description

This function returns a list associated with a Pnode. The function PnodeStates returns or manipulates them. Depending on the implementation, states may have restrictions on the names to it is best to stick with variable naming conventions (start with a letter, no embedded spaces or punctuation).

Usage

PnodeStates(node)
PnodeStates(node) <- value
PnodeNumStates(node)

Arguments

node

A Pnode object whose states are to be accessed.

value

A character vector giving the names of the new states. the names of the states. State names may be restricted by the implementing package and should probably stick to variable naming conventions.

Details

The states are important when building conditional probability tables (CPTs). In particular, the state names are used to label the columns of the CPT. Thus, state names can be used to address arrays in the same way that dimnames can. In particular, the state names can be used to index the vectors returned by PnodeStates(), PnodeStateTitles(), PnodeStateTitles(), and PnodeStateValues().

Value

The function PnodeStates() returns a character vector whose values and names are both set to the state names. The setter version of this function invisibly returns the node object.

The expression PnodeNumStates(node) returns an integer scalar giving the number of states of node.

Note

Changing the number of states once a conditional probability table is set will change the dimensions of the table, and hence will likely remove it.

Author(s)

Russell Almond

See Also

Pnode, PnodeName(), PnodeStateTitles(), PnodeStateValues(), PnodeStateDescriptions(),

Examples

## Not run: 
library(PNetica)##Requires PNetica
sess <- NeticaSession()
startSession(sess)
anet <- CreateNetwork("Annette", session=sess)

## Discrete Nodes
nodel2 <- NewDiscreteNode(anet,"TwoLevelNode")
stopifnot(
  length(PnodeStates(nodel2))==2,
  PnodeStates(nodel2)==c("Yes","No")
)

PnodeStates(nodel2) <- c("True","False")
stopifnot(
  PnodeNumStates(nodel2) == 2L,
  PnodeStates(nodel2)==c("True","False")
)



nodel3 <- NewDiscreteNode(anet,"ThreeLevelNode",c("High","Med","Low"))
stopifnot(
  PnodeNumStates(nodel3) == 3L,
  PnodeStates(nodel3)==c("High","Med","Low"),
  PnodeStates(nodel3)[2]=="Med"
)

PnodeStates(nodel3)[2] <- "Median"
stopifnot(
  PnodeStates(nodel3)[2]=="Median"
)

PnodeStates(nodel3)["Median"] <- "Medium"
stopifnot(
  PnodeStates(nodel3)[2]=="Medium"
)

DeleteNetwork(anet)
stopSession(sess)

## End(Not run)

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