Skip to content

Instantly share code, notes, and snippets.

@simon-anders
Last active September 14, 2018 14:14
Show Gist options
  • Save simon-anders/f135b894035b3bfbf6af0616257dda2f to your computer and use it in GitHub Desktop.
Save simon-anders/f135b894035b3bfbf6af0616257dda2f to your computer and use it in GitHub Desktop.
library( quantreg )
x <- runif( 1000, 0, 10 )
y <- 30*exp(-(x-5)^2) + rnorm(1000) + x*rnorm(1000)
plot( x, y )
fit <- rq( y ~ x + I(x^2), .9 )
xg <- seq( 0, 10, l=1000 )
lines( xg, predict( fit, data.frame( x=xg, `I(x^2)`=xg^2 ) ), col="red" )
mm <- cbind( 1, x, x^2 )
yfit <-
sapply( xg, function(xp) {
fit <- rq.wfit( mm, y, .9, dnorm( x, mean=xp, sd=2 ) )
fit$coefficients %*% c( 1, xp, xp^2 ) })
lines( xg, yfit, col="orange" )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment