### details

parent 765b282d
Pipeline #2534 passed with stage
in 3 seconds
 ############################################################################### print.mcmcabn.R --- Author : Gilles Kratzer Last modified : 05/02/2019 : print.mcmcabn <- function(x, ...) { cat("Posterior Bayesian network score estimated using MCMC:") cat("Number of Burn in steps: ", (x$burnin), "\n", sep = "") cat("Posterior Bayesian network score estimated using MCMC:\n") cat("Number of burn-in steps: ", (x$burnin), "\n", sep = "") cat("Number of MCMC steps: ", (x$iterations), "\n", sep = "") cat("Thinning: ", (x$thinning), "\n\n", sep = "") ... ...
 ... ... @@ -4,13 +4,13 @@ summary.mcmcabn <- function(object, quantiles = c(0.025, 0.25, 0.5, 0.75, 0.975) cat("MCMC summary:\n", sep = "") cat("Number of Burn in steps: ", (object$burnin), "\n", sep = "") cat("Number of burn-in steps: ", (object$burnin), "\n", sep = "") cat("Number of MCMC steps: ", (object$iterations), "\n", sep = "") cat("Thinning: ", (object$thinning), "\n\n", sep = "") cat("Maximum score: ", max(object$scores), "\n", sep = "") cat("Empirical mean: ", mean(object$scores), "\n", sep = "") cat("Empirical standard deviation: ", sd(object$scores), "\n", sep = "") cat("Empirical standard deviation: ", format(sd(object$scores),...), "\n", sep = "") cat("Quantiles of the posterior network score:\n") ... ... @@ -19,16 +19,17 @@ summary.mcmcabn <- function(object, quantiles = c(0.025, 0.25, 0.5, 0.75, 0.975) print(out1, ...) cat("\n\nGlobal acceptance rate: ", 1 - mean(object$rejection), "\n", sep = "") cat("\n\nGlobal acceptance rate: ", format( 1 - mean(object$rejection), ...), "\n", sep = "") out2 <- matrix(data = table(object$method, object$rejection), ncol = 2, dimnames = list(levels(factor(object$method)), c("Accepted", "Rejected"))) print(out2, ...) cat("\n\nSample size adjusted for autocorrelation: ", unname(effectiveSize(object$scores)), "\n", sep = "") cat("\n\nSample size adjusted for autocorrelation: ", format( unname(effectiveSize(object$scores)), ...), "\n", sep = "") unname(acf(object$scores, lag.max = 10, plot = FALSE)) # unname(acf(object\$scores, lag.max = 10, plot = FALSE)) cat("\nAutocorrelations by lag:\n") ... ...
 ... ... @@ -16,10 +16,10 @@ \examples{ ## This data set was generated using the following code: library(bnlearn) #for the dataset library(abn) #for the cache of score function library("bnlearn") # for the dataset library("abn") # for the cache of score function #renaming columns of the dataset # Renaming columns of the dataset colnames(asia) <- c("Asia", "Smoking", "Tuberculosis", ... ... @@ -29,7 +29,7 @@ colnames(asia) <- c("Asia", "XRay", "Dyspnea") #lets define the distribution list ## Defining the distribution list dist.asia <- list(Asia = "binomial", Smoking = "binomial", Tuberculosis = "binomial", ... ... @@ -42,8 +42,6 @@ dist.asia <- list(Asia = "binomial", bsc.compute.asia <- buildscorecache(data.df = asia, data.dists = dist.asia, max.parents = 2) } \keyword{datasets}
 ... ... @@ -16,9 +16,9 @@ \examples{ ## This data set was generated using the following code: library(bnlearn) #for the dataset library("bnlearn") # for the dataset #renaming columns of the dataset # Renaming columns of the dataset colnames(asia) <- c("Asia", "Smoking", "Tuberculosis", ... ... @@ -28,7 +28,7 @@ colnames(asia) <- c("Asia", "XRay", "Dyspnea") #lets define the distribution list # Defining the distribution list dist.asia <- list(Asia = "binomial", Smoking = "binomial", Tuberculosis = "binomial", ... ...
 ... ... @@ -15,7 +15,7 @@ query(mcmcabn = NULL, \arguments{ \item{mcmcabn}{object of class mcmcabn.} \item{formula}{formula statement or adjacency matrix to query the MCMC samples, see details. If this argument is NULL, then the average arc-wise frequencies is reported.} \item{formula}{formula statement or adjacency matrix to query the MCMC samples, see details. If this argument is \code{NULL}, then the average arc-wise frequencies is reported.} } \description{The function allows users to perform structural queries over MCMC samples produced by \code{mcmcabn}. ... ... @@ -23,10 +23,10 @@ query(mcmcabn = NULL, \details{The query can be formulated using an adjacency matrix or a formula-wise expression. The adjacency matrix should be squared of dimension equal to the number of nodes in the networks. Their entries should be either 1,0 or -1. The 1 indicates the requested arcs, the -1 the excluded and the 0 all other entries that are not subject to query. The rows indicated the set of parents of the index nodes. The order of rows and column should be the same as the one used in the mcmcabn() function in the data.dist argument. The adjacency matrix should be squared of dimension equal to the number of nodes in the networks. Their entries should be either 1, 0 or -1. The 1 indicates the requested arcs, the -1 the excluded and the 0 all other entries that are not subject to query. The rows indicated the set of parents of the index nodes. The order of rows and column should be the same as the one used in the \code{mcmcabn()} function in the \code{data.dist} argument. The formula statement has been designed to ease querying over the MCMC sample. It allows user to make complex queries without explicitly writing an adjacency matrix (which can be painful when the number of variables is large). The formula argument can be provided using typically a formula like: ~ node1|parent1:parent2 + node2:node3|parent3. The formula statement has to start with ~. 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 name. : is the separator between either children or parents, | separates children (left side) and parents (right side), + separates \code{~ node1|parent1:parent2 + node2:node3|parent3}. The formula statement has to start with ~. 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 name. : is the separator between either children or parents, | separates children (left side) and parents (right side), + separates terms, . replaces all the variables in name. Additional, when one want to exclude an arc simply put - in front of that statement. Then a formula like: ~ -node1|parent1 exclude all DAGs that have an arc between parent1 and node1. If the formula argument is not provided the function returns the average support of all individual arcs using a named matrix. ... ... @@ -36,33 +36,32 @@ If the formula argument is not provided the function returns the average support \author{Gilles Kratzer} \references{Kratzer, G. Furrer, R. "Is a single unique Bayesian network enough to accurately represent your data?". arXiv preprint arXiv:1902.06641. \references{Kratzer, G., Furrer, R. "Is a single unique Bayesian network enough to accurately represent your data?". arXiv preprint arXiv:1902.06641. Lauritzen S, Spiegelhalter D (1988). "Local Computation with Probabilities on Graphical Structures and their Application to Expert Systems (with discussion)". Journal of the Royal Statistical Society: Series B, 50(2):157–224. Lauritzen, S., Spiegelhalter, D. (1988). "Local Computation with Probabilities on Graphical Structures and their Application to Expert Systems (with discussion)". Journal of the Royal Statistical Society: Series B, 50(2):157–224. Scutari, M. (2010). Learning Bayesian Networks with the bnlearn R Package. Journal of Statistical Software, 35(3), 1 - 22. doi:http://dx.doi.org/10.18637/jss.v035.i03. Scutari, M. (2010). Learning Bayesian Networks with the bnlearn R Package. Journal of Statistical Software, 35(3), 1–22. doi:http://dx.doi.org/10.18637/jss.v035.i03. } \examples{ ## Example from the asia dataset from Lauritzen and Spiegelhalter (1988) provided by Scutari (2010) ## Example from the asia dataset from Lauritzen and Spiegelhalter (1988) ## provided by Scutari (2010) data("mcmc_run_asia") ##return a named matrix with individual arc support ## Return a named matrix with individual arc support query(mcmcabn = mcmc.out.asia) ## what is the probability of LungCancer node being children of the Smoking node? ## What is the probability of LungCancer node being children of the Smoking node? query(mcmcabn = mcmc.out.asia,formula = ~LungCancer|Smoking) ## what is the probability of Smoking node being parent of ## What is the probability of Smoking node being parent of ## both LungCancer and Bronchitis node? query(mcmcabn = mcmc.out.asia, formula = ~ LungCancer|Smoking+Bronchitis|Smoking) formula = ~ LungCancer|Smoking+Bronchitis|Smoking) ## what is the probability of previous statement, ## when there is no arc from Smoking to Tuberculosis and from Bronchitis to XRay? ## What is the probability of previous statement, when there ## is no arc from Smoking to Tuberculosis and from Bronchitis to XRay? query(mcmcabn = mcmc.out.asia, formula = ~LungCancer|Smoking + Bronchitis|Smoking - Tuberculosis|Smoking - XRay|Bronchitis) formula = ~LungCancer|Smoking + Bronchitis|Smoking - Tuberculosis|Smoking - XRay|Bronchitis) }