# NOT RUN {
# Example 1
n <- 100
x <- runif(n=n,min=0,max=5)
y <- 1 + 1.5*x+ .5*x*rnorm(n)
plot(x,y, main="Scatterplot and Quantile Regression Fit", xlab="x", cex=.5, col="gray")
for (i in 1:5) {
if (i==1) p = .05
if (i==2) p = .25
if (i==3) p = .50
if (i==4) p = .75
if (i==5) p = .95
fit = Brq(y~x,tau=p,runs=2000, burn=500)
# Note: runs =11000 and burn =1000
abline(a=mean(fit$c[1]),b=mean(fit$c[2]),lty=i,col=i)
}
abline( lm(y~x),lty=1,lwd=2,col=6)
legend(x=-0.30,y=max(y)+0.5,legend=c(.05,.25,.50,.75,.95,"OLS"),lty=c(1,2,3,4,5,1),
lwd=c(1,1,1,1,1,2),col=c(1:6),title="Quantile")
# Example 2
#data(salary)
#attach(salary)
# y=b0+b1x1+b2x2
#plot(Years, Salaries,cex=0.5, ylab="Salaries", xlab="Years",main="",col="gray")
#for(p in c(0.05, 0.25, 0.50, 0.75, 0.95)){
#xseq <- seq(min(Years), max(Years), len=5000)
#fit <- Brq( Salaries~Years+I(Years^2),tau=p, runs=5000, burn=1000)
#lines(xseq, fit$coef %*% rbind(1, xseq,xseq^2),lty=1, lwd=1.5, col="blue")
#}
# }
Run the code above in your browser using DataLab