https://github.com/cran/quantreg
Tip revision: e71c994d653adbe4d49f0fed4cb9d80ae22d8ce1 authored by Roger Koenker on 24 June 2012, 00:00:00 UTC
version 4.81
version 4.81
Tip revision: e71c994
hinged.R
# A Demo of simple bivariate rqss fitting of a hinge function
require(quantreg)
## Make sure the demo does not ``die'' when rgl is not available:
do.rgl <- interactive() && require(rgl)
#generate the data
n <- 1000
x <- runif(n)
y <- runif(n)
z <- -abs(x-y)
### Make an initial quite rough fit of the data
fit <- rqss(z ~ qss(cbind(x,y),lambda = .005))
print(summary(fit)$penalty)
if(do.rgl) {
plot(fit, render = "rgl")
cat("Now orient the plot as desired:",
"Resize window,",
"mouse button 1 to change viewpoint,",
"mouse button 2 to zoom,",
"and hit return when ready",sep="\n")
scan()
rgl.bg(color="8")
cat("To try another value of lambda:",
"Type a positive number",
"To quit hit return", sep="\n")
repeat{
cat("lambda: ")
lam <- scan(what = double(1))
if(length(lam)>0){
fit <- rqss(z ~ qss(cbind(x,y),lambda = lam))
rgl.clear()
plot(fit, render = "rgl")
} else
break
}
} else {
if(!interactive()) pdf(file = "hinge-demo.pdf")
plot(fit)
}