我尝试让Latex和knitr以标准化的\Sexpr{}输出统计数据。
例如:我计算了一个相关性:
mycor<-cor.test(a,b)
假设结果如下:
Pearson's product-moment correlation
data: a and b
t = 2.9413, df = 54, p-value = 0.004805
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
0.1204668 0.5780293
sample estimates:
cor
0.3715985
如何让LaTeX生成输出?
而不需要编写以下内容:
r(54)= .37,p <.01
$r(\Sexpr{mycor$parameter)=\Sexpr{mycor$estimate}$, $p < .05$
一直这样吗?
我想编写一个命令,让它适用于我所报告的每个相关性。请注意,我要寻找一种让它自动将p = 0.004805转换为p < .01的可能性。
顺便说一下:我已经尝试过用以下方法实现:
\newcommand{\repcor}[1]{$r(\Sexpr{#1$parameter)=\Sexpr{#1$estimate}$}
但这并不起作用...
提前感谢! 本杰明