data(Data.Incomes)
PLR <- Lorenz.Reg(Income ~ ., data = Data.Incomes,
penalty = "SCAD", eps = 0.01)
y <- PLR$y
index <- predict(PLR)
# Default method where the first step is obtained with loess()
Rearrangement.estimation(y = y, index = index, method = "loess")
# Custom method, where the first step is obtained with ksmooth()
# ksmooth() lacks from a separation between fitting and predicting interfaces
ksmooth_method <- list(
fit_fun = function(y, x, ...) {
list(y = y, x = x, args = list(...))
},
predict_fun = function(fit, newdata) {
if(missing(newdata)){
x.points <- fit$x
} else {
x.points <- newdata[,1]
}
o <- order(order(x.points))
yhat <- do.call(ksmooth, c(list(x = fit$x, y = fit$y, x.points = x.points), fit$args))$y
yhat[o]
}
)
Rearrangement.estimation(y = y, index = index, method = ksmooth_method, bandwidth = 0.1)
Run the code above in your browser using DataLab