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

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

问题描述

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

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!

推荐答案

给予 Pander 尝试一下,它是R的全面表格式化程序包,并支持t.test结果类型.不过,我不确定是否会遗漏过多的信息来满足您的口味.

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生成Markdown而不是LaTeX表,因此需要使用pandoc将结果转换为LaTeX.

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

或者,您可以使用 broom 从您的t.test结果生成正则表,并注视

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

stargazer(tidy(result))

Broom也知道glance函数用于减少输出,但是,对于t.test,结果是相同的.

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

实际上不可能将stargazer扩展为其他类型,因为所有内容都在函数中进行了硬编码.您唯一可以做的就是将感兴趣的数据放入data.frame,并将其传递给stargazer.您可能需要使用这种方法.这是您可以做什么的基本示例:

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 = ': '), ...)
}

然后像这样使用它:

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

产生以下输出:

…请注意完全不正确的对齐方式和错误的负数格式.我放弃了尝试使其工作:我建议放弃观星者,这不像自定义.

… 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.

总而言之,观星者的输出并不像他们声称的那样美丽"或易于使用":它们的表格式混乱,并且与表格式的最佳做法不符( booktabs 包文档).该函数无法针对自己的类型进行有意义的自定义,而是提供了一系列参数.哦,尽管他们声称支持大量模型",但他们甚至不支持基本R假设检验.

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天全站免登陆