bidag2codalist: Converting multiple BiDAG chains to mcmc.list

View source: R/bidag2coda.R

bidag2codalistR Documentation

Converting multiple BiDAG chains to mcmc.list

Description

This function converts a list of objects of classes 'orderMCMC' or 'partitionMCMC' to an object of class 'mcmc.list'. This object can be further used for convergence and mixing diagnostics implemented in the R-package coda.

Usage

bidag2codalist(
  MCMClist,
  edges = FALSE,
  pdag = TRUE,
  p = 0.1,
  burnin = 0.2,
  window = 10,
  cumulative = FALSE
)

Arguments

MCMClist

a list of objects of classes orderMCMC or partitionMCMC

edges

logical, when FALSE (default), then only DAG score trace is extracted; when TRUE, a trace of posterior probabilities is extracted for every edge (based on the sampled DAGs defined by parameters 'window' and 'cumulative') resulting in up to n^2 trace vectors, where n is the number of nodes in the network

pdag

logical, when edges=TRUE, defines if the DAGs are converted to CPDAGs prior to computing posterior probabilities; ignored otherwise

p

numeric, between 0 and 1; defines the minimum probability for including posterior traces in the returned objects (for probabilities close to 0, PRSF diagnostics maybe too conservative; the threshold above 0 is recommended)

burnin

numeric between 0 and 1, indicates the percentage of the samples which will be discarded as 'burn-in' of the MCMC chain; the rest of the samples will be used to calculate the posterior probabilities; 0.2 by default

window

integer, defines a number of DAG samples for averaging and computing edges' posterior probabilities; ignored when edges=FALSE

cumulative

logical, indicates if posterior probabilities should be calculated based on a cumulative sample of DAGs, where 25% of the first samples are discarded

Value

Object of class mcmc.list from the package coda

Author(s)

Polina Suter

References

Robert J. B. Goudie and Sach Mukherjee (2016). A Gibbs Sampler for Learning DAGs. J Mach Learn Res. 2016 Apr; 17(30): 1–39.

Examples

## Not run: 
library(coda)
scoreBoston<-scoreparameters("bge",Boston)
ordershort<-list()
#run very short chains -> convergence issues
ordershort[[1]] <- sampleBN(scoreBoston, algorithm = "order", iterations=2000)
ordershort[[2]] <- sampleBN(scoreBoston, algorithm = "order", iterations=2000)
codashort_edges<-bidag2codalist(ordershort,edges=TRUE,pdag=TRUE,p=0.05,burnin=0.2,window=10)
gd_short<-gelman.diag(codashort_edges, transform=FALSE, autoburnin=FALSE, multivariate=FALSE)
length(which(gd_short$psrf[,1]>1.1))/(length(gd_short$psrf[,1]))
#=>more MCMC iterations are needed, try 100000

## End(Not run)

BiDAG documentation built on May 31, 2023, 6:46 p.m.

Related to bidag2codalist in BiDAG...