Skip to content

Instantly share code, notes, and snippets.

@dbetebenner
Created August 1, 2013 08:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dbetebenner/6129683 to your computer and use it in GitHub Desktop.
Save dbetebenner/6129683 to your computer and use it in GitHub Desktop.
Quantile regression with b-splines using R
require(splines)
require(quantreg)
### Create some data
x <- rnorm(100, mean=50, sd=10)
noise <- rnorm(100, sd=5)
y <- x + noise
### Basic scatterplot of data
plot(x,y)
### The SGP function creates knots at the 0.2, 0.4, 0.6, and 0.8 quantile of the provided data and the
### boundaries by extending the range by 5 percent
rq.1 <- rq(y ~ bs(x, knots=quantile(x, prob=c(0.2, 0.4, 0.6, 0.8)), Boundary.knots=extendrange(x, f=0.05)))
### Summary of results
summary(rq.1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment