1## Demo for a simple change point (broken-stick) problem
2
3x <- runif(200,0,10)
4u <- rnorm(200)/5
5y <- 1 + x - .5 * (x-3) * (x > 3) + u
6plot(y ~ x, cex= .5, col = "grey")
7
8
9z <- rqss(y ~ qss(x,lambda = 10), tau= .50)
10plot(z, col = "dark blue")
11
12#Now plot the fitted points and jump points in derivative
13
14eps <- 0.00001 # Zero Tolerance
15Nz <- abs(z$resid[1:200]) < eps
16Nj <- abs(z$resid[201:398]) > eps
17xx <- z$qss[[1]]$xyz[,1]
18yy <- z$coef[1] + z$qss[[1]]$xyz[,2]
19xj <- xx[3:200]
20yj <- yy[3:200]
21points(xx[Nz],yy[Nz],col="green")
22points(xj[Nj],yj[Nj],col="red")
23print(paste("Number of zero residuals:  ",sum(Nz)))
24print(paste("Number of jumps in slope:  ",sum(Nj)))
25legend(6,3,c("Derivative Jumps", "Zero residuals"),pch = "o", col=c("red","green"))
26