【问题标题】:Annotated correlation tables with stargazer带有stargazer的带注释的相关表
【发布时间】:2013-10-12 20:19:46
【问题描述】:

我想在乳胶报告中报告相关表,我正在使用“stargazer”将我的 R 对象转换为 tex 代码。相关数据当前存储在数据框中。

我想打印 rownames 并可能在表格下方添加 注释。我找不到 'print rownames' 参数,而 'notes' 参数似乎不起作用。

有什么想法吗?

## create object
x           <- matrix(1:4, 2, byrow = TRUE)
dimnames(x) <- list(c("A", "B"), c("A", "B"))
x           <- data.frame(x)

## create Tex-Code
stargazer(x, summary = FALSE, title = "2x2 Matrix",
          notes = "This is a two by two Matrix")

【问题讨论】:

  • PS:我也想知道如何正确对齐值。正值和负值似乎都居中显示,导致显示不稳定。当我使用'align = TRUE'时,与相关性(例如 .33)相比,完整值(1)设置在左侧太远。有人知道替代方案吗?

标签: r latex stargazer


【解决方案1】:

从5.0版本开始,stargazer可以直接输出矩阵/向量的内容。以下代码应该为您的问题提供简单直观的解决方案:

## create object
x           <- matrix(1:4, 2, byrow = TRUE)
dimnames(x) <- list(c("A", "B"), c("A", "B"))

## create Tex-Code
stargazer(x, title = "2x2 Matrix",
          notes = "This is a two by two Matrix")

【讨论】:

    【解决方案2】:

    这是一个降价解决方案,可以使用例如转换为 LaTeX。 Pandoc:

    > require(pander)
    > pander(x, caption = 'Annotation')
    
    ---------------
    &nbsp;   A   B 
    ------- --- ---
     **A**   1   2 
    
     **B**   3   4 
    ---------------
    
    Table: Annotation
    

    【讨论】:

      【解决方案3】:

      要获取“行名”,请尝试以下骇人听闻的解决方案:

      ## create object
      x           <- matrix(1:4, 2, byrow = TRUE)
      x           <- data.frame(x)
      x           <- cbind(c("A","B"),x)
      colnames(x) <- c("","A", "B")
      
      ## create Tex-Code
      stargazer(x, summary = FALSE, title = "2x2 Matrix",
                notes = "This is a two by two Matrix", type="text")
      

      目前(v. 4.5.1),“stargazer”最适合使用回归表和数据框。但是,您的问题表明用户可能对更好地支持矩阵感兴趣。预计在未来的版本(接下来的几个月)中会出现这种情况。

      至于注释,这些目前仅适用于回归表。但是,它们将在下一版本中用于汇总统计信息和数据框表。如果您愿意编辑源代码,则可以通过替换以下行来获得与未来实现非常接近(虽然不是很完美)的东西:

      .format.s.stat.parts <<- c("-!","stat names","-!","statistics1","-!")
      

      作者:

      .format.s.stat.parts <<- c("-!","stat names","-!","statistics1","-!","notes")
      

      【讨论】:

        猜你喜欢
        • 2022-01-14
        • 1970-01-01
        • 2016-09-18
        • 2021-12-20
        • 1970-01-01
        • 2019-09-16
        • 2022-12-16
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多