2

I am running a quantile regression model on some data with one natural cubic spline, which needs to be monotonically decreasing (because it cannot physically increase at any point). To start with I used the ns() function from the splines package to achieve this but quickly found that it won't do (unsurprisingly). So I found the function mSpline from the package splines2 which is supposed to fit monotonic splines, but it also does not work. Below is an example of the two functions and how they fail on mtcars.

How can I achieve my goal of obtaining monotonically decreasing splines either with my approach or some other approach?

Bonus points if additional variables can be added to the model, which are not splined.

library(quantreg)
mod=rq(mpg~ns(hp,df=3),data=mtcars,tau=0.99)
mod=rq(mpg~mSpline(hp,df=3),data=mtcars,tau=0.99) #monotone

preds=predict(mod)

plot(mtcars$mpg~mtcars$hp)
points(preds~mtcars$hp,col=2,cex=1,pch=16)
user2974951
  • 9,535
  • 1
  • 17
  • 24

1 Answers1

1

First part of your question: Quantile Regression with smoothing splines and monotonicity restrictions can be implemented using splineDesign from the Splines package together with quantreg (option method="fnc" for the rq-function). R Code is available from the supplement to https://doi.org/10.1002/jae.2347 in the open archive http://qed.econ.queensu.ca/jae/datasets/haupt002/

Second part of your question: the implemented model is additive and allows to add further splines, parametric, or semiparametric components.