我使用 psych::cortest.mat 对相关矩阵进行了比较。我想将输出放在 Sweave 文件中,以便使用 knitr 进行生产。当我使用 Hmisc::latex() 函数时,它可以工作,但它也会为每个结果产生大约 7 位数字,这使得它真的没有吸引力。我可以在 knitr 中使用 markup 参数生成输出,但我文档中的所有其他表都可以使用 latex output (results='asis') 更有效地生成。
想法?
#Sample data
variable1<-rnorm(100, mean=7, sd=1)
variable2<-rnorm(100, mean=4, sd=1)
variable3<-rnorm(100, mean=6, sd=1)
variable4<-rnorm(100, mean=8, sd=2)
variable5<-rnorm(100, mean=9, sd=1)
variable6<-rnorm(100, mean=7, sd=3)
#Correlation matrices
cor.mat1<-cor(data.frame(variable1, variable2, variable3))
cor.mat2<-cor(data.frame(variable4, variable5, variable6))
library(psych)
library(Hmisc)
#Compare matrices
cor.comparison<-cortest.mat(cor.mat1, cor.mat2, n1=100, n2=100)
#try to print
latex(cor.comparison, file='')
#try unclassing
test<-unclass(cor.comparison)
#Try with lapply
lapply(test, function(x) round(x,2))
#try also changing options(digits=)
options(digits=3)
latex(cor.comparison, file='')