用 r 为 tex 格式化 ttest 输出 [英] Format ttest output by r for tex

查看:16
本文介绍了用 r 为 tex 格式化 ttest 输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了格式化 R 为 Tex 生成的回归输出,我使用 stargazer.但是,此命令不适用于简单的 t.test 输出(% 错误:无法识别的对象类型).我知道xtable"和schoRsch"包,但是在应用这两个包时会丢失一些信息.有谁知道另一个命令?非常感谢!

解决方案

试试

... 请注意完全不可靠的对齐方式和负数的错误格式.我放弃了尝试让它工作:我建议放弃 stargazer,它不喜欢定制.

总而言之,stargazer 的输出并不像他们声称的那样漂亮"或易于使用":他们的表格格式很混乱,并且与表格格式的最佳实践相冲突(总结在 booktabs 包文档).该函数无法为自己的类型进行有意义的自定义,而是提供了一堆参数.哦,尽管他们声称支持大量模型",但他们甚至不支持基础 R 假设检验.

stargazer 是一个非常糟糕的软件包.

For formatting my regression outputs generated by R for Tex, I use stargazer. However this command doesn't work for a simple t.test ouput (% Error: Unrecognized object type). I know the "xtable" and "schoRsch" packages, however there is some loss of information, when applying these two. Does anyone know another command? Thank you very much!

解决方案

Give Pander a try, it’s an all round good table formatting package for R, and supports the t.test result type. I’m not sure whether it leaves out too much information for your taste, though.

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

Pander produces Markdown rather than LaTeX tables, so the result needs to be transformed into LaTeX using pandoc.

Alternatively, you can use broom to generate a regular table form your t.test result, and stargaze that:

stargazer(tidy(result))

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


Extending stargazer for other types is effectively not possible, since everything is hard-coded in the function. The only thing you can do is put the data of interest into a data.frame and pass that to stargazer. You may want to play with this approach a bit. Here’s a basic example of what you could 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 produce the following output:

… Note the completely wonky alignment and the wrong formatting of negative numbers. I gave up trying to get this to work: I would suggest dropping stargazer, it doesn’t like customisation.

In summary, the stargazer output isn’t nearly as "beautiful" or "easy to use" as they claim: their table formatting is cluttered and runs afoul of best practices for table formatting (which are summarised in the booktabs package documentation). The function is impossible to customise meaningfully for own types and instead offers a jungle of parameters. Oh, and despite their claim of supporting "a large number of models", they don’t even support the base R hypothesis tests.

At the risk of sounding divisive, stargazer is a pretty terrible package.

这篇关于用 r 为 tex 格式化 ttest 输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆