更改 stargazer 输出的系数名称
Change coefficient name for stargazer output
我最近收到一个关于的问题,关于如何在使用 Stargazer 输出回归结果时更改变量的名称。答案不适用于 rms 中的 lrm
函数。具体来说,系数输出正确,但标准误差消失了。这是一个可重现的例子:
library(rms)
library(stargazer)
stargazer(attitude)
# logit models
m1 <- lrm(rating ~ complaints + learning + privileges,x=TRUE, y=TRUE,data=attitude)
m2 <- lrm(rating ~ complaints + learning + privileges,x=TRUE, y=TRUE,data=attitude)
names(m1$coefficients)[names(m1$coefficients) == "privileges"] <- "past"
names(m2$coefficients)[names(m2$coefficients) == "privileges"] <- "past"
stargazer(m1,m2, type="text")
知道如何进行这项工作吗?
答案是 lrm
class 对象不仅存储系数,还存储方差-协方差矩阵,因此您需要执行额外的步骤:
rownames(m1$var)[rownames(m1$var) == "privileges"] <- "past"
rownames(m2$var)[rownames(m2$var) == "privileges"] <- "past"
colnames(m1$var)[colnames(m1$var) == "privileges"] <- "past"
colnames(m2$var)[colnames(m2$var) == "privileges"] <- "past"
这会更改方差-协方差矩阵的行名和列名,从而产生正确的结果:
stargazer(m1,m2, type="text")
==========================================
Dependent variable:
----------------------------
rating
(1) (2)
------------------------------------------
....
complaints 0.196*** 0.196***
(0.045) (0.045)
learning 0.063 0.063
(0.039) (0.039)
past -0.034 -0.034
(0.035) (0.035)
------------------------------------------
Observations 30 30
R2 0.713 0.713
chi2 (df = 3) 37.238*** 37.238***
==========================================
Note: *p<0.1; **p<0.05; ***p<0.01
我最近收到一个关于lrm
函数。具体来说,系数输出正确,但标准误差消失了。这是一个可重现的例子:
library(rms)
library(stargazer)
stargazer(attitude)
# logit models
m1 <- lrm(rating ~ complaints + learning + privileges,x=TRUE, y=TRUE,data=attitude)
m2 <- lrm(rating ~ complaints + learning + privileges,x=TRUE, y=TRUE,data=attitude)
names(m1$coefficients)[names(m1$coefficients) == "privileges"] <- "past"
names(m2$coefficients)[names(m2$coefficients) == "privileges"] <- "past"
stargazer(m1,m2, type="text")
知道如何进行这项工作吗?
答案是 lrm
class 对象不仅存储系数,还存储方差-协方差矩阵,因此您需要执行额外的步骤:
rownames(m1$var)[rownames(m1$var) == "privileges"] <- "past"
rownames(m2$var)[rownames(m2$var) == "privileges"] <- "past"
colnames(m1$var)[colnames(m1$var) == "privileges"] <- "past"
colnames(m2$var)[colnames(m2$var) == "privileges"] <- "past"
这会更改方差-协方差矩阵的行名和列名,从而产生正确的结果:
stargazer(m1,m2, type="text")
==========================================
Dependent variable:
----------------------------
rating
(1) (2)
------------------------------------------
....
complaints 0.196*** 0.196***
(0.045) (0.045)
learning 0.063 0.063
(0.039) (0.039)
past -0.034 -0.034
(0.035) (0.035)
------------------------------------------
Observations 30 30
R2 0.713 0.713
chi2 (df = 3) 37.238*** 37.238***
==========================================
Note: *p<0.1; **p<0.05; ***p<0.01