Need to kill some time, so thought I'd Opine.

Given the intent, as I understood it... to extract components from a quantile 
regression (rq) object similar to how one might extract effects from an lm 
object.
 
Since it seems effects() is not implemented for rq, here are some alternative 
approaches to achieve similar functionality or extract useful information from 
the quantile regression model:

1. Extracting Coefficients. Use the coef() function to extract the coefficients 
of the quantile regression model. This is similar to extracting the effects in 
a linear model.

> coef(qm.9)

This will return the estimated coefficients for the 0.9 quantile.

2. Extracting Fitted Values. To get the fitted values from the quantile 
regression model, use: 

> fitted(qm.9)

This gives the fitted values for the quantile regression model, similar to what 
you'd see in an lm() model.

3. Extracting ResidualsResiduals from the quantile regression can be extracted 
using the resid() function: 

> resid(qm.9)

This gives the residuals for the 0.9 quantile regression model, which can be a 
useful diagnostic for checking model fit.

4. Manually Calculating "Effects".    While effects() is not available, you can 
manually calculate effects by examining the design matrix and the coefficients. 
If the term "effects" refers to the influence of different covariates in the 
model, these can be assessed by looking at the coefficients themselves and 
their impact on the fitted values.

5. Using the summary() Function.        The summary() function for rq objects 
provides detailed information about the quantile regression fit, including 
coefficient estimates, standard errors, and statistical significance:

> summary(qm.9)

This can give a more comprehensive understanding of how covariates are 
contributing to the model. 

6. Working with Design Matrices.            If you need the design matrix for 
further custom calculations, you can extract it using: 

> model.matrix(qm.9)                 

 This returns the matrix of predictor variables, which you can then use to 
manually compute the "effects" of changes in the predictors.

7. Explore Partial Effects with predict(). The predict() function can help you 
assess how changes in predictor values affect the outcome. For instance, to 
predict values at specific points in the design space, you can use: 

> predict(qm.9, newdata = data.frame(your_new_data))

8. Bootstrapping to Examine Variability. If you want to assess variability in 
the effects of predictors, you could use bootstrapping. The boot.rq() function 
in the quantreg package allows you to bootstrap the quantile regression 
coefficients, giving insight into the variability of the estimated "effects."

Example:

> boot_results <- boot.rq(y ~ X, tau = 0.9, data = your_data, R = 1000)

> summary(boot_results)

9.Interaction or Additive Effects (If Applicable). If you're trying to capture 
interaction or additive effects, you might need to specify interaction terms 
directly in your formula and then inspect the coefficients for these terms. 
Quantile regression will estimate these coefficients in the same manner as 
linear regression but specific to the quantile of interest.

In conclusion, while effects() is not available for quantile regression, the 
combination of coef(), fitted(), resid(), model.matrix(), and summary() 
provides the main components of a quantile regression model that should provide 
similar insights to what effects() provides for linear models.

Forgive any typos please... I'm on a mobile device.

Kind regards,
Gregg Powell


Sent from Proton Mail Android


-------- Original Message --------
On 06/09/2024 01:37, Koenker, Roger W <rkoen...@illinois.edu> wrote:

>  Apologies,  forgot to copy R-help on this response.
>  
>  Begin forwarded message:
>  
>  
>  From: Roger Koenker <rkoen...@illinois.edu>
>  Subject: Re: [R] effects() extractor for a quantile reqression object: error 
> message
>  Date: September 6, 2024 at 8:38:47 AM GMT+1
>  To: "Christopher W. Ryan" <cr...@binghamton.edu>
>  
>  Chris,
>  
>  This was intended to emulate the effects component of lm() fitting, but was 
> never implemented.  Frankly, I don’t quite see on first glance how this works 
> for lm() — it seems to be (mostly) about situations where X is not full rank 
> (see lm.fit) and I also never bothered to implement rq for X that were not 
> full rank.
>  
>  Roger
>  
>  
>  On Sep 6, 2024, at 3:50 AM, Christopher W. Ryan via R-help 
> <r-help@r-project.org> wrote:
>  
>  I'm using quantreg package version 5.98 of 24 May 2024, in R 4.4.1 on
>  Linux Mint.
>  
>  The online documentation for quantreg says, in part, under the
>  description of the rq.object, "The coefficients, residuals, and effects
>  may be extracted by the generic functions of the same name, rather than
>  by the $ operator."
>  
>  I create an rq object for the 0.9 quantile, called qm.9
>  
>  effects(qm.9)
>  
>  yields, the error message, " effects(qm.9)
>  Error in UseMethod("effects") :
>  no applicable method for 'effects' applied to an object of class "rq"
>  
>  I'm confused. Appreciate any suggestions. Thanks.
>  
>  --Chris Ryan
>  
>  ______________________________________________
>  R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>  
> https://urldefense.com/v3/__https://stat.ethz.ch/mailman/listinfo/r-help__;!!DZ3fjg!8EOq_-vshoZYLg-FZREULmFkpvaXrZ6aw5ABLzjX4aq3XNvoDxGipcY73SPgiBQasfWdncPj7J2odYZKU3BD$
>  PLEASE do read the posting guide 
> https://urldefense.com/v3/__https://www.R-project.org/posting-guide.html__;!!DZ3fjg!8EOq_-vshoZYLg-FZREULmFkpvaXrZ6aw5ABLzjX4aq3XNvoDxGipcY73SPgiBQasfWdncPj7J2odY7Gv6_Z$
>  and provide commented, minimal, self-contained, reproducible code.
>  
>  
>  
>       [[alternative HTML version deleted]]
>  
>  ______________________________________________
>  R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>  https://stat.ethz.ch/mailman/listinfo/r-help
>  PLEASE do read the posting guide https://www.R-project.org/posting-guide.html
>  and provide commented, minimal, self-contained, reproducible code.
>  

Attachment: signature.asc
Description: OpenPGP digital signature

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide https://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to