问题描述
我有一组多重共线性变量,我正在尝试使用岭回归来解决这个问题.我在R中使用glmnet
包,其中alpha = 0(用于岭回归).
I have a set of multicollinear variables and I'm trying to use ridge regression to tackle that. I am using the glmnet
package in R with alpha = 0 (for ridge regression).
library(glmnet)
我有一个lambda值序列,我正在通过cv.glmnet选择最佳的lambda值
I have a sequence of lambda values, and I am choosing the best lambda value through cv.glmnet
lambda <- 10^seq(10, -2, length = 100)
-创建模型矩阵并分配y变量
-- creating model matrix and assigning the y variable
x <- model.matrix(dv ~ ., datamatrix) [,-1]
y <- datamatrix$dv
-使用交叉验证确定最佳lambda并使用该lambda值预测y
-- Using cross validation to determine the best lambda and predicting y using that lambda value
ridge.mod <- glmnet(x, y, alpha = 0, lambda = lambda)
cv.out <- cv.glmnet(x, y, alpha = 0)
ridge.pred <- predict(ridge.mod, s = cv.out$lambda.min, newx = x)
到目前为止,我已经可以成功地做到这一点,但是我还必须检查该特定lambda值的VIF,以确保系数稳定并且可以控制多重共线性.但是我不确定如何在GLMNET中检查VIF,因为通常的vif()
函数会引发此错误.
I am able to successfully do till this point, but I have to also check for the VIF for this particular lambda value to ensure that the coefficients have stabilized and the multicollinearity is controlled. But I am not sure how to check for VIF in GLMNET since the usual vif()
function throws this error.
能否请您帮助我确定我的方法是否存在问题或如何解决此问题?
Could you please help me identify if there is anything wrong in my approach or how to solve this issue?
VIF是否不适用于GLMNET中的验证?
Is VIF not applicable for validation in GLMNET?
谢谢.
推荐答案
VIF仅是一组独立变量的属性.只要是因变量不改变独立变量(例如加性模型),无论是什么因变量以及使用哪种模型(线性回归,广义模型)都没有关系.请参见car
包中的vif
函数.因此,将VIF应用于弹性净回归时,不会告诉您是否已经处理了多重共线性问题.它可以告诉您存在多重共线性要处理.
VIF is a property of set of independent variables only. It doesn't matter what dependent variable is and what kind of model you use (linear regression, generalized model) as long as it doesn't change indeperndent variables (as e.g. additive model does). See vif
function from car
package. So, VIF applied to elastic net regression, won't tell you if you have dealt with multicollinearity. It can just tell you that there was a multicollinearity to deal with.
这篇关于R中的glmnet中的Ridge回归;使用glmnet软件包计算不同lambda值的VIF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!