从 R 中的 anova (glm) 中提取残余偏差 [英] Extract Residual Deviance from anova (glm) in R

查看:30
本文介绍了从 R 中的 anova (glm) 中提取残余偏差的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 R 中安装了 glm 模型并使用了 anova 表.我需要提取剩余偏差"列.但它会产生错误.代码如下:

I fitted a glm model in R and took the anova table. I need to extract the "Residual Deviance" column. But it generates an error. Here are the codes:

创建数据:

counts <- c(18,17,15,20,10,20,25,13,12)
outcome <- gl(3,1,9)
treatment <- gl(3,3)

拟合 GLM:

glm.D93 <- glm(counts ~ outcome + treatment, family = quasipoisson(link = "log"))

方差分析表:

av.1=anova(glm.D93)
av.1
Analysis of Deviance Table

Model: quasipoisson, link: log

Response: counts

Terms added sequentially (first to last)


          Df Deviance Resid. Df Resid. Dev
NULL                          8    10.5814
outcome    2   5.4523         6     5.1291
treatment  2   0.0000         4     5.1291

现在我需要提取Resid.Dev"列.所以我尝试了 str

Now I need to extract "Resid. Dev" column. So I tried str

> str(av.1)
Classes ‘anova’ and 'data.frame':       3 obs. of  4 variables:
 $ Df        : int  NA 2 2
 $ Deviance  : num  NA 5.45 0
 $ Resid. Df : int  8 6 4
 $ Resid. Dev: num  10.58 5.13 5.13
 - attr(*, "heading")= chr "Analysis of Deviance Table\n\nModel: quasipoisson, link: log\n\nResponse: counts\n\nTerms added sequentially (first to last)\n\"| __truncated__

最后我提取了 Resid.Dev 但它给了我一个错误:

Finally I extracted Resid. Dev but it gives me an error:

> av.1$Resid. Dev
Error: unexpected symbol in "av.1$Resid. Dev"

推荐答案

使用引号

> av.1$"Resid. Dev"
[1] 10.581446  5.129141  5.129141

等价

av.1[["Resid. Dev"]]

这篇关于从 R 中的 anova (glm) 中提取残余偏差的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆