set.seed(123); nn <- 1000
kdata <- data.frame(x2 = sort(runif(nn)))
kdata <- transform(kdata, mylocat = 1 + 3 * x2,
myscale = 1)
kdata <- transform(kdata, y = rkoenker(nn, loc = mylocat, scale = myscale))
fit <- vglm(y ~ x2, koenker(perc = c(1, 50, 99)), data = kdata, trace = TRUE)
fit2 <- vglm(y ~ x2, studentt2(df = 2), data = kdata, trace = TRUE) # 'same' as fit
coef(fit, matrix = TRUE)
head(fitted(fit))
head(predict(fit))
# Nice plot of the results
plot(y ~ x2, data = kdata, col = "blue", las = 1,
sub = paste("n =", nn),
main = "Fitted quantiles/expectiles using Koenker's distribution")
matplot(with(kdata, x2), fitted(fit), add = TRUE, type = "l", lwd = 3)
legend("bottomright", lty = 1:3, lwd = 3, legend = colnames(fitted(fit)),
col = 1:3)
fit@extra$percentile # Sample quantiles
Run the code above in your browser using DataLab