# \dontshow{
# Simulate data
set.seed(1)
n <- 100
x <- runif(n)
y <- log(1 + 10*x) + rald(n, scale = 0.5, p = 0.5)
# MCMC parameters
mcmc <- list(nblow = 1000, smcmc = 1000, nskip = 1)
# Fit the model with default priors and mcmc parameters
fout <- bsaq(y ~ fs(x), p = 0.5, nbasis = 30, mcmc = mcmc, shape = "Free")
# fitted values
fit <- fitted(fout)
# plots
plot(fit)
# }
if (FALSE) {
######################
# Increasing-concave #
######################
# Simulate data
set.seed(1)
n <- 200
x <- runif(n)
y <- log(1 + 10*x) + rald(n, scale = 0.5, p = 0.5)
# Number of cosine basis functions
nbasis <- 50
# Fit the model with default priors and mcmc parameters
fout1 <- bsaq(y ~ fs(x), p = 0.25, nbasis = nbasis,
shape = 'IncreasingConcave')
fout2 <- bsaq(y ~ fs(x), p = 0.5, nbasis = nbasis,
shape = 'IncreasingConcave')
fout3 <- bsaq(y ~ fs(x), p = 0.75, nbasis = nbasis,
shape = 'IncreasingConcave')
# fitted values
fit1 <- fitted(fout1)
fit2 <- fitted(fout2)
fit3 <- fitted(fout3)
# plots
plot(x, y, lwd = 2, xlab = 'x', ylab = 'y')
lines(fit1$xgrid, fit1$wbeta$mean[1] + fit1$fxgrid$mean, lwd=2, col=2)
lines(fit2$xgrid, fit2$wbeta$mean[1] + fit2$fxgrid$mean, lwd=2, col=3)
lines(fit3$xgrid, fit3$wbeta$mean[1] + fit3$fxgrid$mean, lwd=2, col=4)
legend('topleft', legend = c('1st Quartile', '2nd Quartile', '3rd Quartile'),
lwd = 2, col = 2:4, lty = 1)
}
Run the code above in your browser using DataLab