首页 > 解决方案 > 在没有截距的情况下使用 SCAD 惩罚拟合 Lasso

问题描述

我正在使用cv.ncvreg适合. 由于我需要选择使用交叉验证,因此我选择使用函数。我在下面给出了我的代码。LassoSCADlambdacv.ncvregr

library(ncvreg)
n = 100
p = 10
beta0 = c(2, 0, 3, 0, 0, 1, 0, 0, 0, 0)
X = matrix(rnorm(n * p, 0,1), ncol = p)
y=vector(mode="numeric",length=n) 
X[,3]=rnorm(n,2,1)
X[,4]=rnorm(n,4,1)
X[,5]=rnorm(n,5,1)
ei_N=rnorm(n,0,1)   # the model errors 
y= X%*%beta0 + ei_N
fit = cv.ncvreg(X, y, penalty = "SCAD", standardize=TRUE)
coef = coef(fit, s = "lambda.min")
coef

我获得以下输出

(Intercept)          V1          V2          V3          V4          V5          V6          V7 
 0.06907783  1.98544923  0.00000000  3.01165615  0.00000000  0.00000000  1.00447815  0.00000000 
         V8          V9         V10 
 0.00000000  0.00000000  0.00000000

如果您看到输出,则拟合模型具有intercept. 如果没有一段时间的交叉验证来选择,我如何lasso适应SCAD惩罚?谢谢你。interceptlambda

标签: rcross-validationnon-linear-regressionlasso-regression

解决方案


推荐阅读