crossplot: Bivariate Plot of Posterior Densities

View source: R/bivariate.R

crossplotR Documentation

Bivariate Plot of Posterior Densities

Description

Bivariate plot of the posterior densities of corresponding vectors of parameter nodes. Three plotting methods are provided, that may be overlayed if desired.

  • If drawcross == TRUE, caterpillar-like plots will be produced, with quantile intervals in the x- and y- directions.

  • If drawx == TRUE, caterpillar-like plots will be produced, but rotated along the standardized principal component axes. This may be useful to draw if correlation is present.

  • If drawblob == TRUE, smoothed polygons will be produced, each containing approximately ⁠ci=⁠ x100% of the associated MCMC samples.

All methods can overlay multiple bars or polygons, depending on the length of ⁠ci=⁠.

Usage

crossplot(
  dfx,
  dfy = NULL,
  p = NULL,
  col = 4,
  drawcross = TRUE,
  drawx = FALSE,
  drawblob = FALSE,
  blobres = NULL,
  blobsmooth = NULL,
  outline = FALSE,
  ci = c(0.5, 0.95),
  lwd = 1,
  mean = FALSE,
  link = FALSE,
  linklwd = 1,
  labels = FALSE,
  labelpos = NULL,
  labelcex = 0.7,
  whichx = NULL,
  rowx = NULL,
  columnx = NULL,
  whichy = NULL,
  rowy = NULL,
  columny = NULL,
  xlab = NULL,
  ylab = NULL,
  main = NULL,
  xlim = NULL,
  ylim = NULL,
  transformx = c("none", "exp", "expit"),
  transformy = c("none", "exp", "expit"),
  add = FALSE,
  ...
)

Arguments

dfx

Output object returned from jagsUI::jags(); or alternately, two-dimensional data.frame or matrix in which parameter node element is given by column and MCMC iteration is given by row. A vector may also be used, that expresses MCMC iterations of a single parameter node. If used with ⁠dfy=⁠, this will be plotted in the x-direction.

dfy

Optionally, a two-dimensional data.frame or matrix in which parameter node element is given by column and MCMC iteration is given by row. A vector may also be used, that expresses MCMC iterations of a single parameter node. If used, this will be plotted in the y-direction.

p

Vector of parameter names, if input to dfx is a jagsUI output object. If used, this must be of length 2.

col

Color for plotting, or recyclable vector of colors. Defaults to 4. If col == "random", rcolors will be used to generate a random vector of colors.

drawcross

Whether to draw quantile bars in the x- and y-directions. Defaults to TRUE.

drawx

Whether to draw quantile bars along the standardized principal component axes. Defaults to FALSE.

drawblob

Whether to draw smoothed quantile polygons. Defaults to FALSE.

blobres

Optional tuning parameter for drawing quantile polygons, and corresponds to the number of polygon vertices. If the default NULL is accepted, the function will supply a value based on the number of MCMC samples.

blobsmooth

Optional tuning parameter for drawing quantile polygons, and corresponds to half the number of polygon vertices used for local smoothing. If the default NULL is accepted, the function will supply a value based on the number of MCMC samples and the number of vertices.

outline

Whether to draw quantile polygons as lines rather than filled regions. Defaults to FALSE.

ci

Vector of intervals to overlay. Defaults to 50 percent and 95 percent.

lwd

Base line width for plotting. Defaults to 1.

mean

Whether to include points for means. Defaults to FALSE.

link

Whether to link medians in sequence. Defaults to FALSE.

linklwd

Line width to use for linking. Defaults to 1.

labels

Whether to add labels, or a vector of labels to add. Defaults to FALSE.

labelpos

Optionally, an argument to pos in text for labels. Defaults to NULL.

labelcex

Optional character expansion for labels. Defaults to 0.7.

whichx

Element to subset for x, if only one element of a vector of parameter nodes is desired for plotting.

rowx

Row to subset for x, in the case of a 2-d matrix of parameter nodes in-model.

columnx

Column to subset for x, in the case of a 2-d matrix of parameter nodes in-model.

whichy

Element to subset for x, if only one element of a vector of parameter nodes is desired for plotting.

rowy

Row to subset for y, in the case of a 2-d matrix of parameter nodes in-model.

columny

Column to subset for y, in the case of a 2-d matrix of parameter nodes in-model.

xlab

X-axis label. If the default NULL is accepted, this will be drawn automatically.

ylab

Y-axis label. If the default NULL is accepted, this will be drawn automatically.

main

Plot title.

xlim

X-axis limits. If the default (NULL) is accepted, the limits will be determined automatically.

ylim

Y-axis limits. If the default (NULL) is accepted, the limits will be determined automatically.

transformx

Should the x-axis be (back)transformed? Options are "exp", indicating exponential, or "expit", indicating inverse-logit. Defaults to "none", indicating no transformation. Note: if transformx="exp"is used, consider adding additional plotting argument log="x" or log="xy".

transformy

Should the y-axis be (back)transformed? Options are "exp", indicating exponential, or "expit", indicating inverse-logit. Defaults to "none", indicating no transformation. Note: if transformy="exp"is used, consider adding additional plotting argument log="y" or log="xy".

add

Whether to add to existing plot

...

additional plotting arguments

Value

NULL

Author(s)

Matt Tyers

See Also

caterpillar, pairstrace_jags

Examples

## basic functionality with cross geometry
crossplot(SS_out, p=c("trend","rate"))

## default labels
crossplot(SS_out, p=c("trend","cycle"), labels=TRUE)

## showing:
## - link lines
## - blob geometry (smoothed confidence polygons)
## - random colors with col="random"
crossplot(SS_out, p=c("trend","cycle"),
          labels=SS_data$x, labelpos=1, link=TRUE, drawblob=TRUE,
          col="random")

## adding x geometry and showing usage with a single vector element (41)
crossplot(SS_out, p=c("trend","cycle"),
          whichx=41, whichy=41,
          drawblob=TRUE, drawx=TRUE)

## single vectors (or data.frames or 2d matrices) can also be used
xx <- SS_out$sims.list$trend[,41]
yy <- SS_out$sims.list$cycle[,41]

par(mfrow = c(2, 2))
plot(xx, yy, col=adjustcolor(1, alpha.f=.1), pch=16, main="cross geometry")
crossplot(xx, yy, add=TRUE, col=1)
plot(xx, yy, col=adjustcolor(1, alpha.f=.1), pch=16, main="x geometry")
crossplot(xx, yy, add=TRUE, col=1,
          drawcross=FALSE, drawx=TRUE)
plot(xx, yy, col=adjustcolor(1, alpha.f=.1), pch=16, main="blob geometry")
crossplot(xx, yy, add=TRUE, col=1,
          drawcross=FALSE, drawblob=TRUE)
plot(xx, yy, col=adjustcolor(1, alpha.f=.1), pch=16, main="blob outlines")
crossplot(xx, yy, add=TRUE, col=1,
          drawcross=FALSE, drawblob=TRUE, outline=TRUE)

jagshelper documentation built on Oct. 22, 2024, 1:06 a.m.