回归表中的参考类别
我得到了一个线性回归模型的结果,在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
情况下实现这一目标? 有没有其他的软件包可以做到这一点?
不完全是你想要的,但你可以通过协变量标签参数手动指定协变量标签。 但是我一直无法知道如何添加标题,但需要手动添加换行符。
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
这给出了与ASCII输出所期望的相当接近的结果。 无论它在Latex中成功,都需要您对其进行测试。 n
的处理在那里可能不会有相同的副作用。
stargazer(model1,type='text', column.labels="nCut (Reference: Fair)",
covariate.labels=c(". 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
链接地址: http://www.djcxy.com/p/78517.html
上一篇: Reference category in regression table
下一篇: What's the relationship between the async/await pattern and continuations?