在 R 的 stabsel 中使用 penalty.factor
Use penalty.factor in stabsel in R
我想在 glmnet 套索上使用 stabsel 来进行变量选择。我正在按照 https://github.com/hofnerb/stabs 上的示例进行操作,并且效果很好。
不过,我还想强制包含几个变量。这可以在 glmnet 中使用参数 'penalty.factor' 实现,但是将 args.fitfun 中的此参数传递给 stabsel 结果错误(见下文)。
data("bodyfat", package = "TH.data")
pfac=c(0,0,0,1,0,1,1,1,1)
stab.glmnet <- stabsel(x = bodyfat[, -2], y = bodyfat[,2],
fitfun = glmnet.lasso, cutoff = 0.75,
PFER = 1, args.fitfun=list(penalty.factor = pfac))
Error in res[[1]] : subscript out of bounds
In addition: Warning message:
In run_stabsel(fitter = fit_model, args.fitter = args.fitfun, n = n, :
100 fold(s) encountered an error. Results are based on 0 folds only.
Original error message(s):
Error : Matrices must have same number of columns in rbind2(.Call(dense_to_Csparse, x), y)
Error : Matrices must have same number of columns in rbind2(.Call(dense_to_Csparse, x), y)
Error : Matrices must have same number of columns in rbind2(.Call(dense_to_Csparse, x), y)
Error : Matrices must have same number of columns in rbind2(.Call(dense_to_Csparse, x), y)
Error : Matrices must have same number of columns in rbind2(.Call(dense_to_Csparse, x), y)
Error : Matrices must have same number of columns in rbind2(.Call(dense_to_Csparse, x), y)
Error : Matrices must have same number of columns in rbind2(.Call(dense_to_Csparse, x), y)
Error : Matrices must have same number of columns in rbind2(.Call(dense_to_Csparse, x), y)
Error : Matrices must have same number of columns in rbind2(.Call(dense_to_Csparse, x), y)
Error : Matrices must have same number of columns in rbind2(.Call(dense_to_Csparse, x [... truncated]
如有任何帮助,我们将不胜感激!
我明白了。由于我们通过设置 penalty.factor 强制包括 n 个变量,我们需要调整三个 stabsel 变量(截止、PFER、q)以确保我们允许在每次重采样中至少选择 n 个变量。
见https://github.com/hofnerb/stabs/blob/master/README.md
和
http://onlinelibrary.wiley.com/doi/10.1111/j.1467-9868.2010.00740.x/full
更多细节。
我想在 glmnet 套索上使用 stabsel 来进行变量选择。我正在按照 https://github.com/hofnerb/stabs 上的示例进行操作,并且效果很好。
不过,我还想强制包含几个变量。这可以在 glmnet 中使用参数 'penalty.factor' 实现,但是将 args.fitfun 中的此参数传递给 stabsel 结果错误(见下文)。
data("bodyfat", package = "TH.data")
pfac=c(0,0,0,1,0,1,1,1,1)
stab.glmnet <- stabsel(x = bodyfat[, -2], y = bodyfat[,2],
fitfun = glmnet.lasso, cutoff = 0.75,
PFER = 1, args.fitfun=list(penalty.factor = pfac))
Error in res[[1]] : subscript out of bounds
In addition: Warning message:
In run_stabsel(fitter = fit_model, args.fitter = args.fitfun, n = n, :
100 fold(s) encountered an error. Results are based on 0 folds only.
Original error message(s):
Error : Matrices must have same number of columns in rbind2(.Call(dense_to_Csparse, x), y)
Error : Matrices must have same number of columns in rbind2(.Call(dense_to_Csparse, x), y)
Error : Matrices must have same number of columns in rbind2(.Call(dense_to_Csparse, x), y)
Error : Matrices must have same number of columns in rbind2(.Call(dense_to_Csparse, x), y)
Error : Matrices must have same number of columns in rbind2(.Call(dense_to_Csparse, x), y)
Error : Matrices must have same number of columns in rbind2(.Call(dense_to_Csparse, x), y)
Error : Matrices must have same number of columns in rbind2(.Call(dense_to_Csparse, x), y)
Error : Matrices must have same number of columns in rbind2(.Call(dense_to_Csparse, x), y)
Error : Matrices must have same number of columns in rbind2(.Call(dense_to_Csparse, x), y)
Error : Matrices must have same number of columns in rbind2(.Call(dense_to_Csparse, x [... truncated]
如有任何帮助,我们将不胜感激!
我明白了。由于我们通过设置 penalty.factor 强制包括 n 个变量,我们需要调整三个 stabsel 变量(截止、PFER、q)以确保我们允许在每次重采样中至少选择 n 个变量。
见https://github.com/hofnerb/stabs/blob/master/README.md 和 http://onlinelibrary.wiley.com/doi/10.1111/j.1467-9868.2010.00740.x/full 更多细节。