Home > OS >  Why is LaTeX failing to compile in RMarkdown
Why is LaTeX failing to compile in RMarkdown

Time:04-03

My code should be a pretty easy knit to a pdf, but it will not compile and I'm getting this message in R Markdown:

! LaTeX Error: Unicode character ₁ (U 2081) not set up for use with LaTeX.

Error: LaTeX failed to compile L-work-5.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See L- work-5.log for more info. Execution halted

here is the code:


---
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
```

CodePudding user response:

For a start, try deleting the special characters and in the line

two independent variables, X~₁i~ and X~₂i~

This will let you compile.

You might be able to get this to work by including something like

\newunicodechar{₁}{\ensuremath{{}_1}}

and similarly for the subscript-2 character, at the top of your file (from this TeX Stack Exchange question), but I haven't tested it and don't want to go down that rabbit hole right now ...

Or just change the relevant text to

two independent variables, $X_{1i}$ and $X_{2i}$

which will probably typeset it as originally intended!

  • Related