gpt4 book ai didi

r - 如何从函数 Anova() 中提取残差并读取系数?

转载 作者:行者123 更新时间:2023-12-04 01:45:47 27 4
gpt4 key购买 nike

我使用 car 包中的函数 Anova() 来执行类型 III 的测试。但是我不知道如何提取残差或如何获取参数估计的信息。

有没有什么方法可以做到这些,比如 residuals(model)summary.lm(model)

最佳答案

Anova 的输出是 class anovadata.frame

因此,如果我们使用带行/列名称的提取,它应该可以工作。使用 ?Anova 文档中的可重现示例

library(car)
mod <- lm(conformity ~ fcategory*partner.status, data=Moore,
contrasts=list(fcategory=contr.sum, partner.status=contr.sum))
out <- Anova(mod, type = 3)
str(out)
#Classes ‘anova’ and 'data.frame': 5 obs. of 4 variables:
# $ Sum Sq : num 5753 36 240 175 818
# $ Df : num 1 2 1 2 39
# $ F value: num 274.359 0.859 11.425 4.185 NA
# $ Pr(>F) : num 3.05e-19 4.31e-01 1.66e-03 2.26e-02 NA
# - attr(*, "heading")= chr "Anova Table (Type III tests)\n" "Response: conformity"

print 方法改变了打印输出的方式。但是,如果我们只是剥离 anova 类。 “残差”也在行名中

row.names(out)
#[1] "(Intercept)" "fcategory" "partner.status"
#[4] "fcategory:partner.status" "Residuals"

因此,使用行/列名称进行提取

out["Residuals","Sum Sq"]
#[1] 817.764

关于r - 如何从函数 Anova() 中提取残差并读取系数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55313379/

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