## 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