Commit c5cfd791 authored by Reinhard Furrer's avatar Reinhard Furrer
Browse files

abn version 2.7-3

parent 3564e8fe
\name{abn-defunct}
\alias{abn-defunct}
\alias{search.hillclimber}
\title{Defunct functions and data in package \pkg{abn}}
\description{
The functions and data listed are defunct in package \pkg{abn}. Alternative data and functions with similar
functionality are mentioned.}
\usage{
search.hillclimber(...)
}
\seealso{
\code{\link{searchHillClimber}}
}
% R documentation directory (show via RShowDoc("KEYWORDS")):
\keyword{internal}
\name{abn-deprecated}
\alias{abn-deprecated}
\alias{fitabn}
\alias{plotabn}
\alias{searchHillclimber}
\alias{mostprobable}
\alias{buildscorecache}
\title{Deprecated functions and data in package \pkg{abn}}
\description{
The functions and data listed are deprecated and/or renamed and will be defunct
in the near future. Alternative data and functions with similar
functionality are mentioned.}
\usage{
fitabn(...)
plotabn(...)
searchHillclimber(...)
mostprobable(...)
buildscorecache(...)
}
\seealso{
\code{\link{plotAbn}}, \code{\link{searchHillclimber}}, \code{\link{mostProbable}}, \code{\link{buildScoreCache}},
}
% R documentation directory (show via RShowDoc("KEYWORDS")):
\keyword{internal}
% abn-internal.Rd ---
% Author : Fraser Lewis
% Last modified on : 26/09/2014, 30/05/2019 , 11/11/2019
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\name{abn-internal}
\alias{calc.node.inla.glm}
\alias{calc.node.inla.glmm}
\alias{buildScoreCache.mle}
\alias{buildScoreCache.bayes}
\alias{fitAbn.bayes}
\alias{fitAbn.mle}
\title{abn internal functions}
\description{
These are functions for either internal use or error checking and are
not meant to be called directly by the user.
}
\usage{
buildScoreCache.bayes(data.df=NULL, data.dists=NULL, group.var=NULL, cor.vars=NULL,
dag.banned=NULL, dag.retained=NULL, max.parents=NULL,
which.nodes=NULL,defn.res=NULL,dry.run=FALSE, centre=TRUE,
control = build.control(method = "bayes"), verbose = FALSE)
buildScoreCache.mle(data.df = NULL, data.dists = NULL, max.parents = NULL,
adj.vars = NULL, cor.vars = NULL, dag.banned = NULL,
dag.retained = NULL, which.nodes = NULL, centre = TRUE,
defn.res = NULL, dry.run = FALSE, verbose = FALSE,
control = build.control(method = "mle"))
fitAbn.mle(dag = NULL, data.df = NULL, data.dists = NULL, adj.vars = NULL,
cor.vars = NULL, centre = TRUE, control = fit.control(method = "mle"),
verbose = FALSE)
fitAbn.bayes(dag=NULL, data.df=NULL, data.dists=NULL, group.var=NULL,
cor.vars=NULL, centre=TRUE, compute.fixed=FALSE,
control = fit.control(method = "bayes"),
verbose=FALSE)
calc.node.inla.glm(child.loc,dag.m.loc,data.df.loc,data.dists.loc,
ntrials.loc,exposure.loc,compute.fixed.loc,
mean.intercept.loc,prec.intercept.loc,mean.loc,prec.loc,
loggam.shape.loc,loggam.inv.scale.loc,verbose.loc)
calc.node.inla.glmm(child.loc,dag.m.loc,data.df.loc,data.dists.loc,
ntrials.loc,exposure.loc,compute.fixed.loc,
mean.intercept.loc,prec.intercept.loc,mean.loc,prec.loc,
loggam.shape.loc,loggam.inv.scale.loc,verbose.loc)
}
\details{
\code{buildScoreCache.mle} and \code{buildScoreCache.bayes} are internal functions called by \code{buildScoreCache}. \cr
\code{fitAbn.mle} and \code{fitAbn.bayes} are internal functions called by \code{fitAbn}. \cr
\code{calc.node.inla.glm} and \code{calc.node.inla.glmm} are internal wrappers to INLA and are called from \code{fitAbn.bayes}.}
\author{Fraser Iain Lewis, Gilles Kratzer}
\keyword{internal}
......@@ -11,20 +11,27 @@
\format{An adapted data frame of the original dataset which consists of 341 observations of 8 variables and a grouping variable (farm).
\describe{
\item{farm}{farm ID.}
\item{female}{sex of the pig (1=female, 0=castrated). }
\item{age}{days elapsed from birth to slaughter (days).}
\item{adg}{average daily weight gain (grams).}
\item{AR}{presence of atrophic rhinitis.}
\item{pneumS}{presence of moderate to severe pneumonia.}
\item{female}{sex of the pig (1=female, 0=castrated). }
\item{livdam}{presence of liver damage (parasite-induced white spots).}
\item{eggs}{presence of fecal/gastrointestinal nematode eggs at time of slaughter.}
\item{wormCount}{count of nematodes in small intestine at time of slaughter.}
\item{livdam}{presence of liver damage (parasite-induced white spots).}
\item{AR}{presence of atrophic rhinitis.}
\item{age}{days elapsed from birth to slaughter (days).}
\item{adg}{average daily weight gain (grams).}
\item{farm}{farm ID.}
}
}
}
\details{
When using the data to fit an additive Bayesian network, the variables \code{AR}, \code{pneumS}, \code{female}, \code{livdam},
\code{eggs} are considered binomial, \code{wormcount} Poisson,
\code{age} and \code{adg} Gaussian. The variable \code{farm} can be used
to adjust for grouping.
}
\references{
Kratzer, G., Lewis, F.I., Comin, A., Pittavino, M. and Furrer, R. (2019). "Additive Bayesian Network Modelling with the R Package abn". arXiv preprint arXiv:1911.09006.
\references{
Kratzer, G., Lewis, F.I., Comin, A., Pittavino, M. and Furrer, R. (2019). "Additive Bayesian Network Modelling with the R Package abn". arXiv preprint arXiv:1911.09006.
Dohoo, Ian Robert, Wayne Martin, and Henrik Stryhn. Veterinary epidemiologic research. No. V413 DOHv. Charlottetown, Canada: AVC Incorporated, 2003.}
......
% build_control.Rd ---
% Author : Kalina Cherneva
% Created on : 04/10/2021
% Last modification : 04/10/2021
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\name{build.control}
\alias{build.control}
\title{
Control the iterations in \code{\link{buildScoreCache}}
}
\description{
Allow the user to set restrictions in the \code{\link{buildscorecache}} for both the
Bayesian and the MLE approach.
}
\usage{
build.control(method = "bayes", max.mode.error = 10, mean = 0, prec = 0.001,
loggam.shape = 1, loggam.inv.scale = 5e-05, max.iters = 100, epsabs = 1e-07,
error.verbose = FALSE, trace = 0L, epsabs.inner = 1e-06, max.iters.inner = 100,
finite.step.size = 1e-07, hessian.params = c(1e-04, 0.01),
max.iters.hessian = 10, max.hessian.error = 0.5, factor.brent = 100,
maxiters.hessian.brent = 100, num.intervals.brent = 100,
ncores = 0, max.irls = 100, tol = 10^-8, seed = 9062019)
}
\arguments{
\item{method}{a character that takes one of two values: "bayes" or "mle"}
\item{max.mode.error}{if the estimated modes from INLA differ by a factor of max.mode.error or more from those computed internally, then results from INLA are replaced by those computed internally. To force INLA always to be used, then max.mode.error=100, to force INLA never to be used max.mod.error=0.}
\item{mean}{the prior mean for all the Gaussian additive terms for each node}
\item{prec}{the prior precision for all the Gaussian additive term for each node}
\item{loggam.shape}{the shape parameter in the Gamma distribution prior for the precision in a Gaussian node}
\item{loggam.inv.scale}{the inverse scale parameter in the Gamma distribution prior for the precision in a Gaussian node}
\item{max.iters}{total number of iterations allowed when estimating the modes in Laplace approximation}
\item{epsabs}{absolute error when estimating the modes in Laplace approximation for models with no random effects.}
\item{error.verbose}{logical, additional output in the case of errors occurring in the optimization}
\item{trace}{Non-negative integer. If positive, tracing information on the progress of the "L-BFGS-B" optimization is produced. Higher values
may produce more tracing information. (There are six levels of tracing. To understand exactly what these do see the source code.)}
\item{epsabs.inner}{absolute error in the maximization step in the (nested) Laplace approximation for each random effect term}
\item{max.iters.inner}{total number of iterations in the maximization step in the nested Laplace approximation}
\item{finite.step.size}{suggested step length used in finite difference estimation of the derivatives for the (outer) Laplace approximation when estimating modes}
\item{hessian.params}{a numeric vector giving parameters for the adaptive algorithm, which determines the optimal stepsize in the finite-difference estimation of the hessian. First entry is the initial guess, second entry absolute error}
\item{max.iters.hessian}{integer, maximum number of iterations to use when determining an optimal finite difference approximation (Nelder-Mead)}
\item{max.hessian.error}{if the estimated log marginal likelihood when using an adaptive 5pt finite-difference rule for the Hessian differs by more than max.hessian.error from when using an adaptive 3pt rule then continue to minimize the local error by switching to the Brent-Dekker root bracketing method}
\item{factor.brent}{if using Brent-Dekker root bracketing method then define the outer most interval end points as the best estimate of h (stepsize) from the Nelder-Mead as (h/factor.brent,h*factor.brent)}
\item{maxiters.hessian.brent}{maximum number of iterations allowed in the Brent-Dekker method}
\item{num.intervals.brent}{the number of initial different bracket segments to try in the Brent-Dekker method}
\item{max.irls}{total number of iterations for estimating network scores using an Iterative Reweighed Least Square algorithm}
\item{tol}{real number giving the minimal tolerance expected to terminate the Iterative Reweighed Least Square algorithm to estimate network score.}
\item{ncores}{The number of cores to parallelize to, see \sQuote{Details}.}
\item{seed}{a non-negative integer which sets the seed.}
}
\details{
Parallelization over all children is possible via the function \code{foreach} of the package \pkg{doParallel}. \code{ncode=1} uses single threaded \code{foreach}. \code{ncode=-1} uses all available cores but one.
With \code{ncores=0} a simple \code{for} loop is used.
}
\value{
A list with 18 components for the Bayesian approach, or a list with 4 components for "mle"
}
\examples{
ctrlmle <- build.control(method = "mle", ncores = 0, max.irls = 100, tol = 10^-11, seed = 9062019)
ctrlbayes <- build.control(method = "bayes", max.mode.error = 10, mean = 0, prec = 0.001,
loggam.shape = 1, loggam.inv.scale = 5e-05, max.iters = 100,
epsabs = 1e-07, error.verbose = FALSE, epsabs.inner = 1e-06,
max.iters.inner = 100, finite.step.size = 1e-07, hessian.params = c(1e-04, 0.01),
max.iters.hessian = 10, max.hessian.error = 0.5, factor.brent = 100,
maxiters.hessian.brent = 100, num.intervals.brent = 100,
tol = 10^-8, seed = 9062019)
}
This diff is collapsed.
......@@ -10,15 +10,19 @@
\name{compareDag}
\alias{compareDag}
\alias{compareEG}
\alias{compareDAG}
\encoding{latin1}
%- Also NEED an `\alias' for EACH other topic documented here.
\title{Compare two DAGs}
\title{Compare two DAGs or EGs}
\description{Function that returns multiple graph metrics to compare two DAGs, known as confusion matrix or error matrix.}
\description{Function that returns multiple graph metrics to compare two
DAGs or essential graphs, known as confusion matrix or error matrix.}
\usage{
compareDag(ref, test, node.names = NULL)
compareDag(ref, test, node.names = NULL, checkDAG = TRUE)
compareEG(ref, test)
}
%- maybe also `usage' for other objects documented here.
......@@ -26,9 +30,9 @@ compareDag(ref, test, node.names = NULL)
\item{ref}{a matrix or a formula statement (see details for format) defining the reference network structure, a directed acyclic graph (DAG). Note that row names must be set or given in \code{node.names} if the DAG is given via a formula statement.}
\item{test}{a matrix or a formula statement (see details for format) defining the test network structure, a directed acyclic graph (DAG). Note that row names must be set or given in \code{node.names} if the DAG is given via a formula statement.}
\item{node.names}{a vector of names if the DAGs are given via formula, see details.}
\item{checkDAG}{should the DAGs be tested for DAGs (default).}
}
\details{
This R function returns standard Directed Acyclic Graph comparison metrics. In statistical classification, those metrics are known as a confusion matrix or error matrix. Those metrics allows visualization of the difference between different DAGs. In the case where comparing TRUTH to learned structure or two learned structures, those metrics allow the user to estimate the performance of the learning algorithm. In order to compute the metrics, a contingency table is computed of a pondered difference of the adjacency matrices od the two graphs.
......@@ -53,6 +57,11 @@ False Ommision Rate \deqn{\frac{\sum FN}{\sum PCN}}{\frac{\sum FN}{\sum PCN}}
Hamming-Distance: Number of changes needed to match the matrices.
The \code{ref} or \code{test} can be provided using a formula statement (similar to GLM input). A typical formula is \code{ ~ node1|parent1:parent2 + node2:node3|parent3}. The formula statement have to start with \code{~}. In this example, node1 has two parents (parent1 and parent2). node2 and node3 have the same parent3. The parents names have to exactly match those given in \code{node.names}. \code{:} is the separtor between either children or parents, \code{|} separates children (left side) and parents (right side), \code{+} separates terms, \code{.} replaces all the variables in \code{node.names}.
\cr
To test for essential graphs (or graphs) in general, the test for DAG
need to be switched off \code{checkDAG=FALSE}. The function
\code{compareEG()} is a wrapper to \code{compareDag(, checkDAG=FALSE)}.
}
......@@ -78,7 +87,7 @@ ref.m <- matrix(data = c(0,0,0,
colnames(test.m) <- rownames(test.m) <- colnames(ref.m) <- colnames(ref.m) <- c("a", "b", "c")
compareDag(ref = ref.m, test = test.m)
unlist(compareDag(ref = ref.m, test = test.m))
}
\keyword{utilities}
\concept{DAG}
......@@ -10,7 +10,7 @@
\name{createDag}
\alias{createDag}
\alias{create_abnDag}
\alias{createAbnDag}
\encoding{latin1}
%- Also NEED an `\alias' for EACH other topic documented here.
......@@ -19,10 +19,8 @@
\description{Create a legitimate DAG in the abn format.}
\usage{
create_abnDag( dag, data.df = NULL, data.dists = NULL, ...)
createAbnDag( dag, data.df = NULL, data.dists = NULL, ...)
}
%- maybe also `usage' for other objects documented here.
\arguments{
\item{dag}{a matrix or a formula specifying a DAG, see \sQuote{Details}.}
\item{data.df}{named dataframe or named vector.}
......@@ -30,17 +28,23 @@ create_abnDag( dag, data.df = NULL, data.dists = NULL, ...)
\item{...}{further arguments passed to or from other methods.}
}
\details{An object of class \code{class(abn)} contains a named matrix describing the DAG and possibly additional objects such as the associated distributions of the nodes.
\details{An object of class \code{class(abnDag)} contains a named matrix describing the DAG and possibly additional objects such as the associated distributions of the nodes.
If the dag is specified with a formula, either \code{data.df} or
\code{data.dists} is required with the \code{.} quantifier.
\code{data.dists} is required with the \code{.} quantifier.
If the dag is specified with an unnamed matrix and both \code{data.df} and
\code{data.dists} are missing, lower-case letters of the Roman alphabet
are used for the node names.
}
\value{An object of class \code{abnDag} containing a named matrix and a named list giving the distribution for each node.}
\examples{
create_abnDag( ~a+b|a, data.df=c("a"=1, "b"=1))
createAbnDag( ~a+b|a, data.df=c("a"=1, "b"=1))
plot( createAbnDag( matrix( c(0,1,0,0),2,2)))
}
\keyword{utilities}
......
% -*- Mode: Rd -*-
% essentialGraph.Rd ---
% -*- Mode: Rd -*-
% essentialGraph.Rd ---
% Author : Gilles Kratzer
% Created On : 17/07/2018
% Last Modified By: GK (rd file + naming + examples)
% Last Modified On:
% Update Count :
% Last Modified On:
% Update Count :
% Status : Unknown, Use with caution!
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
......@@ -13,13 +13,13 @@
\encoding{latin1}
%- Also NEED an `\alias' for EACH other topic documented here.
\title{Plot an ABN graphic}
\title{Construct the essential graph}
\description{Plot an ABN DAG using formula statement or a matrix in using Rgraphviz through the graphAM class}
\description{Constructs different versions of the essential graph from a given DAG}
\usage{essentialGraph(dag, node.names = NULL, PDAG = "minimal")
}
%- maybe also `usage' for other objects documented here.
\arguments{
\item{dag}{a matrix or a formula statement (see \sQuote{Details} for format) defining the network structure, a directed acyclic graph (DAG).}
......@@ -30,7 +30,7 @@
\details{
This function returns an essential graph from a DAG. This can be useful if the learning procedure is defined up to a Markov class of equivalence. A minimal PDAG is defined as only directed edges are those who participate in v-structure. Whereas the completed PDAG: every directed edge corresponds to a compelled edge, and every undirected edge corresponds to a reversible edge.
This function returns an essential graph from a DAG, aka acyclic partially directed graph (PDAG). This can be useful if the learning procedure is defined up to a Markov class of equivalence. A minimal PDAG is defined as only directed edges are those who participate in v-structure. Whereas the completed PDAG: every directed edge corresponds to a compelled edge, and every undirected edge corresponds to a reversible edge.
The \code{dag} can be provided using a formula statement (similar to glm). A typical formula is \code{ ~ node1|parent1:parent2 + node2:node3|parent3}. The formula statement have to start with \code{~}. In this example, node1 has two parents (parent1 and parent2). node2 and node3 have the same parent3. The parents names have to exactly match those given in \code{node.names}. \code{:} is the separator between either children or parents, \code{|} separates children (left side) and parents (right side), \code{+} separates terms, \code{.} replaces all the variables in \code{node.names}.
}
......@@ -40,6 +40,10 @@ The \code{dag} can be provided using a formula statement (similar to glm). A typ
\references{
West, D. B. (2001). Introduction to Graph Theory. Vol. 2. Upper Saddle River: Prentice Hall.
Chickering, D. M. (2013) A Transformational Characterization of Equivalent Bayesian Network Structures, arXiv:1302.4938.
Further information about \pkg{abn} can be found at:\cr
\url{http://r-bayesian-networks.org}}
......@@ -48,9 +52,9 @@ Further information about \pkg{abn} can be found at:\cr
\examples{
dag <- matrix(c(0,0,0, 1,0,0, 1,1,0), nrow = 3, ncol = 3)
dist <- list(a="gaussian", b="gaussian", c="gaussian")
dist <- list(a="gaussian", b="gaussian", c="gaussian")
colnames(dag) <- rownames(dag) <- names(dist)
essentialGraph(dag)
}
\keyword{utilities}
......
% build_control.Rd ---
% Author : Kalina Cherneva
% Created on : 26/10/2021
% Last modification : 26/10/2021
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\name{fit.control}
\alias{fit.control}
\title{
Control the iterations in \code{\link{fitAbn}}
}
\description{
Allow the user to set restrictions in the \code{\link{fitAbn}} for both the
Bayesian and the MLE approach.
}
\usage{
fit.control(method = "bayes", mean = 0, prec = 0.001, loggam.shape = 1,
loggam.inv.scale = 5e-05, max.mode.error = 10, max.iters = 100,
epsabs = 1e-07, error.verbose = FALSE, trace = 0L, epsabs.inner = 1e-06,
max.iters.inner = 100, finite.step.size = 1e-07,
hessian.params = c(1e-04, 0.01), max.iters.hessian = 10,
max.hessian.error = 1e-04, factor.brent = 100, maxiters.hessian.brent = 10,
num.intervals.brent = 100, min.pdf = 0.001, n.grid = 250, std.area = TRUE,
marginal.quantiles = c(0.025, 0.25, 0.5, 0.75, 0.975), max.grid.iter = 1000,
marginal.node = NULL, marginal.param = NULL, variate.vec = NULL,
max.irls = 100, tol = 10^-11, seed = 9062019)
}
\arguments{
\item{method}{a character that takes one of two values: "bayes" or "mle"}
\item{mean}{the prior mean for all the Gaussian additive terms for each node.}
\item{prec}{the prior precision for all the Gaussian additive terms for each node.}
\item{loggam.shape}{the shape parameter in the Gamma distributed prior for the precision in any Gaussian nodes, also used for group-level precision is applicable.}
\item{loggam.inv.scale}{the inverse scale parameter in the Gamma distributed prior for the precision in any Gaussian nodes, also used for group-level precision, is applicable. }
\item{max.mode.error}{if the estimated modes from INLA differ by a factor of max.mode.error or more from those computed internally, then results from INLA are replaced by those computed internally. To force INLA always to be used, then \code{max.mode.error=100}, to force INLA never to be used \code{max.mod.error=0}. See details.}
\item{max.iters}{total number of iterations allowed when estimating the modes in Laplace approximation}
\item{epsabs}{absolute error when estimating the modes in Laplace approximation for models with no random effects.}
\item{error.verbose}{logical, additional output in the case of errors occurring in the optimization}
\item{trace}{Non-negative integer. If positive, tracing information on the progress of the "L-BFGS-B" optimization is produced. Higher values
may produce more tracing information. (There are six levels of tracing. To understand exactly what these do see the source code.)}
\item{epsabs.inner}{absolute error in the maximization step in the (nested) Laplace approximation for each random effect term}
\item{max.iters.inner}{total number of iterations in the maximization step in the nested Laplace approximation}
\item{finite.step.size}{suggested step length used in finite difference estimation of the derivatives for the (outer) Laplace approximation when estimating modes}
\item{hessian.params}{a numeric vector giving parameters for the adaptive algorithm, which determines the optimal step size in the finite-difference estimation of the Hessian. First entry is the initial guess, second entry absolute error}
\item{max.iters.hessian}{integer, maximum number of iterations to use when determining an optimal finite difference approximation (Nelder-Mead)}
\item{max.hessian.error}{if the estimated log marginal likelihood when using an adaptive 5pt finite-difference rule for the Hessian differs by more than max.hessian.error from when using an adaptive 3pt rule then continue to minimize the local error by switching to the Brent-Dekker root bracketing method, see details}
\item{factor.brent}{if using Brent-Dekker root bracketing method then define the outer most interval end points as the best estimate of h (stepsize) from the Nelder-Mead as (h/factor.brent,h*factor.brent)}
\item{maxiters.hessian.brent}{maximum number of iterations allowed in the Brent-Dekker method}
\item{num.intervals.brent}{the number of initial different bracket segments to try in the Brent-Dekker method}
\item{min.pdf}{the value of the posterior density function below which we stop the estimation only used when computing marginals, see details.}
\item{n.grid}{recompute density on an equally spaced grid with \code{n.grid} points.}
\item{std.area}{logical, should the area under the estimated posterior density be standardized to exactly one, useful for error checking.}
\item{marginal.quantiles}{vector giving quantiles at which to compute the posterior marginal distribution at.}
\item{max.grid.iter}{gives number of grid points to estimate posterior density at when not explicitly specifying a grid used to avoid excessively long computation.}
\item{marginal.node}{used in conjunction with \code{marginal.param} to allow bespoke estimate of a marginal density over a specific grid. value from 1 to the number of nodes.}
\item{marginal.param}{used in conjunction with \code{marginal.node}. value of 1 is for intercept, see modes entry in results for the appropriate number.}
\item{variate.vec}{a vector containing the places to evaluate the posterior marginal density, must be supplied if \code{marginal.node} is not null}
\item{max.irls}{integer given the maximum number of run for estimating network scores using an Iterative Reweighed Least Square algorithm.}
\item{tol}{real number giving the minimal tolerance expected to terminate the Iterative Reweighed Least Square algorithm to estimate network score.}
\item{seed}{a non-negative integer which sets the seed.}
}
\value{
A list with 26 components for the Bayesian approach, or a list with 3 components for "mle".
}
\examples{
ctrlmle <- fit.control(method = "mle", max.irls = 100, tol = 10^-11, seed = 9062019)
ctrlbayes <- fit.control(method = "bayes", mean = 0, prec = 0.001, loggam.shape = 1,
loggam.inv.scale = 5e-05, max.mode.error = 10, max.iters = 100,
epsabs = 1e-07, error.verbose = FALSE, epsabs.inner = 1e-06,
max.iters.inner = 100, finite.step.size = 1e-07, hessian.params = c(1e-04, 0.01),
max.iters.hessian = 10, max.hessian.error = 1e-04, factor.brent = 100,
maxiters.hessian.brent = 10, num.intervals.brent = 100, min.pdf = 0.001,
n.grid = 100, std.area = TRUE, marginal.quantiles = c(0.025, 0.25, 0.5, 0.75, 0.975),
max.grid.iter = 1000, marginal.node = NULL, marginal.param = NULL, variate.vec = NULL,
seed = 9062019)
}
This diff is collapsed.
......@@ -19,18 +19,23 @@
\usage{
infoDag(dag, node.names = NULL)
infoDag(object, node.names = NULL)
}
%- maybe also `usage' for other objects documented here.
\arguments{
\item{dag}{a matrix or a formula statement (see details for format) defining the network structure, a directed acyclic graph (DAG). Note that row names must be set up or given in \code{node.names}.}
\item{object}{an object of class \code{abnLearned}, \code{abnFit}. Alternatively, a matrix or a formula statement defining the network structure, a directed acyclic graph (DAG). Note that row names must be set up or given in \code{node.names}.}
\item{node.names}{a vector of names if the DAG is given via formula, see details.}
}
\details{
This function returns a named list with the following entries: the number of nodes, the number of arcs, the average Markov blanket size, the neighborhood average set size, the parent average set size, and the children's average set size.
This function returns a named list with the following entries: the
number of nodes, the number of arcs, the average Markov blanket size,
the neighborhood average set size, the parent average set size, and the
children's average set size.
The \code{dag} can be provided using a formula statement (similar to glm). A typical formula is \code{ ~ node1|parent1:parent2 + node2:node3|parent3}. The formula statement have to start with \code{~}. In this example, node1 has two parents (parent1 and parent2). node2 and node3 have the same parent3. The parents names have to exactly match those given in \code{node.names}. \code{:} is the separator between either children or parents, \code{|} separates children (left side) and parents (right side), \code{+} separates terms, \code{.} replaces all the variables in \code{node.names}.
}
......@@ -54,10 +59,8 @@ dist <- list(a="gaussian", b="gaussian", c="gaussian", d="gaussian")
colnames(dag) <- rownames(dag) <- names(dist)
infoDag(dag)
plot(createAbnDag(dag))
\dontrun{
plot(create_abnDag(dag))
}
}
\keyword{utilities}
......
......@@ -33,21 +33,20 @@ The \code{dag} can be provided using a formula statement (similar to glm). A typ
\examples{
## Defining distribution and dag
dist <- list(a="gaussian", b="gaussian", c="gaussian", d="gaussian", e="binomial",
f="binomial")
dist <- list(a="gaussian", b="gaussian", c="gaussian", d="gaussian",
e="binomial", f="binomial")
dag <- matrix(c(0,1,1,0,1,0,
0,0,1,1,0,1,
0,0,0,0,0,0,
0,0,0,0,0,0,
0,0,0,0,0,1,
0,0,0,0,0,0), nrow = 6L, ncol = 6L, byrow = TRUE)
0,0,0,0,0,0), nrow = 6L, ncol = 6L, byrow = TRUE)
colnames(dag) <- rownames(dag) <- names(dist)
mb(dag, node = "b", data.dists = dist)
mb(dag, node = "e", data.dists = dist)
mb(dag, node = c("b","e"), data.dists = dist)
mb(dag, node = "b")
mb(dag, node = c("b","e"))
mb(~a|b:c:e+b|c:d:f+e|f, node = "e", data.dists = dist)
}
\keyword{utilities}
\concept{DAG}
% -*- Mode: Rd -*-
% mostprobable.Rd ---
% -*- Mode: Rd -*-
% mostprobable.Rd ---
% Author : Fraser Lewis
% Created On :
% Created On :
% Last Modified By: Marta Pittavino
% Last Modified On: Gilles Kratzer
% Update Count :
% Update Count :
% Status : Unknown, Use with caution!
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\name{mostprobable}
\alias{mostprobable}
\alias{mostProbable}
\encoding{latin1}
%- Also NEED an `\alias' for EACH other topic documented here.
......@@ -19,28 +18,29 @@
\description{Find most probable DAG structure using exact order based approach due to Koivisto and Sood, 2004}
\usage{
mostprobable(score.cache, prior.choice=1, score="mlik", verbose=TRUE)
mostProbable(score.cache, score="bic", prior.choice=1, verbose=TRUE, ...)
}
%- maybe also `usage' for other objects documented here.
\arguments{
\item{score.cache}{object of class \code{abnCache} typically outputted by from \code{buildscorecache()}.}
\item{score.cache}{object of class \code{abnCache} typically outputted by from \code{buildScoreCache()}.}
\item{score}{which score should be used to score the network. Possible choices are \code{aic, bic, mdl, mlik}.}
\item{prior.choice}{an integer, 1 or 2, where 1 is a uniform structural prior and 2 uses a weighted prior, see details}
\item{score}{character giving which network score should be used to select the structure.}
\item{verbose}{if TRUE then provides some additional output.}
\item{...}{further arguments passed to or from other methods.}
}
\details{
The procedure runs the exact order based structure discovery approach of Koivisto and Sood (2004) to find the most probable posterior network (DAG). The local.score is the node cache, as created using \code{\link{buildscorecache}} (or manually provided the same format is used). Note that the scope of this search is given by the options used in local.score, for example, by restricting the number of parents or the ban or retain constraints given there.
The procedure runs the exact order based structure discovery approach of Koivisto and Sood (2004) to find the most probable posterior network (DAG). The local.score is the node cache, as created using \code{\link{buildScoreCache}} (or manually provided the same format is used). Note that the scope of this search is given by the options used in local.score, for example, by restricting the number of parents or the ban or retain constraints given there.
This routine can take a long time to complete and is highly sensitive to the number of nodes in the network. It is recommended to use this on a reduced data set to get an idea as to the computational practicality of this approach. In particular, memory usage can quickly increase to beyond what may be available. For additive models, problems comprising up to 20 nodes are feasible on most machines. Memory requirements can increase considerably after this, but then so does the run time making this less practical. It is recommended that some form of over-modeling adjustment is performed on this resulting DAG (unless dealing with vast numbers of observations), for example, using parametric bootstrapping, which is straightforward to implement in MCMC engines such as JAGS or WinBUGS. See the case studies at \url{http://r-bayesian-networks.org}
This routine can take a long time to complete and is highly sensitive to the number of nodes in the network. It is recommended to use this on a reduced data set to get an idea as to the computational practicality of this approach. In particular, memory usage can quickly increase to beyond what may be available. For additive models, problems comprising up to 20 nodes are feasible on most machines. Memory requirements can increase considerably after this, but then so does the run time making this less practical. It is recommended that some form of over-modeling adjustment is performed on this resulting DAG (unless dealing with vast numbers of observations), for example, using parametric bootstrapping, which is straightforward to implement in MCMC engines such as JAGS or WinBUGS. See the case studies at \url{http://r-bayesian-networks.org}
or the files provided in the package directories \code{inst/bootstrapping_example} and \code{inst/old_vignette}
for details.
for details.
The parameter \code{prior.choice} determines the prior used within each node for a given choice of parent combination. In Koivisto and Sood (2004) p.554, a form of prior is used, which assumes that the prior probability for parent combinations comprising of the same number of parents are all equal. Specifically, that the prior probability for parent set G with cardinality |G| is proportional to 1/[n-1 choose |G|] where there are n total nodes. Note that this favors parent combinations with either very low or very high cardinality, which may not be appropriate. This prior is used when \code{prior.choice=2}. When \code{prior.choice=1} an uninformative prior is used where parent combinations of all cardinalities are equally likely. The latter is equivalent to the structural prior used in the heuristic searches e.g., \code{searchHillclimber} or \code{searchHeuristic}.
The parameter \code{prior.choice} determines the prior used within each node for a given choice of parent combination. In Koivisto and Sood (2004) p.554, a form of prior is used, which assumes that the prior probability for parent combinations comprising of the same number of parents are all equal. Specifically, that the prior probability for parent set G with cardinality |G| is proportional to 1/[n-1 choose |G|] where there are n total nodes. Note that this favors parent combinations with either very low or very high cardinality, which may not be appropriate. This prior is used when \code{prior.choice=2}. When \code{prior.choice=1} an uninformative prior is used where parent combinations of all cardinalities are equally likely. The latter is equivalent to the structural prior used in the heuristic searches e.g., \code{searchHillclimber} or \code{searchHeuristic}.
Note that the network score (log marginal likelihood) of the most probable DAG is not returned as it can easily be computed using \code{\link{fitabn}}, see examples below.
Note that the network score (log marginal likelihood) of the most probable DAG is not returned as it can easily be computed using \code{\link{fitAbn}}, see examples below.
}
......@@ -56,70 +56,63 @@ Further information about \bold{abn} can be found at:\cr
\examples{
\dontrun{
##############################
## Example 1
##############################
## this data comes with abn see ?ex1.dag.data
mydat <- ex1.dag.data
## This data comes with `abn` see ?ex1.dag.data
mydat <- ex1.dag.data[1:5000, c(1:7,10)]
## setup distribution list for each node
## Setup distribution list for each node:
mydists <- list(b1="binomial", p1="poisson", g1="gaussian", b2="binomial",
p2="poisson", b3="binomial", g2="gaussian", b4="binomial",
b5="binomial", g3="gaussian")
## assum no constraints in ban nor retain
p2="poisson", b3="binomial", g2="gaussian", g3="gaussian")
## parent limits
max.par <- list("b1"=0,"p1"=0,"g1"=1,"b2"=1,"p2"=2,"b3"=3,"g2"=3,"b4"=2,"b5"=2,"g3"=2)
## now build cache
mycache <- buildscorecache(data.df = mydat, data.dists = mydists, max.parents = max.par)
## Parent limits, for speed purposes quite specific here:
max.par <- list("b1"=0,"p1"=0,"g1"=1,"b2"=1,"p2"=2,"b3"=3,"g2"=3,"g3"=2)
## Now build cache (no constraints in ban nor retain)
mycache <- buildScoreCache(data.df=mydat, data.dists=mydists, max.parents=max.par)
## Find the globally best DAG
mp.dag <- mostprobable(score.cache=mycache)
fitabn(object=mp.dag)$mlik
## Find the globally best DAG:
mp.dag <- mostProbable(score.cache=mycache)
myres <- fitAbn(object=mp.dag,create.graph=TRUE)
myres$mlik
plot(myres) # plot the best model
## plot the best model
myres <- fitabn(object=mp.dag,create.graph=TRUE)