Learn R Programming

R2BayesX (version 0.1-2)

samples: Extract Samples of Coefficients and Variances

Description

Function to extract the samples generated with Markov chain Monte Carlo simulation.

Usage

samples(object, model = NULL, term = NULL, acf = FALSE, ...)

Arguments

object
an object of class "bayesx".
model
for which model the samples should be provided, either an integer or a character, e.g. model = "mcmc.model".
term
character or integer, the term for which samples should be extracted. Also samples of linear effects may be returned if available and term =
acf
if set to TRUE, the autocorrelation function of the samples will be provided.
...
further arguments passed to function acf, e.g. argument lag.max if acf = TRUE.

See Also

bayesx.

Examples

Run this code
## generate some data
set.seed(111)
n <- 200

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

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

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

## extract samples for the P-spline
sax <- samples(b, term = "sx(x)")
names(sax)

## plot coefficient samples
k <- ncol(sax)
par(mfrow = n2mfrow(k))
for(j in 1L:k)
  plot(sax[,j], type = "l")

## linear effects samples
samples(b, term = "linear-samples")

## for acf, increase lag
sax <- samples(b, term = "sx(x)", acf = TRUE, lag.max = 200)
names(sax)


## plot maximum autocorrelation 
## of all parameters
sax <- samples(b, term = c("linear-samples", "var-samples", "sx(x)"), 
  acf = TRUE, lag.max = 50)
names(sax)
matplot(y = apply(sax, 1, max), type = "h", 
  ylab = "ACF", xlab = "lag")

Run the code above in your browser using DataLab