Ttest r output format for tex

To format my regression outputs created by R for Tex, I use stargazer. However, this command does not work for the simple t.test (% Error: Unrecognized object type) command. I know the "xtable" and "schoRsch" packages, however when using these two there is some loss of information. Does anyone know another team? Thank you very much!

+4
source share
1 answer

Give Pander a try, its full round table formatting format for R and supports the result type t.test . I'm not sure if this leaves too much information for your taste.

 result = t.test(…) pander(result) 

Pander produces Markdown, not LaTeX tables, so the result needs to be converted to LaTeX using pandoc.

Alternatively, you can use broom to generate a regular table with the result of t.test and evaluate that:

 stargazer(tidy(result)) 

Broom also knows the glance function for reduced output, however for t.test result is the same.


Extending stargazer to other types is virtually impossible, since everything is hard-coded into a function. The only thing you can do is put the data of interest in data.frame and pass it to stargazer . You might want to play a little with this approach. Here is a basic example of what you can do:

 stargazer_htest = function (data, ...) { summary = data.frame(`Test statistic` = data$statistic, DF = data$parameter, `p value` = data$p.value, `Alternative hypothesis` = data$alternative, check.names = FALSE) stargazer(summary, flip = TRUE, summary = FALSE, notes = paste(data$method, data$data.name, sep = ': '), ...) } 

And then use it like this:

 stargazer_htest(t.test(extra ~ group, data = sleep)) 

To create the following output:

screenshot

... Pay attention to completely winning alignment and incorrect formatting of negative numbers. I gave up trying to make it work: I propose to abandon the star enemy, he does not like settings.

Thus, the output of stargazer is not as “beautiful” or “easy to use” as they claim: their table formatting is cluttered and works with best practices for formatting the table (which are summarized in booktabs batch documentation). The function cannot be individually configured for its own types and instead offers a jungle of parameters. Oh, and despite their claims to support "a large number of models," they don’t even support base R hypothesis tests.

With the risk of voicing splits, stargazer is a pretty scary package.

+6
source

All Articles