[英]R - How to Extract T-Statistics From Ridge Regression Results
I am making use of the ridge regression package in R, but am having trouble extracting T-statistics, p values in the the coefficients list. 我正在使用R中的岭回归软件包 ,但是在提取系数列表中的T统计量p值时遇到了麻烦。
Here is some sample code from here ; 下面是一些示例代码在这里 ;
data(GenCont)
mod <- linearRidge(Phenotypes ~ ., data = as.data.frame(GenCont))
summary(mod)
This returns 这返回
Call:
linearRidge(formula = Phenotypes ~ ., data = as.data.frame(GenCont))
Coefficients:
Estimate Scaled estimate Std. Error (scaled) t value (scaled) Pr(>|t|)
(Intercept) 1.533386 NA NA NA NA
SNP1 0.277296 4.045409 0.266120 15.201 < 2e-16 ***
SNP2 -0.110458 -1.256154 0.216332 5.807 6.38e-09 ***
But I want to access the data in "coefficients" programmatically. 但是我想以编程方式访问“系数”中的数据。 I understand that if i were using lm, then something along the lines of
我了解,如果我使用lm,则类似
coef(summary(mod))
should work, but this does not seem to do what I am after. 应该可以工作,但这似乎并不能满足我的要求。 I simply get a NULL.
我只是得到一个NULL。
Any ideas on how to access this data please? 请问有关如何访问此数据的任何想法?
To get coefficient table for the situation where ridge parameters are chosen automatically you should store summary()
result as some object and then access list element summaries$summary1$coefficients
. 要获得针对自动选择了脊参数的情况的系数表,您应该将
summary()
结果存储为某个对象,然后访问列表元素summaries$summary1$coefficients
。 Whole structure of the summary()
object you can see with function str(sumar)
. 您可以使用功能
str(sumar)
看到summary()
对象的整个结构。
sumar<-summary(mod)
sumar$summaries$summary1$coefficients
Estimate Scaled estimate Std. Error (scaled) t value (scaled) Pr(>|t|)
(Intercept) 1.533385893 NA NA NA NA
SNP1 0.277296215 4.045408706 0.2661197 15.20146202 0.000000e+00
SNP2 -0.110457822 -1.256153622 0.2163319 5.80660491 6.375233e-09
SNP3 -0.110457822 -1.256153622 0.2163319 5.80660491 6.375233e-09
SNP4 0.005229639 0.011635212 0.3716925 0.03130332 9.750276e-01
SNP5 0.531172545 6.323006229 0.3153685 20.04958196 0.000000e+00
SNP6 -0.119163534 -1.373227248 0.2230470 6.15667175 7.428960e-10
SNP7 0.113843942 0.113730041 0.3721807 0.30557749 7.599264e-01
SNP8 -0.099148877 -1.028580596 0.3558067 2.89084074 3.842128e-03
SNP9 -0.008320553 -0.008312229 0.3723863 0.02232152 9.821915e-01
SNP10 0.058562323 0.101128163 0.3715670 0.27216670 7.854938e-01
SNP11 -0.096526424 -1.495698673 0.3292496 4.54275034 5.552500e-06
SNP12 -0.334279101 -0.333944654 0.3722483 0.89710186 3.696646e-01
To get only t values select fourth column of this table. 要仅获取t值,请选择此表的第四列。
> sumar$summaries$summary1$coefficients[,4]
(Intercept) SNP1 SNP2 SNP3 SNP4 SNP5 SNP6 SNP7 SNP8 SNP9
NA 15.20146202 5.80660491 5.80660491 0.03130332 20.04958196 6.15667175 0.30557749 2.89084074 0.02232152
SNP10 SNP11 SNP12
0.27216670 4.54275034 0.89710186
To access other elements produced by summary() function you just need to select appropriate list element. 要访问由summary()函数产生的其他元素,您只需选择适当的列表元素。 Structure of summary object shows which element to chose.
摘要对象的结构显示要选择的元素。
str(sumar$summaries$summary1)
List of 4
$ coefficients: num [1:13, 1:5] 1.53339 0.2773 -0.11046 -0.11046 0.00523 ...
..- attr(*, "dimnames")=List of 2
.. ..$ : chr [1:13] "(Intercept)" "SNP1" "SNP2" "SNP3" ...
.. ..$ : chr [1:5] "Estimate" "Scaled estimate" "Std. Error (scaled)" "t value (scaled)" ...
$ df : Named num [1:3] 3.12 1.21 5.04
..- attr(*, "names")= chr [1:3] "model" "variance" "residual"
$ nPCs : int 1
$ lambda : num 2.21
For example to get df
例如获取
df
sumar$summaries$summary1$df
model variance residual
3.120934 1.205412 5.036457
Results can be selected also without creating new object - just use summary(mod)
instead of object name sumar
. 也可以选择结果而无需创建新对象-只需使用
summary(mod)
而不是对象名称sumar
。
summary(mod)$summaries$summary1$df
model variance residual
3.120934 1.205412 5.036457
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.