R 中模型对象的增强/变异
所以我正在运行多个 Cochrane orcutt 回归,这没有问题。然后,我使用 modelsummary() 显示这些回归的输出。到目前为止仍然没有问题。
但是,当我尝试使用 modelplot() 比较模型时,在 cochrane orcutt 模型(“orcutt”类)中没有计算置信区间,因此出现以下错误:
eval(parse(text = text, keep.source = FALSE), envir) 中的错误: 未找到对象“conf.low”
我知道这里的问题是什么 - 只是没有由 cochrane.orcutt() 命令计算的置信区间“部分”。部分解决方案也是显而易见的 - 我可以使用点估计/系数和标准误差(当然默认情况下包含在模型中)来计算置信区间。
然而,当我想在 modelplot() 中使用这些置信区间值时,我的问题就出现了,因为它们不在模型对象“中”。在我的无知中,我尝试使用 mutate() 尝试以下操作来创建置信区间的下限:
model %>%
+ mutate(`conf.low`=`coefficients`-1.96*`std.error`)
我希望这能够很好地传达我的问题,感谢您的阅读。
So I am running multiple cochrane orcutt regressions, which is no problem. I then display the output of these regressions using modelsummary(). Still no problems up to this point.
However, when I then try to compare the models using modelplot(), there are no confidence intervals computed in the cochrane orcutt model (class "orcutt") and I thus get the following error:
Error in eval(parse(text = text, keep.source = FALSE), envir) :
object 'conf.low' not found
I know what the problem here is - there are just no confidence interval "parts" computed by the cochrane.orcutt() command. A partial solution is also obvious - I can just calculate the confidence intervals using the point estimates/coefficients and the standard errors (which are of course included in the model by default).
However my problem arises when I want to use these confidence interval values in modelplot(), because they are not "in" the model object. In my ignorance, I attempted the following to try and create the lower bound of a confidence interval, using mutate():
model %>%
+ mutate(`conf.low`=`coefficients`-1.96*`std.error`)
I hope this conveys my problem well enough, thank you for reading.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如评论中所述,
mutate
是dplyr
包中的一个函数,旨在处理数据帧,而不是模型对象或在modelsummary
表上。另外,请注意,我无法正确诊断您的问题,因为您没有提供最小可重现示例并且您不提供t 事件告诉我们您使用哪个函数来估计模型。
在
R
中执行 Cochrane-Orcutt 的一种方法是使用orcutt
包:在幕后,
modelsummary
包使用
函数用于从模型对象中提取估计值:broom
包中的 tidy从上面的输出中,您可以看到
broom
不会提取置信区间。这可以解释为什么modelsummary
无法打印您的表格/图。另一种选择是指示 modelsummary 使用
parameters
包而不是broom
来提取估计值。这可以通过设置全局选项来实现:并且
modelplot
现在也可以工作:另一种选择是使用 broom 默认值,但使用您自己的 tidy_custom.orcutt 方法自定义输出。这有点复杂,但您可以在
modelsummary
网站上找到详细说明:https://vincentarelbundock.github.io/modelsummary/articles/modelsummary.html#adding-new-information-to-existing-modelsAs noted in the comments,
mutate
is a function from thedplyr
package which is intended to work on data frames, and not on model objects or onmodelsummary
tables.Also, please note that I can’t diagnose your problem properly because you did not supply a MINIMAL REPRODUCIBLE EXAMPLE and you don’t event tell us which function you used to estimate the model.
One way to do the Cochrane-Orcutt in
R
is to use theorcutt
package:Behind the scenes, the
modelsummary
package uses thetidy
function from thebroom
package to extract estimates from model objects:From the output above, you see that
broom
does NOT extract a confidence interval. This could explain whymodelsummary
can’t print your table/plot.One alternative option is to instruct
modelsummary
to use theparameters
package to extract estimates instead ofbroom
. This can be achieved by setting a global option:And
modelplot
now works too:Yet another alternative would be to use the
broom
default, but to customize the output using your owntidy_custom.orcutt
method. This is a bit more involved, but you’ll find detailed instruction on themodelsummary
website: https://vincentarelbundock.github.io/modelsummary/articles/modelsummary.html#adding-new-information-to-existing-models