gpt4 book ai didi

回归表中的引用类别

转载 作者:行者123 更新时间:2023-12-04 12:31:57 24 4
gpt4 key购买 nike

我得到了一个线性回归模型的结果,在 R 中有一个因子变量,我想要漂亮,然后输出到 LaTeX。理想情况下,因子变量将通过一行显示在表中,该行给出变量的名称和引用类别,否则为空白,然后是下面带有缩进文本的行,这些行给出了因子的水平以及相应的估计值。

我长期使用 stargazer将回归结果从 R 获取到 LaTeX 的包,但看不到用它实现我想要的结果的方法。一个例子:

library(ggplot2)
library(stargazer)

levels(diamonds$cut)

options(contrasts = c("contr.treatment", "contr.treatment"))
model1 <- lm(price~cut,data=diamonds)
stargazer(model1,type='text')

这会产生默认输出:
===============================================
Dependent variable:
---------------------------
price
-----------------------------------------------
cutGood -429.893***
(113.849)

cutVery Good -376.998***
(105.164)

cutPremium 225.500**
(104.395)

cutIdeal -901.216***
(102.412)

Constant 4,358.758***
(98.788)

-----------------------------------------------
Observations 53,940
R2 0.013
Adjusted R2 0.013
Residual Std. Error 3,963.847 (df = 53935)
F Statistic 175.689*** (df = 4; 53935)
===============================================
Note: *p<0.1; **p<0.05; ***p<0.01

这是我想要的:
===============================================
Dependent variable:
---------------------------
price
-----------------------------------------------

Cut (Reference: Fair)

Good -429.893***
(113.849)

Very Good -376.998***
(105.164)

Premium 225.500**
(104.395)

Ideal -901.216***
(102.412)

Constant 4,358.758***
(98.788)

-----------------------------------------------
Observations 53,940
R2 0.013
Adjusted R2 0.013
Residual Std. Error 3,963.847 (df = 53935)
F Statistic 175.689*** (df = 4; 53935)
===============================================
Note: *p<0.1; **p<0.05; ***p<0.01

有什么办法可以在 stargazer 中实现这一点吗?没有太多的黑客?是否有其他软件包可以更简单地做到这一点?

最佳答案

不完全是您想要的,但您可以通过 covariate.labels 参数手动指定协变量标签。但是,我无法找到如何添加标题,这需要您手动添加换行符。

stargazer(model1,type='text',
covariate.labels=c("Cut (Reference: Fair) Good",
". Very good",
". Premium",
". Ideal"))


======================================================
Dependent variable:
---------------------------
price
------------------------------------------------------
Cut (Reference: Fair) Good -429.893***
(113.849)

. Very good -376.998***
(105.164)

. Premium 225.500**
(104.395)

. Ideal -901.216***
(102.412)

Constant 4,358.758***
(98.788)

------------------------------------------------------
Observations 53,940
R2 0.013
Adjusted R2 0.013
Residual Std. Error 3,963.847 (df = 53935)
F Statistic 175.689*** (df = 4; 53935)
======================================================
Note: *p<0.1; **p<0.05; ***p<0.01

关于回归表中的引用类别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22812897/

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