【发布时间】:2021-08-14 02:45:42
【问题描述】:
有没有可能将 psych Package mediate() 函数的汇总统计数据转换为 Latex ?
到目前为止,我尝试了 stargazer、texreg 和 xtable - 但没有成功...
#check and install required packages
if (!require("psych")) install.packages("psych")
if (!require("stargazer")) install.packages("stargazer")
if (!require("texreg")) install.packages("texreg")
if (!require("xtable")) install.packages("xtable")
#load required packages
library(psych)
library(stargazer)
library(texreg)
library(xtable)
#data from Preacher and Hayes (2004)
sobel <- structure(list(SATIS = c(-0.59, 1.3, 0.02, 0.01, 0.79, -0.35,
-0.03, 1.75, -0.8, -1.2, -1.27, 0.7, -1.59, 0.68, -0.39, 1.33,
-1.59, 1.34, 0.1, 0.05, 0.66, 0.56, 0.85, 0.88, 0.14, -0.72,
0.84, -1.13, -0.13, 0.2),
THERAPY = structure(c(0, 1, 1, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0),
value.labels = structure(c(1, 0), .Names = c("cognitive", "standard"))),
ATTRIB = c(-1.17, 0.04, 0.58, -0.23, 0.62, -0.26, -0.28, 0.52, 0.34, -0.09, -1.09, 1.05, -1.84, -0.95, 0.15, 0.07,
-0.1, 2.35, 0.75, 0.49, 0.67, 1.21, 0.31, 1.97, -0.94, 0.11, -0.54, -0.23, 0.05, -1.07)), .Names = c("SATIS", "THERAPY", "ATTRIB"),
row.names = c(NA, -30L), class = "data.frame", variable.labels = structure(c("Satisfaction", "Therapy", "Attributional Positivity"),
.Names = c("SATIS", "THERAPY", "ATTRIB")))
#n.iter set to 50 (instead of default of 5000) for speed of example
res <- mediate(1,2,3,sobel,n.iter=50) #The example in Preacher and Hayes
res
summary(res)
【问题讨论】: