ggpmisc icon indicating copy to clipboard operation
ggpmisc copied to clipboard

Add support for `lqs()` in `stat_poly_eq()` and `stat_poly_line()`

Open aphalo opened this issue 2 years ago • 8 comments

Currrently we support lm() and rlm() and any other function that returns an object of class "lm". MASS::lqs() with method lts is a useful alternative that could be also supported rather easily, I think.

aphalo avatar Jun 21 '23 10:06 aphalo

Today, I added support for gls() from package 'nlme'.

aphalo avatar Apr 13 '25 20:04 aphalo

  • [x] Revise stat_poly_line()
  • [x] Revise stat_ploy_eq()
  • [x] Revise function documentation
  • [x] Revise article
  • [x] Test with existing unit tests
  • [x] Add new unit tests

aphalo avatar Apr 13 '25 22:04 aphalo

For resistant regression, any thoughts on how difficult it would be to identify on the plot, eg with a different colour, which observations are assumed to be outliers?

markbneal avatar Apr 15 '25 20:04 markbneal

With robust regression with 'MASS::rlm()' weights can be used to colour the residuals. This is also how 'wle' used to do this. 'wle' seems to have been archived for some time in CRAN. The third example in the section "stat_fit_deviations" shows how I achieved this with 'MASS::rlm()'. I have found this way of highlighting useful in teaching. However, currently, this approach does not work with lqs(). There are no weights in the fitted model object.

aphalo avatar Apr 16 '25 15:04 aphalo

So they don't report weights, but implicitly the weights are zero or one. Worth easing an issue for mass?

markbneal avatar Apr 17 '25 10:04 markbneal

I am not sure. MASS has been stable for so many years... you could try, though. In such a case, I think the way to go would be the approach used in 'robustbase', implementing weights() with a type parameter. I haven't yet studied 'robustbase::lmrob' in enough detail to know if it can be used in place of both rlm() and lqs(). The defaults seem different, at least. weights() is not as widely available as coefficients(), residuals(), fitted() and predict(). For example, there is no specialization of weights() for gls().

aphalo avatar Apr 18 '25 09:04 aphalo

Interesting, as weights can be both an input and an output of the modelling process, a single name called weights seems unhelpful. posterior_weights is not a great nsme for the second case, as it implies a Bayesian method. Thoughts?

markbneal avatar Apr 18 '25 15:04 markbneal

@markbneal robustbase::lmrob() calls them robustness.weights and robustbase::ltsReg() calls them lts.weights. In the development version of 'ggpp' I am using robustness.weights but I am not particularly happy with this choice. What do you think?Would computed.weights be understandable and with no additional implied meaning related to the procedure used?

Did you notice that I also wrote some comments in #71 about robustbase::ltsReg() as a possible replacement for lqs()?

aphalo avatar Apr 20 '25 20:04 aphalo