contour_matrix: Produce a matrix of contours plots from a data array

Description Usage Arguments Value Notes See Also Examples

View source: R/plot_contour.R

Description

contour_matrix generates an M*M matrix of scatter/density plots.

Given an array of data with M columns (variables) and N rows (observations), produce a matrix of plots showing contours for each pair of parameters. The pairs() function shows a matrix of scatter plots for each pair of variables, here the scatter plots are replaced by contour plots. The contours are produced by using MASS:kde2d to produce a 2D Gaussian kernal density estimate, and finding the contours that encolse a fraction (prob) of the total density.

Usage

1
2
3
4
5
6
7
contour_matrix(theta, ranges = NULL, cex = 1, prob.levels = c(0.9,
  0.95), labels = colnames(theta), upper = NA, dot.level = NULL,
  breaks = 30, smooth1d = TRUE, smooth2d = TRUE, npix = 100,
  cex.lab = 1, cex.axis = 1, prob1d = NULL, sigma = FALSE,
  jittr = FALSE, thin = NULL, pch = 1, col = "black",
  plot.image = FALSE, plot.1dlines = TRUE, fill.col = "steelblue3",
  ...)

Arguments

theta

(array) N by M array of parameter values

ranges

(array) M by 2 array of ranges for the plots

cex

(float) character expansion factor.

prob.levels

(float) probability levels, e.g. to plot contours enclosing 90% and 95% of the mass on 2D distributions

labels

(array of strings) names of the variables

upper

(string) plot also in upper-right triangle. See notes.

dot.level

(integer) draw dots outside of which contour? (1,2,...)

breaks

(integer) how many bins for 1D histograms

smooth1d

(logical) plot smoothed distributions, rather than histograms on the leading diagonal?

smooth2d

(logical) use smooth, kernel density estimates, rather than 2D histograms?

npix

(integer) use npix*npix grid of pixels for computing 2D smoothed distributions (resolution of contour maps)

cex.lab

(float) expansion factor for axis labels.

cex.axis

(float) expansion factor for axis names.

prob1d

(float array) probability levels at which to mark intervals on 1D distributions, e.g. c(0.683, 0.90).

sigma

(logical) are probability levels prob1d and prob.levels given in terms of sigmas? (If FALSE - the default - then these are probabilities.)

jittr

(logical) add 'jitter' to points to reduce overlap.

thin

(integer) a factor by which to 'thin out' data input data i.e. plot only a fraction 1/thin of the data points.

col

(string) colour of the data points.

plot.image

(logical) Plot a colour image underneath the contours?

plot.1dlines

(logical) Mark intervals on 1D plots (histogram/density)?

fill.col

(string) Colour to use under the histogram.

...

(anything) any other graphical keywords to be passed to plot(...)

Value

Array of the 1D intervals for each parameter, or NULL.

Notes

The input chain should be a list such as produced by gw_sampler or mh_sampler that contains the following:

theta

(array) n * ndim array of posterior samples n samples of ndim vectors of parameters

method

(string) name of MCMC method used

nchains

number of chains/walkers used

The upper parameter determines what is to be shown in the upper-right corner of the plot. The options are:

You may notice that the fraction of points plotted outside the dot.levels contour line is often smaller than prob.levels[dot.levels]. This is usually true for finite N and is a natural consequence of plotting contours that enclose a fraction of the smoothed density rather than a fraction of the points.

See Also

gw_sampler, mh_sampler, get_levels2d, get_levels1d, interp_image, hist2d, plot_density, plot_density_contours

Examples

1
2
3
4
5
6
7
8
9
n <- 10000
x <- rchisq(n, df=2)
y <- x + rnorm(n)
z <- rnorm(n, sd=1)
dat <- cbind(x,y,z)
contour_matrix(dat, smooth1d=TRUE)
contour_matrix(dat, prob.levels=c(1,2), cex=0.5, npix=100, sigma=TRUE,
          dot.level=2, prob1d=c(1, 2), smooth1d=TRUE, cex.lab=1.3,
          plot.1dlines = TRUE)

svdataman/tonic documentation built on Aug. 2, 2019, 3:21 p.m.