PNetica-package | R Documentation |
This package provides RNetica implementation of Peanut interface.This provides an implementation of the Peanut protocol using the Netica (RNetica) Bayesian network engine. This allows parameters of parametric Bayesian network models written and Netica and using Peanut to be processed with R tools, and the parameter saved in the Netica objects.
The DESCRIPTION file:
This package was not yet installed at build time.
The Peanut
package provides a set of generic
functions for manipulation parameterized networks, in particular, for
the abstract Pnet
and Pnode
classes. This package provides concrete implementations of those classes
using the built in classes of RNetica
. In
particular, Pnet.NeticaBN
extends
NeticaBN
and Pnode.NeticaNode
extends
NeticaNode
. The documentation object
Pnode.States
documents additional fields of this object.
The properties of the Pnet
and
Pnode
objects are stored as serialized Netica user
fields (see NetworkUserObj
and
NodeUserObj
). The documentation object
Pnode.Properties
documents the methods.
The as.Pnet
(as.Pnode
) method for
a NeticaBN
(NeticaNode
)
merely adds “Pnet” (“Pnode”) to class(net)
(class(node)
). All of the methods in the PNetica
are
defined for either the NeticaBN
or
NeticaNode
object, so strictly speaking, adding
the “Pnet” or “Pnode” class is not necessary, but it is
recommended in case this is used in the future.
Here are some Netica specific details which may not be apparent from
the description of the generic functions in the
Peanut
package.
The cases
argument to calcPnetLLike
,
calcExpTables
and
GEMfit
all
expect the pathname of a Netica case file (see
write.CaseFile
).
The methods calcPnetLLike
,
calcExpTables
, and therefore
GEMfit
when called with a
Pnet
as the first argument, expect that
there exists a node set (see
NetworkNodesInSet
) called “onodes”
corresponding to
the observable variables in the case file cases
.
The function CompileNetwork
needs to be
called before calls to calcPnetLLike
,
calcExpTables
and
GEMfit
.
The method PnetPnodes
stores
its value in a nodeset called “pnodes”. It is recommended
that the accessor function be used for modifying this field.
The PnetPriorWeight
field of the
Pnet.NeticaBN
object and all of the fields of the
Pnode.NeticaNode
are stored in serialized user fields
with somewhat obvious names (see
NetworkUserObj
and
NodeUserObj
). These fields should not be
used for other purposes.
As both the nodesets and and user fields are serialized when Netica
serializes a network (WriteNetworks
) the
fields of the Pnet.NeticaBN
and
Pnode.NeticaNode
objects should be properly saved and
restored.
The first time the network and nodes are created, it is recommended that
Pnet
and Pnode.NeticaNode
(or simply the generic functions Pnet
and
Pnode
. Note that calling
Pnode
will calculate defaults for the
PnodeLnAlphas
and PnodeBetas
based on the current value of NodeParents(node)
,
so this should be set before calling this function. (See examples).
Index: This package was not yet installed at build time.
Netica and Norsys are registered trademarks of Norsys, LLC (http://www.norsys.com/), used by permission.
Extensive use of PNetica
will require a Netica API license from
Norsys. This is basically a requirement of the
RNetica
package, and details are described more
fully there. Without a license, RNetica
and PNetica
will work in a student/demonstration mode which limits the size of the
network.
Although Norsys is generally supportive of the RNetica project, it does not officially support RNetica, and all questions should be sent to the package maintainers.
Russell Almond
Maintainer: Russell Almond <ralmond@fsu.edu>
Almond, R. G. (2015) An IRT-based Parameterization for Conditional Probability Tables. Paper presented at the 2015 Bayesian Application Workshop at the Uncertainty in Artificial Intelligence Conference.
PNetica
depends on the following other packages.
RNetica
A binding of the Netica C API into R.
Peanut
An the generic functions for which this package provides implementations.
CPTtools
A collection of implementation independent Bayes net utilities.
sess <- NeticaSession()
startSession(sess)
## Building CPTs
tNet <- CreateNetwork("TestNet", session=sess)
theta1 <- NewDiscreteNode(tNet,"theta1",
c("VH","High","Mid","Low","VL"))
NodeLevels(theta1) <- effectiveThetas(NodeNumStates(theta1))
NodeProbs(theta1) <- rep(1/NodeNumStates(theta1),NodeNumStates(theta1))
theta2 <- NewDiscreteNode(tNet,"theta2",
c("VH","High","Mid","Low","VL"))
NodeLevels(theta2) <- effectiveThetas(NodeNumStates(theta2))
NodeProbs(theta2) <- rep(1/NodeNumStates(theta2),NodeNumStates(theta2))
partial3 <- NewDiscreteNode(tNet,"partial3",
c("FullCredit","PartialCredit","NoCredit"))
NodeParents(partial3) <- list(theta1,theta2)
partial3 <- Pnode(partial3,Q=TRUE, link="partialCredit")
PnodePriorWeight(partial3) <- 10
BuildTable(partial3)
## Set up so that first skill only needed for first transition, second
## skill for second transition; adjust alphas to match
PnodeQ(partial3) <- matrix(c(TRUE,TRUE,
TRUE,FALSE), 2,2, byrow=TRUE)
PnodeLnAlphas(partial3) <- list(FullCredit=c(-.25,.25),
PartialCredit=0)
BuildTable(partial3)
partial4 <- NewDiscreteNode(tNet,"partial4",
c("Score4","Score3","Score2","Score1"))
NodeParents(partial4) <- list(theta1,theta2)
partial4 <- Pnode(partial4, link="partialCredit")
PnodePriorWeight(partial4) <- 10
## Skill 1 used for first transition, Skill 2 used for second
## transition, both skills used for the 3rd.
PnodeQ(partial4) <- matrix(c(TRUE,TRUE,
FALSE,TRUE,
TRUE,FALSE), 3,2, byrow=TRUE)
PnodeLnAlphas(partial4) <- list(Score4=c(.25,.25),
Score3=0,
Score2=-.25)
BuildTable(partial4)
## Fitting Model to data
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 <- NetworkFindNode(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]])
}
casepath <- system.file("testdat","IRT10.2PL.200.items.cas",
package="PNetica")
## Record which nodes in the casefile we should pay attention to
NetworkNodesInSet(irt10.base,"onodes") <-
NetworkNodesInSet(irt10.base,"observables")
BuildAllTables(irt10.base)
CompileNetwork(irt10.base) ## Netica requirement
item1 <- irt10.items[[1]]
priB <- PnodeBetas(item1)
priA <- PnodeAlphas(item1)
priCPT <- NodeProbs(item1)
gemout <- GEMfit(irt10.base,casepath)
DeleteNetwork(irt10.base)
DeleteNetwork(tNet)
stopSession(sess)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.