0

I want to report correlation tables in a latex report and I'm using 'stargazer' to transform my R objects into tex-code. The correlational data is currently stored in a data frame.

I would like to print rownames and possibly add an annotation under the table. I couldn't find a 'print rownames'-argument and the 'notes'-argument doesn't seem to work.

Any Ideas?

## 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")
stats-hb
  • 958
  • 13
  • 31
  • PS: I also wonder how to align the values properly. positive and negative values both seem to be displayed centered, which leads to a unsteady display. When i use 'align = TRUE', the full values (1) are set too far to the left, compared to the correlations (e.g. .33). Does anyone know an alternative? – stats-hb Oct 12 '13 at 20:22

3 Answers3

1

As of version 5.0, stargazer can directly output the content of matrices/vectors. The following code should provide an easy and intuitive resolution to your problem:

## 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")
0

This is rather a markdown solution that can be converted to LaTeX with e.g. Pandoc:

> require(pander)
> pander(x, caption = 'Annotation')

---------------
&nbsp;   A   B 
------- --- ---
 **A**   1   2 

 **B**   3   4 
---------------

Table: Annotation
daroczig
  • 28,004
  • 7
  • 90
  • 124
0

To get the 'rownames', try this hackish solution:

## 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")

At the moment (v. 4.5.1), 'stargazer' is best suited to working with regression tables and data frames. Your question, however, suggests that users might be interested in better support for matrices. Expect this in future releases (next few months).

As for notes, these really only work for regression tables at the moment. However, they will be available for summary statistics and data frame tables in the next release. If you're willing to edit the source, you can get something very close (although not quite perfect) to the future implementation by replacing the following line(s):

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

by:

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