【问题标题】:Summary of model after adding to list [duplicate]添加到列表后的模型摘要[重复]
【发布时间】:2019-08-20 05:25:29
【问题描述】:

我在 R 中有一组模型,其中我有一组因变量,但自变量相同。这个想法是建立一个模型列表(列表中的每个项目都有一个不同的因变量)。

模型摘要在列表中后,我无法访问它。

这个答案很接近,但没有达到我所需要的:Appending models to list

如果我们设置这两个模型:

fit1 <- lm(Sepal.Length ~ Sepal.Width, data=iris)
fit2 <- lm(Sepal.Length ~ Petal.Width, data=iris)

然后将它们作为列表加入:

x <- list(fit1, fit2)

我希望以下两行给出相同的输出:

summary(x[1])
summary(fit1)

这是我从 summary(x[1]) 中得到的:

summary(x[1])
     Length Class Mode
[1,] 12     lm    list

同时,summary(fit1) 完全符合我的预期:

...
Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept)   6.5262     0.4789   13.63   <2e-16 ***
Sepal.Width  -0.2234     0.1551   -1.44    0.152 
...

如何让模型在列表中后的结果看起来像 summary(fit1)?

【问题讨论】:

  • 它应该是summary(x[[1]]),因为[[ 提取了list 元素,而[ 仍然是一个包含一个元素的列表

标签: r


【解决方案1】:

问题是我们需要[[ 来提取list 元素。 [ 将提取一个带有一个元素的list

identical(summary(x[[1]]), summary(fit1))
#[1] TRUE

【讨论】:

    猜你喜欢
    • 2020-11-17
    • 1970-01-01
    • 1970-01-01
    • 2012-12-07
    • 2013-04-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多