簡體   English   中英

r stargazer-將行添加到回歸輸出並統一其順序

[英]r stargazer - add lines to regression output and costumise their order

我的問題介於這個問題和這個問題之間。

我想在回歸輸出中為因子變量的參考類別添加一行。 觀星者似乎沒有做到這一點的簡便方法。 我當前的方法是使用add.lines添加一行,然后在我的Word文檔中手動更改該新行的順序。 這當然是乏味的。

x <- as.factor(c("a","b","c"))
x1 <- c(1,2,3)

# Estimate a model
m1 <- lm(x1~x)

#Create output
stargazer(m1, type = "text", style="ajs", add.lines=c("a (ref.)"))

我現在站在這里:

> stargazer(m1, type = "text", style="ajs", add.lines=c("a (ref.)"))


========================
                 X1     
------------------------
xb              1.000   


xc              2.000   


Constant        1.000   


a (ref.)                
Observations      3     
R2              1.000   
------------------------
Notes:       *P < .05   
             **P < .01  
             ***P < .001

我想要的輸出是這樣的:

========================
                 X1     
------------------------
a (ref.)                
   xb           1.000   


   xc           2.000   


Constant        1.000   


Observations      3     
R2              1.000   
------------------------
Notes:       *P < .05   
             **P < .01  
             ***P < .001

自定義添加行順序的自動方法是什么? 或者,如果您願意,還有一個更籠統的問題:以正確的順序添加因子變量的參考類別的簡便方法是什么?

您可以使用table.layout參數來自定義表格布局:

library(stargazer)
stargazer(m1, type = "text", style="ajs", add.lines=c("a (ref.)"), table.layout = "=ldc-ats-n")

結果:

========================
                 X1     
------------------------
a (ref.)                
xb              1.000   


xc              2.000   


Constant        1.000   



Observations      3     
R2              1.000   
------------------------
Notes:       *P < .05   
             **P < .01  
             ***P < .001

注意:

"=ldc-ats-n"確定哪些元素以及它們在輸出中出現的順序,每個字符都是一個元素。 例如, "t"表示“系數表”,而"a"表示“其他行”,因此將"a"放在"t"之前會為您提供正確的順序。 請參閱?stargazer並轉到table.layout了解更多詳細信息。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM