【发布时间】:2016-01-28 09:02:52
【问题描述】:
我想用 knitr 写一篇可重复的社会科学论文。因此,我想使用 knitr 内联块打印验证性因子分析的拟合指数。
我的最小例子:
\documentclass{article}
\begin{document}
Run a lavaan model
<<lavaanmodel>>=
library(lavaan)
## cfa model from help
HS.model <- ' visual =~ x1 + x2 + x3
textual =~ x4 + x5 + x6
speed =~ x7 + x8 + x9 '
cfaout <- cfa(HS.model, data=HolzingerSwineford1939)
@
Specifiy a fitprintfunction
<<fpf_def>>=
fpf_la <- function(x){ fm_tmp <- fitmeasures(x)
cat("\\chi^2 = ", fm_tmp[c("chisq")],
", df = ", fm_tmp[c("df")],
", RMSEA = ", fm_tmp[c("rmsea")],
", CFI = ", fm_tmp[c("cli")],
", TLI = ", fm_tmp[c("tli")],
", SRMR = ", fm_tmp[c("srmr")],
sep = "")}
@
Print the fit inline:\\
The specified model resulted in good model fit $\Sexpr{fpf_la(cfaout)}$
\end{document}
问题:$\Sexpr{fpf_la(cfaout)}$ 没有任何结果。
我猜想在内联块中处理非数字输出会导致问题?
【问题讨论】: