更改占星师输出

时间:2015-06-30 11:22:06

标签: r regression stargazer

我最近收到了一个关于the answer here的问题,关于在使用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")

知道如何使这项工作吗?

1 个答案:

答案 0 :(得分:1)

答案是lrm类对象不仅存储系数,还存储方差 - 协方差矩阵,因此您需要执行额外的步骤:

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"

这会改变方差 - 协方差矩阵的rownames和colnames,从而产生正确的结果:

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