Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

mcmc.diagnostics

Conduct MCMC diagnostics on a model fit


Description

This function prints diagnistic information and creates simple diagnostic plots for MCMC sampled statistics produced from a fit.

Usage

mcmc.diagnostics(object, ...)

## S3 method for class 'ergm'
mcmc.diagnostics(
  object,
  center = TRUE,
  esteq = TRUE,
  vars.per.page = 3,
  which = c("plots", "texts", "summary", "autocorrelation", "crosscorrelation",
    "burnin"),
  ...
)

Arguments

object

A model fit object to be diagnosed.

...

Additional arguments, to be passed to plotting functions.

center

Logical: If TRUE, center the samples on the observed statistics.

esteq

Logical: If TRUE, for statistics corresponding to curved ERGM terms, summarize the curved statistics by their negated estimating function values (evaluated at the MLE of any curved parameters) (i.e., η'_{I}(\hat{θ})\cdot (g_{I}(Y)-g_{I}(y)) for I being indices of the canonical parameters in question), rather than the canonical (sufficient) vectors of the curved statistics relative to the observed (g_{I}(Y)-g_{I}(y)).

vars.per.page

Number of rows (one variable per row) per plotting page. Ignored if latticeExtra package is not installed.

which

A character vector specifying which diagnostics to plot and/or print. Defaults to all of the below if meaningful:

"plots"

Traceplots and density plots of sample values for all statistic or estimating function elements.

"texts"

Shorthand for the following text diagnostics.

"summary"

Summary of network statistic or estimating function elements as produced by coda::summary.mcmc.list().

"autocorrelation"

Autocorrelation of each of the network statistic or estimating function elements.

"crosscorrelation"

Cross-correlations between each pair of the network statistic or estimating function elements.

"burnin"

Burn-in diagnostics, in particular, the Geweke test.

Partial matching is supported. (E.g., which=c("auto","cross") will print autocorrelation and cross-correlations.)

Details

A pair of plots are produced for each statistic:a trace of the sampled output statistic values on the left and density estimate for each variable in the MCMC chain on the right. Diagnostics printed to the console include correlations and convergence diagnostics.

For ergm() specifically, recent changes in the estimation algorithm mean that these plots can no longer be used to ensure that the mean statistics from the model match the observed network statistics. For that functionality, please use the GOF command: gof(object, GOF=~model).

In fact, an ergm output object contains the matrix of statistics from the MCMC run as component $sample. This matrix is actually an object of class mcmc and can be used directly in the coda package to assess MCMC convergence. Hence all MCMC diagnostic methods available in coda are available directly. See the examples and https://www.mrc-bsu.cam.ac.uk/software/bugs/the-bugs-project-winbugs/coda-readme/.

More information can be found by looking at the documentation of ergm.

Methods (by class)

  • ergm:

References

Raftery, A.E. and Lewis, S.M. (1995). The number of iterations, convergence diagnostics and generic Metropolis algorithms. In Practical Markov Chain Monte Carlo (W.R. Gilks, D.J. Spiegelhalter and S. Richardson, eds.). London, U.K.: Chapman and Hall.

This function is based on the coda package It is based on the the R function raftery.diag in coda. raftery.diag, in turn, is based on the FORTRAN program gibbsit written by Steven Lewis which is available from the Statlib archive.

See Also

ergm, network package, coda package, summary.ergm

Examples

## Not run: 
#
data(florentine)
#
# test the mcmc.diagnostics function
#
gest <- ergm(flomarriage ~ edges + kstar(2))
summary(gest)

#
# Plot the probabilities first
#
mcmc.diagnostics(gest)
#
# Use coda directly
#
library(coda)
#
plot(gest$sample, ask=FALSE)
#
# A full range of diagnostics is available
# using codamenu()
#

## End(Not run)

ergm

Fit, Simulate and Diagnose Exponential-Family Models for Networks

v3.11.0
GPL-3 + file LICENSE
Authors
Mark S. Handcock [aut], David R. Hunter [aut], Carter T. Butts [aut], Steven M. Goodreau [aut], Pavel N. Krivitsky [aut, cre] (<https://orcid.org/0000-0002-9101-3362>), Martina Morris [aut], Li Wang [ctb], Kirk Li [ctb], Skye Bender-deMoll [ctb], Chad Klumb [ctb], Michał Bojanowski [ctb], Ben Bolker [ctb]
Initial release
2020-10-14

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.