在R中使用惩罚



我想在glmnet lasso顶部使用Stabsel进行可变选择。我正在遵循https://github.com/hofnerb/stabs上的示例,而且效果很好。

但是,我也想强制包括几个变量。可以在Glmnet中使用参数" nungry.factor"实现这一点,但是在Args.fitfun中传递此参数到刺伤结果错误(请参阅下文(。

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]

任何帮助将不胜感激!

我弄清楚了。由于我们是通过设置惩罚来包括N变量的力,因此我们需要调整三个Stabsel变量(截止,PFER,Q(,以确保我们允许在每个重新采样中选择至少N变量。

请参阅https://github.com/hofnerb/stabs/blob/master/master/readme.md和http://onlinelibrary.wiley.com/doi/10.1111/j.1467-9868.2010.00740.x/full更多细节。

最新更新