PnodeEvidence.NeticaNode | R Documentation |
Adding evidence to a Bayesian network is done by setting the value of
the node to one of its states. The generic function
Peanut::PnodeEvidence
(and the method for a
NeticaNode
) simply returns the to which it is set, or
NA
if the node is not set. There are a number of different
ways of setting the state depending on the type of the value argument
(see Details).
## S4 method for signature 'NeticaNode'
PnodeEvidence(node)
## S4 replacement method for signature 'NeticaNode,ANY'
PnodeEvidence(node) <- value
node |
A |
value |
A value representing the new type of the argument. See details. |
The generic function PnodeEvidence
is defined in
the Peanut
package. It returns either the name of a state
(discrete node), a numeric value (continuous node) or NA
if the
node has not been set.
There are different methods for different classes for the value
argument (the RHS of the assignment operator).
If no other method is appropriate, does nothing and issues a warning.
The value of the node is retracted
(RetractNodeFinding
).
If the value
is the name of a state, then
the node will be set to that state
(NodeFinding
). Otherwise, nothing will be
done and a warning will be issued.
The character value of the value
is uses (see
character method).
This method assumes that the node has exactly two
states, and that those states have values
(PnodeStateValues
,
NodeLevels
) 0 and 1. These levels are used
to determine the mapping of TRUE and FALSE to states. If node
state values are not set, then the character method is called
using “TRUE” or “FALSE” as the value.
If the value
is of length 1, then the value of
the node is set (NodeValue
) to the argument.
If the value
is a vector of the same length as the number of
states of the node, then it is regarded as virtual evidence, and the
likelihood is set (NodeLikelihood
).
Difftime value
s are converted to real numbers
in seconds, then the node value is set (see numeric method).
PnodeEvidence
:
For all node types, if the node is not set, PnodeEvidence
returns NA
.
If the node is continuous, its currently set value is returned as a
numeric scalar (NA
if not set).
If the node is discrete, usually a character value giving the current
state (or NA
) is returned. However, if the node was assigned a
likelihood instead of exact evidence, the likelihood vector is
returned.
PnodeEvidence<-
returns the node argument invisibly.
For continuous nodes, PnodeEvidence
is equivalent to
NodeValue
. For discrete nodes, it maps to
either NodeFinding
or
NodeLikelihood
Russell Almond
The function PnetCompile
usually needs to be run before
this function has meaning.
The functions PnodeStates
and
PnodeStateBounds
define the legal values for the value
argument.
sess <- NeticaSession()
startSession(sess)
irt10.base <- ReadNetworks(system.file("testnets","IRT10.2PL.base.dne",
package="PNetica"),session=sess)
irt10.base <- as.Pnet(irt10.base) ## Flag as Pnet, fields already set.
irt10.theta <- PnetFindNode(irt10.base,"theta")
irt10.items <- PnetPnodes(irt10.base)
## Flag items as Pnodes
for (i in 1:length(irt10.items)) {
irt10.items[[i]] <- as.Pnode(irt10.items[[i]])
}
BuildAllTables(irt10.base)
PnetCompile(irt10.base) ## Netica requirement
stopifnot (is.na(PnodeEvidence(irt10.items[[1]])))
PnodeEvidence(irt10.items[[1]]) <- "Correct"
stopifnot(PnodeEvidence(irt10.items[[1]])=="Correct")
PnodeEvidence(irt10.items[[1]]) <- NULL
stopifnot (is.na(PnodeEvidence(irt10.items[[1]])))
PnodeEvidence(irt10.items[[1]]) <- c(Correct=.6,Incorrect=.3)
stopifnot(all.equal(PnodeEvidence(irt10.items[[1]]),
c(Correct=.6,Incorrect=.3),
tol=3*sqrt(.Machine$double.eps) ))
foo <- NewContinuousNode(irt10.base,"foo")
stopifnot(is.na(PnodeEvidence(foo)))
PnodeEvidence(foo) <- 1
stopifnot(PnodeEvidence(foo)==1)
DeleteNetwork(irt10.base)
stopSession(sess)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.