【发布时间】:2021-01-17 18:40:50
【问题描述】:
下面的第二部分代码写在 Markdown 部分,而第一部分代码生成 R 调用的对象。例如,我将设置
homoscedastic_variance = 1
heterokesdastic_variance = 1
$$Var_{homo}(\hat{\tau}) = \frac{1}{N_tN_c}\sum_{i=1}^N (Y_i - \bar{Y}) = `r homoscedastic_variance`$$
While the heteroskedastic is estimated as:
$$Var_{hetero}(\hat{\tau}) = \frac{1}{N_t} s_t^2 + \frac{1}{N_c}s_c^2 = `r heterokesdastic_variance`$$
with $s_c = \frac{1}{N_c - 1}\sum_{i: W_i = 0} (Y_i - \bar{Y_c})^2 $ and analogously for $s_t$.
Then, we can make two confidence intervals:
$CI_{homo} = [`r treatment_effect` \pm 1.96*sqrt(`r homoscedastic_variance`)]$
$CI_{hetero} = [`r treatment_effect` \pm 1.96*sqrt(`r heterokesdastic_variance`)]$
使用 knit -> PDF 选项时,我收到此错误:
! Missing $ inserted.
<inserted text>
$
l.108 with \$s\_c = \frac{1}{N_c - 1}
\sum\_\{i: W\_i = 0\} (Y\_i -
Try to find the following text in script_ps1.Rmd:
with \$s\_c = \frac{1}{N_c - 1}
You may need to add $ $ around a certain inline R expression `r ` in script_ps1.Rmd (see the above hint).
See https://github.com/rstudio/rmarkdown/issues/385 for more info.
Erro: LaTeX failed to compile script_ps1.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See script_ps1.log for more info."
我在 LaTeX 中试过这个,它编译得很好;任何人都知道为什么我得到这个错误?我觉得有趣的是它建议使用 $ $ 内联 R 表达式,但该错误与具有任何内联 R 表达式的表达式无关(如果我删除“with $s_c ...”部分,编织就可以了!
【问题讨论】:
标签: r r-markdown