Created
August 1, 2013 08:53
-
-
Save dbetebenner/6129683 to your computer and use it in GitHub Desktop.
Quantile regression with b-splines using R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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