ryantibs / quantgen

Tools for generalized quantile modeling
https://ryantibs.github.io/quantgen
14 stars 9 forks source link

Fix quantile_lasso() when p = 1. #18

Closed huisaddison closed 1 year ago

huisaddison commented 1 year ago

Fix quantile_lasso() when a single predictor is given (i.e., when dim(x)=c(n, 1)).

Without the fix, the subset operation of line 54 in utils.R drops the second dimension of x when x only has one column, incurring an error at line 64 (as x would now be a vector but apply() expects a matrix).

Minimum reproducing example for the issue (fix was small enough that I didn't bother filing a formal one):

> library(quantgen)
> set.seed(1)
> n = 50
> p = 1
> beta = 5 + rnorm(p)
> beta0 = 10 + rnorm(1)
> X = matrix(rnorm(p*n), ncol=p)
> y = X%*%beta + beta0 + rnorm(n)
> tau = c(0.05, 0.5, 0.95)
> quantgen::quantile_lasso(X, y, tau=tau, lambda=0)
Error in apply(x, 2, mean) : dim(X) must have a positive length