# NOT RUN {
set.seed(123456)
# Generate AR(1) data with rho = 0.9
n = 128
data = arima.sim(n, model = list(ar = 0.9))
data = data - mean(data)
# Run MCMC (may take some time)
mcmc = gibbs_bspline(data, 10000, 5000)
require(beyondWhittle) # For psd_arma() function
freq = 2 * pi / n * (1:(n / 2 + 1) - 1)[-c(1, n / 2 + 1)] # Remove first and last frequency
psd.true = psd_arma(freq, ar = 0.9, ma = numeric(0), sigma2 = 1) # True PSD
plot(mcmc) # Plot log PSD (see documentation of plot.psd)
lines(freq, log(psd.true), col = 2, lty = 3, lwd = 2) # Overlay true PSD
# }
Run the code above in your browser using DataLab