if (FALSE) {
## 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)")
colnames(sax)
## plotting
plot(sax)
## linear effects samples
samples(b, term = "linear-samples")
## for acf, increase lag
sax <- samples(b, term = c("linear-samples", "var-samples", "sx(x)"),
acf = TRUE, lag.max = 200, coda = FALSE)
names(sax)
head(sax)
## plot maximum autocorrelation
## of all parameters
sax <- samples(b, term = c("linear-samples", "var-samples", "sx(x)"),
acf = TRUE, lag.max = 50, coda = FALSE)
names(sax)
matplot(y = apply(sax, 1, max), type = "h",
ylab = "ACF", xlab = "lag")
## example using multiple chains
b <- bayesx(y ~ sx(x), data = dat, chains = 3)
sax <- samples(b, term = "sx(x)")
plot(sax)
}
Run the code above in your browser using DataLab