cmu-delphi / epipredict

Tools for building predictive models in epidemiology.
https://cmu-delphi.github.io/epipredict/
Other
8 stars 9 forks source link

feat: expose "method" arg of quantile_reg #374

Closed dshemetov closed 3 weeks ago

dshemetov commented 1 month ago

Checklist

Please:

Change explanations for reviewer

Allows us to choose the fitting method used by quantilereg::rq.

Magic GitHub syntax to mark associated Issue(s) as resolved when this is merged into the default branch

dajmcdon commented 1 month ago

@dshemetov

  1. I think you need to add function documentation to get the check to pass.
  2. How key/timely is this change? I don't think it hurts anything, but I'm hoping that quantile regression will be implemented in tidymodels in the near future. (At which point we'll remove this function completely)
dshemetov commented 1 month ago
  1. Sounds good
  2. Not too important + I can run tests locally with this branch; do we have a sense for when tidymodels will receive the update?
dajmcdon commented 4 weeks ago

It'll be long enough that if you want this, we should merge. However, technically, you can already set method = "whatever":

library(epipredict) # dev branch
library(quantreg)

tib <- data.frame(y = rnorm(100), x1 = rnorm(100), x2 = rnorm(100))
rq_spec <- quantile_reg(quantile_levels = c(.1, .5, .9)) %>% 
  set_engine("rq") # default, method = "br"
translate(rq_spec) # what the call will look like
#> quantile reg Model Specification (regression)
#> 
#> Main Arguments:
#>   quantile_levels = c(0.1, 0.5, 0.9)
#> 
#> Computational engine: rq 
#> 
#> Model fit template:
#> quantreg::rq(formula = missing_arg(), data = missing_arg(), weights = missing_arg(), 
#>     tau = c(0.1, 0.5, 0.9), method = "br", na.action = stats::na.omit, 
#>     model = FALSE)

rq_other <- quantile_reg(quantile_levels = c(.1, .5, .9)) %>%
  set_engine(engine = "rq", method = "pfnb") # chosen arbitrarily
translate(rq_other) # what the call will look like
#> quantile reg Model Specification (regression)
#> 
#> Main Arguments:
#>   quantile_levels = c(0.1, 0.5, 0.9)
#> 
#> Engine-Specific Arguments:
#>   method = pfnb
#> 
#> Computational engine: rq 
#> 
#> Model fit template:
#> quantreg::rq(formula = missing_arg(), data = missing_arg(), weights = missing_arg(), 
#>     tau = c(0.1, 0.5, 0.9), method = "pfnb", na.action = stats::na.omit, 
#>     model = FALSE)

f <- fit(rq_other, formula = y ~ ., data = tib)
parsnip::extract_fit_engine(f)$call # to see what it called
#> quantreg::rq(formula = y ~ ., tau = ~c(0.1, 0.5, 0.9), data = data, 
#>     na.action = stats::na.omit, method = ~"pfnb", model = FALSE)

Created on 2024-09-06 with reprex v2.1.1

dshemetov commented 3 weeks ago

Oh huh, well that's good enough for my needs, but might as well merge this, since at least it will be a documented option? Either way, not a big deal.