traceplot: History Plot of Selected Variables in the Model

View source: R/plot.R

traceplotR Documentation

History Plot of Selected Variables in the Model

Description

History plot for some variables in a bugs or pbugs object. This function allows also automatically plotting those variables with deficient converge according to the effective sample size (Neff) & Brooks-Gelman-Rubin (Rhat) criteria.

Usage

traceplot(x, var.pattern = character(), var.names = character(),
  not.converged = FALSE, convergence.criteria = c(100, 1.1), mfrow = NULL,
  max.devices = 10, ...)

Arguments

x

Object of class bugs or pbugs.

var.pattern

Character. Regular expression (as used in grep) for selecting the variables to be plotted.

var.names

Character. Vector with the literal names of the variables to be plotted.

not.converged

Logical, default: FALSE. Plot just those variables with deficient convergence?

convergence.criteria

Numeric vector of length 2 with thresholds for the Neff and Rhat criteria. If not.converged is set to TRUE, all those variables with Neff below or Rhat above the set thresholds will be plotted. The default thresholds are fixed to 100 for Neff and 1.1 for the Rhat criteria.

mfrow

A vector of length 2, specifying the number of rows and columns on each device. Default NULL (tries to accommodate the number of parameters using mfrow values from c(1, 1) to c(4, 4)).

max.devices

Maximum number of devices to generate containing the requested history plots. Equal to 10 by default.

...

Additional arguments to be passed to plot function.

Details

If length(var.names) == 0 & length(var.pattern) == 0 & !not.converged, history plots will be plotted for all the variables in the corresponding bugs or pbugs object.

Examples

  ## Not run: 
    library(pbugs)
    data(sample_df)
    bugs_model <- function() {
      for (i in 1:N) {
        y[i] ~ dbern(pi[i])
        logit(pi[i]) <- beta[1] + beta[2] * x1[i] + beta[3] * x2[i] + beta[4] * x3[i]
      }
      for (j in 1:4) {
        beta[j] ~ dflat()
      }
    }
    bugs_data <- with(
      sample_df,
      list(y = y, x1 = x1, x2 = x2, x3 = x3, N = length(y))
    )
    bugs_init <- function() list(beta = rnorm(4, sd = .5))
    bugs_pars <- c("beta", "pi")
    traceplot(result, var.names = c("beta[1]", "beta[3]"))
    traceplot(result, var.pattern = "beta")
    traceplot(result, var.pattern = "beta|pi\\[1\\d?\\]")
  
## End(Not run)


fisabio/pbugs documentation built on Jan. 28, 2024, 5:13 a.m.