Denis Chabot
2006-Feb-05 00:54 UTC
[R] how to extract predicted values from a quantreg fit?
Hi, I have used package quantreg to estimate a non-linear fit to the lowest part of my data points. It works great, by the way. But I'd like to extract the predicted values. The help for predict.qss1 indicates this: predict.qss1(object, newdata, ...) and states that newdata is a data frame describing the observations at which prediction is to be made. I used the same technique I used to extract predicted values of GAM fits with mgcv package: if I fit a GAM using x as the x variable on which I smooth, I then create such a dataframe like this MyX <- data.frame(x=seq(-1,60)) This works fine with GAM (mgcv) but not with quantreg: > y <- rnorm(500, 10, 5) > x <- rep(seq(1,50,1), 10) > My.data <- data.frame(x, y) > My.x <- data.frame(x=seq(5,45)) > > fit <- rqss(y ~ qss(x, lambda=5), tau=0.05) > pred <- predict.qss1(fit, My.x) Could someone please help me creating a dataframe "newdata" that would satisfy predict.qss1? Thanks in advance, Denis Chabot
Dieter Menne
2006-Feb-06 08:37 UTC
[R] how to extract predicted values from a quantreg fit?
Denis Chabot <chabotd <at> globetrotter.net> writes: .... Quantreg package ....> But I'd like to extract the predicted values. The help for > predict.qss1 indicates this:..> predict.qss1(object, newdata, ...) > and states that newdata is a data frame describing the observations > at which prediction is to be made...> > > y <- rnorm(500, 10, 5) > > x <- rep(seq(1,50,1), 10) > > My.data <- data.frame(x, y) > > My.x <- data.frame(x=seq(5,45)) > > > > fit <- rqss(y ~ qss(x, lambda=5), tau=0.05) > > pred <- predict.qss1(fit, My.x) > > Could someone please help me creating a dataframe "newdata" that > would satisfy predict.qss1?Looks like quantreg has been reworked, but predict was not tested. Checking the code, I got a (hopefully) working solution pred <- predict.qss1(fit$qss[[1]]$xyz, My.x$x) but this follow neither convention nor documentation. Maybe you should contact the author of the package to provide an example in the documentation, which would have show the problem earlier. Dieter