Reference category in regression table
I've got results from a linear regression model with a factor variable in R that I would like pretty up and then output into LaTeX. Ideally the factor variable would be presented in the table via a row that gives the name of the variable and the reference category but is otherwise blank and then rows with indented text below that give the levels of the factor together with the corresponding estimates.
I've long used the stargazer
package to get regression results from R into LaTeX but see no way of achieving the result I want with it. An example:
library(ggplot2)
library(stargazer)
levels(diamonds$cut)
options(contrasts = c("contr.treatment", "contr.treatment"))
model1 <- lm(price~cut,data=diamonds)
stargazer(model1,type='text')
This yields the default output:
===============================================
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
Here's what I want:
===============================================
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
Is there any way to achieve this in stargazer
without too much hackery? Are there other packages in which this would be simpler to do?
Not entirely what you wanted, but you're able to manually specify covariate labels via the covariate.labels argument. I haven't been able to find out how you could add a header, though, requiring you to manually add the linebreak.
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
This gives reasonably close to what was desired as an ASCII output. Whether it succeeds in Latex will require that you test it. The handling of n
may not have the same side-effects there.
stargazer(model1,type='text', column.labels="nCut (Reference: Fair)",
covariate.labels=c(". Good",
". Very good",
". Premium",
". Ideal"))
Console:
=================================================
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/78518.html
上一篇: 理解多CDI /焊接
下一篇: 回归表中的参考类别