plotsamples: Plot Sampling Path(s) of Coefficient(s) and Variance(s)

View source: R/plotsamples.R

plotsamplesR Documentation

Plot Sampling Path(s) of Coefficient(s) and Variance(s)

Description

This function plots the sampling paths of coefficient(s) and variance(s) stored in model term objects typically returned from function bayesx or read.bayesx.output.

Usage

plotsamples(x, selected = "NA", acf = FALSE, var = FALSE,
  max.acf = FALSE, subset = NULL, ...)

Arguments

x

a vector or matrix, where each column represents a different sampling path to be plotted.

selected

a character string containing the term name the sampling paths are plotted for.

acf

if set to TRUE, the autocorrelation function for each sampling path is plotted.

var

indicates whether coefficient or variance sampling paths are displayed and simply changes the main title.

max.acf

if set to TRUE, plotsamples will evaluate the maximum autocorrelation over all parameters of each sample.

subset

integer. An index which selects the coefficients for which sampling paths should be plotted.

...

other graphical parameters to be passed to plot and acf, e.g. argument lag.max if acf = TRUE. An argument ask controls the display when more than 12 sampling paths should be plotted.

Author(s)

Nikolaus Umlauf, Thomas Kneib, Stefan Lang, Achim Zeileis.

See Also

plot.bayesx, bayesx, read.bayesx.output.

Examples

## generate some data
set.seed(111)
n <- 500

## regressors
dat <- data.frame(x = runif(n, -3, 3))

## response
dat$y <- with(dat, 1.5 + sin(x) + rnorm(n, sd = 0.6))

## Not run: 
## estimate model
b <- bayesx(y ~ sx(x), data = dat)
summary(b)

## plot sampling path for
## the variance
plot(b, term = "sx(x)", which = "var-samples")

## plot sampling paths for 
## coefficients
plot(b, term = "sx(x)", which = "coef-samples")

## plot maximum autocorrelation of
## all sampled parameters of term s(x)
plot(b, term = "sx(x)", which = "coef-samples", max.acf = TRUE)

## extract samples of term sx(x)
sax <- as.matrix(samples(b, term = "sx(x)"))

## now use plotsamples
plotsamples(sax, selected = "sx(x)")

## some variations
plotsamples(sax, selected = "sx(x)", acf = TRUE)
plotsamples(sax, selected = "sx(x)", acf = TRUE, lag.max = 200)

## End(Not run)

R2BayesX documentation built on Oct. 20, 2023, 9:11 a.m.