gpt4 book ai didi

r - 如何计算R中岭回归的P值?

转载 作者:行者123 更新时间:2023-12-04 10:33:04 26 4
gpt4 key购买 nike

以下是来自 MASS 包的 ?lm.ridge 的示例:

> data(longley) # not the same as the S-PLUS dataset
> names(longley)[1] <- "y"
> lm.ridge(y ~ ., longley)
GNP Unemployed Armed.Forces Population Year Employed
2946.85636017 0.26352725 0.03648291 0.01116105 -1.73702984 -1.41879853 0.23128785
> plot(lm.ridge(y ~ ., longley,
+ lambda = seq(0,0.1,0.001)))
> select(lm.ridge(y ~ ., longley,
+ lambda = seq(0,0.1,0.0001)))
modified HKB estimator is 0.006836982
modified L-W estimator is 0.05267247
smallest value of GCV at 0.0057

enter image description here

我如何计算 P 值或置信区间,就像我在通常的线性回归摘要中可以得到的那样。

最佳答案

就我而言MASS::lm.ridge不会为您的系数计算 p 值。您可以使用 linearRidge来自 ridge 的函数包,但是,确实如此。请参阅以下示例:

data(longley) 
names(longley)[1] <- "y"

library(ridge)
mymod <- linearRidge(y ~ ., longley)

> summary(mymod)

Call:
linearRidge(formula = y ~ ., data = longley)


Coefficients:
Estimate Scaled estimate Std. Error (scaled) t value (scaled) Pr(>|t|)
(Intercept) -1.247e+03 NA NA NA NA
GNP 4.338e-02 1.670e+01 3.689e+00 4.526 6.0e-06 ***
Unemployed 1.184e-02 4.286e+00 2.507e+00 1.710 0.0873 .
Armed.Forces 1.381e-02 3.721e+00 1.905e+00 1.953 0.0508 .
Population -2.831e-02 -7.627e-01 5.285e+00 0.144 0.8853
Year 6.566e-01 1.211e+01 2.691e+00 4.500 6.8e-06 ***
Employed 6.745e-01 9.175e+00 4.996e+00 1.836 0.0663 .
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Ridge parameter: 0.01046912, chosen automatically, computed using 2 PCs

Degrees of freedom: model 3.67 , variance 3.218 , residual 4.123

并使用 summary您会得到带有 p 值和重要性的熟悉表格!

关于r - 如何计算R中岭回归的P值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30554784/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com