为什么 LaTeX 无法在 RMarkdown 中编译
Why is LaTeX failing to compile in RMarkdown
我的代码应该很容易编织成 pdf,但它无法编译,我在 R Markdown 中收到此消息:
! LaTeX 错误:Unicode 字符 ₁ (U+2081)
未设置为与 LaTeX 一起使用。
错误:LaTeX 无法编译 L-work-5.tex。有关调试提示,请参阅 https://yihui.org/tinytex/r/#debugging。有关详细信息,请参阅 L-work-5.log。
执行暂停
代码如下:
---
title: "work 5"
author: "PLars"
date: "4/2/2022"
output: pdf_document
fonttheme: professionalfonts
fontsize: 12pt
editor_options:
markdown:
wrap: 72
---
```{r, echo = FALSE, results = "hide", message = FALSE, purl = FALSE}
library(knitr)
opts_chunk$set(tidy = FALSE,
fig.align = "left",
background = '#a6a6a6',
fig.width = 10,
fig.height = 10,
out.width ="\linewidth",
out.height = "\linewidth",
message = FALSE,
warning = FALSE,
fig.align = "left"
)
options(width = 55, digits = 3)
library(scales)
percent <- function(x, digits = 2, format = "f", ...) {
paste0(formatC(100 * x, format = format, digits = digits, ...), "%")
}
library(haven)
library(tinytex)
library(stargazer)
library(tidyverse)
library(texreg)
library(dplyr)
library(texreg)
library(AER)
library(tidyverse)
```
**Part I - Categorical Models (5 points)**
Say that you estimate an ordered logit model with a three category
dependent variable and two independent variables, X~₁i~ and X~₂i~, and
obtain the following results:
```{=tex}
\begin{center}
\begin{tabular}{c|rc}
\hline \hline
& $\hat{\beta}$ & SE \
\hline
$X_{1}$ & $-0.68$ & $(0.23)$ \
$X_{2}$ & $-0.47$ & $(0.13)$ \
\hline
$\tau_1$ & $-1.02$ & $(0.46)$ \
$\tau_2$ & $.85$ & $(0.21)$ \
\hline
\end{tabular}
\end{center}
```
```{=tex}
\begin{enumerate}
\item Calculate $\Pr(Y_i=1 | X_{1i}=1, X_{2i}=0)$.
\item Calculate $\Pr(Y_i=2 | X_{1i}=1, X_{2i}=0)$.
\item Calculate $\Pr(Y_i=3 | X_{1i}=1, X_{2i}=0)$.
\item Calculate the first difference (difference in probability in category) that result from changing X_{2i} from -2 to 2, holding X_{1i} fixed at 0. Do calculations for each possible value of Y_i.
\item Explain how we might assess whether the parallel regression assumption holds for this model? If it does not, what alternative might you pursue if this were your model?
\end{enumerate}
```
#
First, we calculate $X_i \beta$
```{r}
(xiB <- (-.068*1) + (-0.47*0))
```
Then, plug into the following equations:
```{r}
(prob1 <- 1/(1 + exp(-(-1.02-xiB))))
(prob2 <- 1/(1 + exp(-(.85-xiB))) - prob1)
(prob3 <- 1 - (1/(1 + exp(-(.85-xiB)))))
prob1 + prob2 + prob3
```
首先,尝试删除行
中的特殊字符 ₁
和 ₂
two independent variables, X~₁i~ and X~₂i~
这会让你编译。
您可能可以通过包含类似
的东西来实现它
\newunicodechar{₁}{\ensuremath{{}_1}}
下标 2 字符也类似,位于文件的顶部(来自 this TeX Stack Exchange question),但我尚未对其进行测试,现在不想掉进那个兔子洞。 ..
或者将相关文字改为
two independent variables, $X_{1i}$ and $X_{2i}$
这可能会按原意排版!
我的代码应该很容易编织成 pdf,但它无法编译,我在 R Markdown 中收到此消息:
! LaTeX 错误:Unicode 字符 ₁ (U+2081) 未设置为与 LaTeX 一起使用。
错误:LaTeX 无法编译 L-work-5.tex。有关调试提示,请参阅 https://yihui.org/tinytex/r/#debugging。有关详细信息,请参阅 L-work-5.log。 执行暂停
代码如下:
---
title: "work 5"
author: "PLars"
date: "4/2/2022"
output: pdf_document
fonttheme: professionalfonts
fontsize: 12pt
editor_options:
markdown:
wrap: 72
---
```{r, echo = FALSE, results = "hide", message = FALSE, purl = FALSE}
library(knitr)
opts_chunk$set(tidy = FALSE,
fig.align = "left",
background = '#a6a6a6',
fig.width = 10,
fig.height = 10,
out.width ="\linewidth",
out.height = "\linewidth",
message = FALSE,
warning = FALSE,
fig.align = "left"
)
options(width = 55, digits = 3)
library(scales)
percent <- function(x, digits = 2, format = "f", ...) {
paste0(formatC(100 * x, format = format, digits = digits, ...), "%")
}
library(haven)
library(tinytex)
library(stargazer)
library(tidyverse)
library(texreg)
library(dplyr)
library(texreg)
library(AER)
library(tidyverse)
```
**Part I - Categorical Models (5 points)**
Say that you estimate an ordered logit model with a three category
dependent variable and two independent variables, X~₁i~ and X~₂i~, and
obtain the following results:
```{=tex}
\begin{center}
\begin{tabular}{c|rc}
\hline \hline
& $\hat{\beta}$ & SE \
\hline
$X_{1}$ & $-0.68$ & $(0.23)$ \
$X_{2}$ & $-0.47$ & $(0.13)$ \
\hline
$\tau_1$ & $-1.02$ & $(0.46)$ \
$\tau_2$ & $.85$ & $(0.21)$ \
\hline
\end{tabular}
\end{center}
```
```{=tex}
\begin{enumerate}
\item Calculate $\Pr(Y_i=1 | X_{1i}=1, X_{2i}=0)$.
\item Calculate $\Pr(Y_i=2 | X_{1i}=1, X_{2i}=0)$.
\item Calculate $\Pr(Y_i=3 | X_{1i}=1, X_{2i}=0)$.
\item Calculate the first difference (difference in probability in category) that result from changing X_{2i} from -2 to 2, holding X_{1i} fixed at 0. Do calculations for each possible value of Y_i.
\item Explain how we might assess whether the parallel regression assumption holds for this model? If it does not, what alternative might you pursue if this were your model?
\end{enumerate}
```
#
First, we calculate $X_i \beta$
```{r}
(xiB <- (-.068*1) + (-0.47*0))
```
Then, plug into the following equations:
```{r}
(prob1 <- 1/(1 + exp(-(-1.02-xiB))))
(prob2 <- 1/(1 + exp(-(.85-xiB))) - prob1)
(prob3 <- 1 - (1/(1 + exp(-(.85-xiB)))))
prob1 + prob2 + prob3
```
首先,尝试删除行
中的特殊字符₁
和 ₂
two independent variables, X~₁i~ and X~₂i~
这会让你编译。
您可能可以通过包含类似
的东西来实现它\newunicodechar{₁}{\ensuremath{{}_1}}
下标 2 字符也类似,位于文件的顶部(来自 this TeX Stack Exchange question),但我尚未对其进行测试,现在不想掉进那个兔子洞。 ..
或者将相关文字改为
two independent variables, $X_{1i}$ and $X_{2i}$
这可能会按原意排版!