traceplot: History Plot of Selected Variables in the Model

Description Usage Arguments Details Examples

View source: R/plot.R

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

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

Arguments

x

Object of class bugs or pbugs.

var.names

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

var.pattern

Character. Regular expression (as used in grep) for selecting 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. Equal to c(3,4) by default.

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
  ## 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")
    result    <- pbugs(
      data               = bugs_data,
      inits              = bugs_init,
      parameters.to.save = bugs_pars,
      model.file         = bugs_model,
      n.thin             = 1,
      n.chains           = 4
    )
    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 Nov. 11, 2019, 2:10 p.m.