If monotonicity is imposed, the quadratic B-spline basis functions are used. If the constraints include convexity (or concavity), the cubic B-spline basis functions are used.
The following code has arguments: type of shape constraint, x, y, k=#knots, and number of MCMC loops.
It returns the fit and point-wise confidence intervals at the x-values.
Here is an example implementation, fitting a monotone convex curve to a dataset generated from an exponential function.
For example, suppose we want to fit parallel increasing curves, so that a categorical covariate must be included in the smooth monotone regression. We construct k-1 dummy variables, where k is the number of levels of the covariate, and put these as columns in the matrix z. Note that the columns of z and the vector x must for a linearly independent set, and the one-vector must not be in the span of these vectors.
Here is an example implementation, fitting three monotone convex curves to a data set generate from an exponential function.