Multiple references to `lambda` when specifying `lambda` in `stat.glmnet_coefdiff`
Opened this issue · 0 comments
JamesYang007 commented
I would like to specify the lambda values to pass into glmnet by creating a wrapper function for stat.glmnet_coefdiff
. However, I get the following error:
Error in glmnet::cv.glmnet(X, y, lambda = lambda, intercept = intercept, :
formal argument "lambda" matched by multiple actual arguments
Here is a simple reproducible code:
library(knockoff)
# dummy values
n <- 30
p <- 10
X <- matrix(rnorm(n*p), nrow=n)
y <- rnorm(n)
# important part
custom.stat <- function(X, X_k, y) {
stat.glmnet_coefdiff(X, X_k, y, lambda=c(1,2))
}
out <- knockoff.filter(X, y, statistic=custom.stat)
I looked at the source code and I think the problem lies in cv_coeffs_glmnet line 162.
Specifically, if the caller specifies lambda
, setting lambda
at line 162 introduces a duplicate.