[英]MASS::lm.ridge coefficients
I'm trying to perform ridge regression using the lm.ridge
method. 我正在尝试使用
lm.ridge
方法执行岭回归。 My question is how can I get the coefficients of the fitted model? 我的问题是如何获得拟合模型的系数? I'm getting different results from calling:
我从致电获得不同的结果:
model$coef
coef(model)
Which is the correct one? 哪个是正确的? Also, why do I get different results from calling:
另外,为什么我从调用中得到不同的结果:
coef(model)
and looking at the 1st coefficient, vs. coef(model)
并coef(model)
系数vs. coef(model)[1]
? coef(model)[1]
? As ?lm.ridge
says (in describing the $coef
element of the returned object) [emphasis added] 正如
?lm.ridge
所说(在描述返回对象的$coef
元素时)[强调加]
coef: matrix of coefficients, one row for each value of 'lambda'.
coef:系数矩阵,每个“ lambda”值对应一行。 Note that these are not on the original scale and are for use by the 'coef' method.
请注意,这些不是原始比例,而是由“ coef”方法使用。
This means, specifically, that the $coef
element is not intended for end-users ("if you have to ask ..."). 具体地说,这意味着
$coef
元素不适合最终用户使用(“如果您要询问...”)。 (If you want to see how $coef
is translated, inspect MASS:::coef.ridgelm
.) In general, it's better practice to use an accessor method such as coef()
, when it exists, than to extract components from the guts of a returned object using $
(or @
for S4 objects) - for exactly this reason. (如果您想了解
$coef
的翻译方式,请检查MASS:::coef.ridgelm
。)通常,最好使用访问器方法(例如coef()
(如果存在),而不是从胆量中提取成分。正是由于这个原因,使用$
(或对于S4对象为@
对返回的对象进行计数。 Package authors provide coef()
methods for a reason ... 程序包作者出于某种原因提供了
coef()
方法。
I can't replicate your second question. 我不能重复你的第二个问题。 Using the model from
?lm.ridge
, the answers seem identical except for the precision with which they are printed ... 使用来自
?lm.ridge
的模型,答案似乎相同,除了它们的打印精度...
> m1 <- lm.ridge(y ~ ., longley)
> coef(m1)
GNP Unemployed Armed.Forces Population
2946.85636017 0.26352725 0.03648291 0.01116105 -1.73702984
Year Employed
-1.41879853 0.23128785
> coef(m1)[1]
2946.856
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.