Facilities for easy implementation of hybrid Bayesian networks using R. Bayesian networks are directed acyclic graphs representing joint probability distributions, where each node represents a random variable and each edge represents conditionality. The full joint distribution is therefore factorized as a product of conditional densities, where each node is assumed to be independent of its non-descendents given information on its parent nodes. Since exact, closed-form algorithms are computationally burdensome for inference within hybrid networks that contain a combination of continuous and discrete nodes, particle-based approximation techniques like Markov Chain Monte Carlo are popular. We provide a user-friendly interface to constructing these networks and running inference using the 'rjags' package. Econometric analyses (maximum expected utility under competing policies, value of information) involving decision and utility nodes are also supported.
Facilities for easy implementation of hybrid Bayesian networks using R. Bayesian networks are directed acyclic graphs representing joint probability distributions, where each node represents a random variable and each edge represents conditionality. The full joint distribution is therefore factorized as a product of conditional densities, where each node is assumed to be independent of its non-desendents given information on its parent nodes. Since exact, closed-form algorithms are computationally burdensome for inference within hybrid networks that contain a combination of continuous and discrete nodes, particle-based approximation techniques like Markov Chain Monte Carlo are popular. We provide a user-friendly interface to constructing these networks and running inference using rjags. Econometric analyses (maximum expected utility under competing policies, value of information) involving decision and utility nodes are also supported.
HydeNet
may be installed using
install.packages("HydeNet")
Patched versions from GitHub may be installed using
setRepositories(ind=1:2)
devtools::install_github("nutterb/HydeNet")
Please note that you may need to use the ref
argument in install_github
to get the latest
updates. Please visit the GitHub repository
to explore branches of the project.
The package includes a colletion of vignettes to help you get started. Use vignette(package = "HydeNet")
to see the complete listing of vignettes.
plot.HydeNetwork
to accommodate changes in DiagrammeR
.testthat
ArgumentCheck
to checkmate
pixiedust
to allow better parsing of term names. This
also resulted in removing the dependency on broom
(which is alright, because
pixiedust
depends on broom
.data
argument of compileDecisionModel
.factorFormula
to assist in writing formulae that make use
of factor levels instead of their numeric codes.factorLevels
element in network objects
and arguments in setNode
. See Issue #81plot.HydeNetwork
relevant to changes in
DiagrammeR
0.8.0. Note that the column names in custom node
data frames no longer contain node_id
but use nodes
instead. However, the HydeNet
function arguments have no
changed names, in order to maintain compatibility with 0.9.0.
Future versions may allow for either node_id
or nodes
to
be used. In custom edge data frames, edge_from
and edge_to
are changed to from
and to
, respectively.compileJagsModel
and compileDecisionModel
that prevented cpt
objects from being passed to JAGS models correctly.nodeData
argument to setNode
.ArgumentCheck
packagecompileDecisionModel
. This allows decision networks to be
compiled for absurdly large policy matrices (> 1000 policies)utils
and stats
to comply with new CRAN policies.nodeType
specifications to properly build in
writeJagsModel
. (See Issue #72)cpt
arrays from being passed to jags.model
in
compileDecisionModel
cpt
arrays in the JAGS models.factorRef
element of the compiled Hyde Networks.data
element, not the nodeData
elements.mergeCustomNodes
to prevent loss of custom settingsHydeNetPlots
vignetteGettingStartedWithHydeNet
vignette.ObtainingPosteriorDistributions
vignette.VignetteBuilder
option to the description file. For now, when reinstalling the
package, use the command devtools::install_local([directory])
. If you try to build the
vignettes with the package, a strange error occurs that prevents the installation. This
error is related to the WorkingWithHydeNetObjects
vignette, but I can't reproduce the
error outside of the build command.setNodeModel
and writeJagsFormula
methods are complete.writeJagsModel
now accommodates cpt
objectscompileJagsNetwork
retrieves cpt
objects to include in the
data
argument, allowing JAGS to compile without the user having to
remember to assign the cpt
object to the data.cpt
function is added to assist in developing multidimensional conditional
probability tables. cpt
and cptInput
are generics with methods for list
and formula
. Their structure is undergoing some growing pains right now,
so expect more changes in the future.setNode
validation.compileDecisionModel
.HydeNetwork
chooses cpt
as the fitter for variables where the node is
a factor and all parents are factors.modelToNode.cpt
. This is untested as of yet and may be buggy. Final
changes are pending the finalization of the cpt
objects.nodeFromFormula
is used to generate most likely
node names from terms in model formulas that are used in functions and other
transformations. For instance, when a formula has factor(x)
, only the x
is used in node names. (Solves Issue #31)matchVars
is used to reduce terms in
model formulas to just the node name. (Solves Issue #26)writeJagsModel
and modelToNode
that is
required by an unexported function matchVars
.setNode
to retain current settings for decision and
utility nodes (Issue #53)setNode
are not validated (Issue #24).BlackJack
network object to be consistent with the object defined in
the Decision Nodes vignette.broom (>= 0.3.7)
. This makes sure that the multinom tidiers
are available.gRbase
from Depends: to Imports:plot.HydeNetwork
that prevented plotting without defaultsHydeNetPlots
vignette to accommodate new plotting features.compileDecisionModel
and fixed all the
bugs that popped up in doing so.bjdata
to
BlackJackTrain
. Added documentation for it.BlackJack
data object, which contains a HydeNetwork
object
simulating a game of black jack.dplyr
and magrittr
. This was done to
make dplyr
available for joining MCMC matrices returned by coda.samples
.compileJagsModel
to accommodate compiling multiple JAGS models when
a policy/decision matrix is provided.HydePosterior
, which generates posterior distributions
of all of the JAGS models compiled by HydePosterior
.HydePosterior
HydePosterior
into
a single data frame.compileJagsModel
that affected observed data values.
(Issue #36 on GitHub).modelToNode
that printed the node name in the first
parameter, causing compileJagsModel
to fail. (Issue #35 on GitHub).network$nodeDecision
. It is a logical value indicating if the node should
be considered a decision node.compileDecisionNetwork
function.compileDecisionNetwork
evaluates all of the decision nodes, builds a table
of all combinations of decision options, and systematically runs
compileJagsModel
for each row of that table to create a JAGS model for
each combination of decisions.setNode
, but for convenience, a new
function is introduced (setDecisionNodes
) to allow multiple nodes to be
defined as decision nodes in one call. This is intended for use when a list
of models is used to define a network.