楼上正解。这里用我的 msaenet 给出一个实现,大致对应 lasso 和 adaptive SCAD:
library(msaenet)
dat <- msaenet.sim.gaussian(
n = 400,
p = 10,
rho = 0.5,
coef = c(1, 1.5, 2, 1),
snr = 2,
p.train = 0.5,
seed = 42
)
fit_lasso <- aenet(
x = dat$x.tr,
y = dat$y.tr,
init = "enet",
alphas = 1,
tune = "cv",
nfolds = 5L,
rule = "lambda.1se",
seed = 42
)
fit_lasso$beta.first
#> 10 x 1 sparse Matrix of class "dgCMatrix"
#> s0
#> V1 0.6096754
#> V2 0.9004872
#> V3 2.4194953
#> V4 0.5458725
#> V5 .
#> V6 .
#> V7 .
#> V8 .
#> V9 .
#> V10 .
fit_ascad <- suppressWarnings(asnet(
x = dat$x.tr,
y = dat$y.tr,
init = "ridge",
alphas = 1,
tune = "cv",
nfolds = 5,
seed = 42
))
fit_ascad$beta
#> 10 x 1 sparse Matrix of class "dgCMatrix"
#>
#> [1,] 1.0179300
#> [2,] 1.1580254
#> [3,] 2.5748324
#> [4,] 0.9569498
#> [5,] .
#> [6,] .
#> [7,] .
#> [8,] .
#> [9,] .
#> [10,] .
可以看到另外很重要的一点是推荐使用 signal-to-noise ratio (SNR) 来驱动模拟数据的生成.