从glm中提取pvalue

编程入门 行业动态 更新时间:2024-10-28 17:26:50
本文介绍了从glm中提取pvalue的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在进行许多回归,并且只对一个特定变量对系数和p值的影响感兴趣.因此,在我的脚本中,我希望能够从glm摘要中提取p值(获取系数本身很容易).我知道的查看p值的唯一方法是使用summary(myReg).还有其他方法吗?

I'm running many regressions and am only interested in the effect on the coefficient and p-value of one particular variable. So, in my script, I'd like to be able to just extract the p-value from the glm summary (getting the coefficient itself is easy). The only way I know of to view the p-value is using summary(myReg). Is there some other way?

例如:

fit <- glm(y ~ x1 + x2, myData) x1Coeff <- fit$coefficients[2] # only returns coefficient, of course x1pValue <- ???

我尝试将fit$coefficients当作矩阵,但是仍然无法简单地提取p值.

I've tried treating fit$coefficients as a matrix, but am still unable to simply extract the p-value.

有可能这样做吗?

谢谢!

推荐答案

您想要的

coef(summary(fit))[,4]

从summary(fit)所示的表格输出中提取 p 值的列向量.在对模型拟合运行summary()之前,实际上不会计算 p 值.

which extracts the column vector of p values from the tabular output shown by summary(fit). The p-values aren't actually computed until you run summary() on the model fit.

如果可以的话,请使用提取器函数而不是深入研究对象:

By the way, use extractor functions rather than delve into objects if you can:

fit$coefficients[2]

应该是

coef(fit)[2]

如果没有提取器功能,则str()是您的朋友.它使您可以查看任何对象的结构,从而可以查看对象包含什么以及如何提取它:

If there aren't extractor functions, str() is your friend. It allows you to look at the structure of any object, which allows you to see what the object contains and how to extract it:

summ <- summary(fit) > str(summ, max = 1) List of 17 $ call : language glm(formula = counts ~ outcome + treatment, family = poisson()) $ terms :Classes 'terms', 'formula' length 3 counts ~ outcome + treatment .. ..- attr(*, "variables")= language list(counts, outcome, treatment) .. ..- attr(*, "factors")= int [1:3, 1:2] 0 1 0 0 0 1 .. .. ..- attr(*, "dimnames")=List of 2 .. ..- attr(*, "term.labels")= chr [1:2] "outcome" "treatment" .. ..- attr(*, "order")= int [1:2] 1 1 .. ..- attr(*, "intercept")= int 1 .. ..- attr(*, "response")= int 1 .. ..- attr(*, ".Environment")=<environment: R_GlobalEnv> .. ..- attr(*, "predvars")= language list(counts, outcome, treatment) .. ..- attr(*, "dataClasses")= Named chr [1:3] "numeric" "factor" "factor" .. .. ..- attr(*, "names")= chr [1:3] "counts" "outcome" "treatment" $ family :List of 12 ..- attr(*, "class")= chr "family" $ deviance : num 5.13 $ aic : num 56.8 $ contrasts :List of 2 $ df.residual : int 4 $ null.deviance : num 10.6 $ df.null : int 8 $ iter : int 4 $ deviance.resid: Named num [1:9] -0.671 0.963 -0.17 -0.22 -0.956 ... ..- attr(*, "names")= chr [1:9] "1" "2" "3" "4" ... $ coefficients : num [1:5, 1:4] 3.04 -4.54e-01 -2.93e-01 1.34e-15 1.42e-15 ... ..- attr(*, "dimnames")=List of 2 $ aliased : Named logi [1:5] FALSE FALSE FALSE FALSE FALSE ..- attr(*, "names")= chr [1:5] "(Intercept)" "outcome2" "outcome3" "treatment2" ... $ dispersion : num 1 $ df : int [1:3] 5 4 5 $ cov.unscaled : num [1:5, 1:5] 0.0292 -0.0159 -0.0159 -0.02 -0.02 ... ..- attr(*, "dimnames")=List of 2 $ cov.scaled : num [1:5, 1:5] 0.0292 -0.0159 -0.0159 -0.02 -0.02 ... ..- attr(*, "dimnames")=List of 2 - attr(*, "class")= chr "summary.glm"

因此,我们注意到可以使用coef()提取的coefficients组件,但是其他组件没有诸如null.deviance的提取器,您可以将其提取为summ$null.deviance.

Hence we note the coefficients component which we can extract using coef(), but other components don't have extractors, like null.deviance, which you can extract as summ$null.deviance.

更多推荐

从glm中提取pvalue

本文发布于:2023-10-29 22:52:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1541001.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:glm   pvalue

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!