2016-11-22 8 views
1

私は次の問題を抱えています。問題の解決策を見つけることができないので、ゆっくりと疲れました。次のようにスターゲイザー、ノートのセクションでHTMLの回帰結果表を作成することは意義のカットオフ値を示した場合R Stargazer:ノート内の固定文字ベクタと動的カットオフを組み合わせる方法

:私は、次の問題に直面しています

*p**p***p<0.01 

しかし、私は次のようなレイアウトを好むだろう。

Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 

私はカットオフを動的に抽出し、固定文字ベクトルと組み合わせることでこれを取得したいと考えています。スターゲイザーマニュアルは言う:

> a character vector containing notes to be included below the table. 
> The character strings can include special substrings that will be 
> replaced by the corresponding cutoffs for statistical significance 
> 'stars': [*], [**], and [***] will be replaced by the cutoffs, in 
> percentage terms, for one, two and three 'stars,' respectively (e.g., 
> 10, 5, and 1). Similarly, [0.*], [0.**] and [0.***] will be replaced 
> by the numeric value of cutoffs for one, two and three 'stars' (e.g., 
> 0.1, 0.05, and 0.01). [.*], [.**] and [.***] will omit the leading zeros (e.g., .1, .05, .01). 

私は今、すべての可能な組み合わせを試してみましたが、私はいつも失敗しました。私はいつも、HTMLファイルで[R]、例えば[***]を出力するか、エラーを投げつける。

ノート内の固定ストリング値とダイナミックカットオフを組み合わせる正しいコードを見つけ出す手助けをしてください。

答えて

0

これは興味深い問題です。コードを調べた後には、[***],[**]などを適切なカットオフに置き換えたコードがの前にのコードが適用されるため、コードが検査されたと思います。だから、解決策は正しい順序で来るようにコードを並べ替えることです。これには少しコード手術が必要です。以下は私のために働く。私はstargazer_5.2を実行しています:

library(stargazer) 

## Create new stargazer.wrap() to rearrange order of blocks 
x <- capture.output(stargazer:::.stargazer.wrap) 
idx <- c(grep("for \\(i in 1:length\\(\\.format\\.cutoffs\\)\\)", x)[2], 
    grep("if \\(!is\\.null\\(notes\\)\\)", x), 
    grep("if \\(!is\\.null\\(notes\\.align\\)\\)", x)[2]) 
eval(parse(text = paste0("stargazer.wrap <- ", paste(x[c(1:(idx[1] - 1), 
    (idx[2]):(idx[3] - 1), 
    idx[1]:(idx[2] - 1), 
    idx[3]:(length(x) - 1))], collapse = "\n")))) 

## Create a new stargazer.() that uses our modified stargazer.wrap() function 
x <- capture.output(stargazer) 
x <- gsub(".stargazer.wrap", "stargazer.wrap", x) 
eval(parse(text = paste0("stargazer. <- ", paste(x[-length(x)], collapse = "\n")))) 

結果:まず、前:ご指摘のよう

stargazer(lm(mpg ~ wt, mtcars), 
    type = "text", 
    notes.append = FALSE, 
    notes = c("Signif. codes: 0 $***$ [.***] $**$ [.**] $*$ [.*]")) 
# =============================================================== 
#         Dependent variable:    
#      ------------------------------------------- 
#           mpg      
# --------------------------------------------------------------- 
# wt         -5.344***     
#          (0.559)     

# Constant        37.285***     
#          (1.878)     

# --------------------------------------------------------------- 
# Observations       32      
# R2          0.753     
# Adjusted R2       0.745     
# Residual Std. Error    3.046 (df = 30)    
# F Statistic     91.375*** (df = 1; 30)   
# =============================================================== 
# Note:    Signif. codes: 0 *** [.***] ** [.**] * [.*] 

私たちは、問題を抱えています。さて、私たちの変更されたstargazer.()関数を使用してください(最後の点に注意してください):

stargazer.(lm(mpg ~ wt, mtcars), 
    type = "text", 
    notes.append = FALSE, 
    notes = c("Signif. codes: 0 $***$ [.***] $**$ [.**] $*$ [.*]")) 
# ======================================================== 
#        Dependent variable:   
#      ------------------------------------ 
#          mpg     
# -------------------------------------------------------- 
# wt        -5.344***    
#         (0.559)    

# Constant       37.285***    
#         (1.878)    

# -------------------------------------------------------- 
# Observations       32     
# R2         0.753     
# Adjusted R2      0.745     
# Residual Std. Error   3.046 (df = 30)   
# F Statistic    91.375*** (df = 1; 30)  
# ======================================================== 
# Note:    Signif. codes: 0 *** .01 ** .05 * .1 
関連する問題