Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rqPen changes in version 3.1.x - rqPen::rq.lasso.fit() and rqPen::rq.nc.fit() should be rqPen::rq.pen() #1340

Open
ghost opened this issue Jul 3, 2023 · 0 comments

Comments

@ghost
Copy link

ghost commented Jul 3, 2023

Error sources:

Error description:

The current fit functions for models using the rqPen package ("rqlasso" and "rqnc" are using the rqPen 3.0 fitting method:

# From rqlasso.R
fit = function(x, y, wts, param, lev, last, classProbs, ...) {
  rqPen::rq.lasso.fit(as.matrix(x), y, lambda = param$lambda, ...)
}
# From rqnc.R
fit = function(x, y, wts, param, lev, last, classProbs, ...) {
  rqPen::rq.nc.fit(as.matrix(x), y,
                          lambda = param$lambda,
                          penalty = as.character(param$penalty), ...)
}

(From rqPen NEWS, 2023-02-20):
Older functions that were deprecated in rqPen 3.0 are no longer exported. Big changes are rq.pen() should be used instead of rq.lasso.fit() or rq.nc.fit(). Similarly rq.group.pen() should be used instead of rq.group.fit(). Finally rq.pen.cv() and rq.group.pen.cv() should be used instead of cv.rq.pen() and cv.rq.group.pen().

Reproducible Example:


set.seed(123) # for reproducibility

# Create data
n <- 100 # number of observations
p <- 5 # number of predictors

# Generate predictors
X <- matrix(rnorm(n*p), n, p)
colnames(X) <- paste0("X", 1:p)

# Generate response variable
beta <- rnorm(p)
y <- X %*% beta + rnorm(n)

# Combine predictors and response into a data.frame
df <- data.frame(y = y, X)

# Fit using quantile regression with LASSO regularization 
fit <- caret::train(
    y ~ ., 
    data = df, 
    method = "rqlasso", # Also "rqnc", which also uses `rqPen::rq.pen`
    trControl = caret::trainControl(method="cv", number=5),
    preProcess = c("center", "scale"),
    metric = "RMSE"
)

## 1: `rq.lasso.fit()` was deprecated in rqPen 3.0.
## ℹ Please use `rq.pen()` instead.

sessionInfo()

## R version 4.2.0 (2022-04-22 ucrt)
## Platform: x86_64-w64-mingw32/x64 (64-bit)
## Running under: Windows 10 x64 (build 22621)
## 
## Matrix products: default
## 
## locale:
## [1] LC_COLLATE=English_United States.utf8 
## [2] LC_CTYPE=English_United States.utf8   
## [3] LC_MONETARY=English_United States.utf8
## [4] LC_NUMERIC=C                          
## [5] LC_TIME=English_United States.utf8    
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods  
## [7] base     
## 
## loaded via a namespace (and not attached):
##  [1] Rcpp_1.0.10        lattice_0.21-8     rbibutils_2.2.13  
##  [4] hqreg_1.4          MASS_7.3-60        grid_4.2.0        
##  [7] plyr_1.8.8         MatrixModels_0.5-1 lifecycle_1.0.3   
## [10] hrqglas_1.1.0      Rdpack_2.4         rlang_1.1.0       
## [13] cli_3.6.1          SparseM_1.81       data.table_1.14.8 
## [16] rstudioapi_0.14    Matrix_1.5-4.1     splines_4.2.0     
## [19] tools_4.2.0        rqPen_3.1.3        survival_3.5-5    
## [22] parallel_4.2.0     compiler_4.2.0     quantreg_5.95     

Solution

Either install an older version of rqPen (i.e., devtools::install_version("rqPen", version = "3.0.1", repos = "http://cran.us.r-project.org")), or else update rqPen::rq.lasso.fit() and rqPen::rq.nc.fit() to rqPen::rq.pen():

fit = function(x, y, wts, param, lev, last, classProbs, ...) {
  rqPen::rq.pen(as.matrix(x), y, lambda = param$lambda, ...)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants