[R] predicted values from rq

Roger Koenker roger at ysidro.econ.uiuc.edu
Tue Oct 14 15:24:51 CEST 2003


Matthew,

I intended to respond, but this got lost in the shuffle last weekend.
You are correct that there is no predict method for rq...this is
something that is on the todo list, but it required some thought
about what form this should take.  When I do this sort of thing
I use your generate predictions "by hand" using something like this

	X <- model.matrix(yourModelFormulaGoesHere)
	pred <- X %*% fit$coef[,1]

This presumes that you are using the default algorithm "br".
This is usually in a loop over the quantiles that I'm interested in.
I hope that this helps.

Roger

PS.  Generally help inquiries about packages are directed to maintainers
in the first instance and then to R-help in desperation.  This probably
helps explain there was no response.


url:	www.econ.uiuc.edu/~roger/my.html	Roger Koenker
email	rkoenker at uiuc.edu			Department of Economics
vox: 	217-333-4558				University of Illinois
fax:   	217-244-6678				Champaign, IL 61820

On Tue, 14 Oct 2003, Landis, R Matthew wrote:

> Dear statistics and R experts,
>
> I'm reposting the following message - I orginally posted it last Friday, and
> generated exactly no response.  I assume it got lost over the weekend
> (either that or it is just unbelievably obvious!).
>
> I would like to plot the predicted values from a quantile regression
> analysis (quantreg v.3.31; R v.1.7.1) so that I can evaluate the fit.
>
> I fit the model using something like:  fit.rq <- rq(growth ~ ht*spp*light,
> tau = 0.9)
>
> My response variable is tree growth (continuous), and my predictor variables
> are height (continuous), species (factor with 3 levels), and light (ordered
> factor with 3 levels).  I'd like to look at the relationship between growth
> and height separately for each combination of species and light.
>
> I would simply use 'predict()' as in lm, but unfortunately, there does not
> seem to be a predict method for rq objects (unless I am missing something?).
> I know how to extract coefficients from the rq object, and I've calculated
> predicted values by simply adding the relevant coefficients for a particular
> level of spp*light as:  intercept <- fit.rq$coef[1,1] + fit.rq$coef[3,1] +
> ...; slope <- fit.rq$coef[2,1] + fit.rq$coef[5,1] +...)  but this is slow
> and awkward to do for each of the 9 levels (not to mention different values
> of tau).  Plus, I would eventually like to do some non-linear fits, and then
> it will be even worse.  I'm sure there must be a way to do this with a
> matrix of coefficients, if only my poor memory of linear algebra didn't
> prevent me from seeing it.
>
> Is there a simple straightforward way to generate the predicted values
> without having to manually add up all the relevant coefficients for each
> level?  Or, even better, is predict.rq out there somewhere that I haven't
> found?  The help on rq objects does refer to it, but ?predict.rq doesn't
> turn up anything.
>
> Thanks for any help,
> Matt
>
> R. Matthew Landis, Ph.D.
> Dept. Biology
> Middlebury College
> Middlebury VT 05753
>
> tel. 802/443.3484
> fax.802/443.2072
>
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
>




More information about the R-help mailing list