0

我想在 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]

任何帮助将非常感激!

4

1 回答 1

0

我想到了。由于我们通过设置惩罚因子强制包含 n 个变量,因此我们需要调整三个 stabsel 变量(截止、PFER、q)以确保我们允许在每次重采样中选择至少 n 个变量。

有关更多详细信息,请参阅https://github.com/hofnerb/stabs/blob/master/README.mdhttp://onlinelibrary.wiley.com/doi/10.1111/j.1467-9868.2010.00740.x/full

于 2017-04-25T21:05:29.053 回答