jacob-long / jtools

Tools for summarizing/visualizing regressions and other helpful stuff
https://jtools.jacob-long.com
GNU General Public License v3.0
162 stars 22 forks source link

Summary of quantile regression using conquer algorithm fails #141

Closed mattmoo closed 1 month ago

mattmoo commented 1 year ago

In summ.rq(), there is a point where it is assumed that there is a p column in the fourth column of the coefficients. For the recently implemented "conquer" algorithm, this is not the case.

library(jtools)
library(quantreg)

n = 2500
dat = data.table(
  x = runif(min = 0, max = 1, n = n),
  y = factor(sample(c('A','B'), size = 100, replace = TRUE))
)
dat[, z := x * 0.6 + 0.3 * (y == 'B') + rnorm(n = n, mean = 0, sd = 1)]

# "conquer" QR method
qr <- quantreg::rq(z ~ x + y, data=dat, tau = 0.5, method = 'conquer')

jtools::export_summs(qr)

It can be worked around with a check at line 166 of summ_rq.R:

    if (ncol(coef(sum)) == 4) {
      ps <- coef(sum)[,4]
    } else if  (ncol(coef(sum)) == 3) {
      ps = rep(1, length(ts))
    }

Just calling the p-value 1, so it doesn't highlight anything, I'm sure that it's not the best solution.

jacob-long commented 8 months ago

In trying to probe this, I'm unable to even get the code to run due to an error occurring within the conquer package.

library(jtools)
library(quantreg)
library(data.table)

n = 2500
dat = data.table(
  x = runif(min = 0, max = 1, n = n),
  y = factor(sample(c('A','B'), size = 100, replace = TRUE))
)
dat[, z := x * 0.6 + 0.3 * (y == 'B') + rnorm(n = n, mean = 0, sd = 1)]

qr <- quantreg::rq(z ~ x + y, data=dat, tau = 0.5, method = 'conquer')
#> Error in match.arg(kernel) : 'arg' must be of length 1

This is true for all examples I can test fitting rq models. Could be an issue with my configuration, but for now I'm reticent to try to fix the underlying bug with jtools when I can't actually produce an rq model without p-values to test my work.

mattmoo commented 8 months ago

Thanks Jacob, I'm getting that error now too. Evidently it's not a very mature technique (and I had to ditch it for other reasons).