I am doing homework (yes) but this question is about the R Markdown I am using to render the answers, rather than the homework question itself. I hope that's fine.
When I use code chunks inside a ordered list (the problems are numbered so almost everything is in numbered lists), then ordered list items after it are rendered verbatim (so inline equations are rendered like: $\beta_0$ instead of showing the symbols) and don't wrap even though I have tidy=TRUE and width.cutoff set to 50. They run right off the page. They also aren't indented, which makes it further clear that they aren't getting evaluated as ordered list items. The width.cutoff option works for the code chunks but not for the ordered list items, for some reason. I can't find this error anywhere else online. I found these questions: How to wrap code and the output in markdown (.Rmd)
knitr: How to prevent text wrapping in output?
In R markdown in RStudio, how can I prevent the source code from running off a pdf page?
but they all just seem to tell me to play with the width or width.cutoff options, which I have already done and aren't working. I attach some test code below and a screenshot of what the pdf comes out to be(link to disappointing image). As you can see, the a. part comes out fine, but b, c, and sub-questions do not. In the larger file, the top-level numbered list also has this problem. If anyone has any ideas please let me know.
Also, I don't know if this is important, but these lines show in RStudio in blue, unless I add another line break before them, in which case they turn back to black and thereafter alternate between blue and black. But the color doesn't seem to matter, they still get rendered the same way in the same place. I've tried double spaces at the ends of the previous lines, no change. The only thing that makes them not render as verbatim is to delete the new lines before them and allow them to be right next to the text line above them, but since they aren't indented this makes them look like they're part of the previous question and is problematic for reading. Thank you in advance for any help!
---
title: "TestThing"
output:
pdf_document:
latex_engine: xelatex
header-includes:
- \usepackage{amsmath,amsthm,amssymb,graphicx,epstopdf}
---
```{r echo=FALSE, warning=FALSE}
library(knitr)
library(foreign)
library(car)
library(xtable)
library(plyr)
library(reshape2)
```
```{r set-options, echo=FALSE, cache=FALSE}
options(width=50)
opts_chunk$set(comment = "", warning = FALSE, message = FALSE, echo = TRUE, tidy = TRUE, size="small", width.cutoff=50)
```
3. Problem 3
(a) Some amount of text.
Solving for $\hat{\beta}$:
\begin{equation}
\begin{aligned}
(y-X\hat{\beta})'(y-X\hat{\beta}) &= y'y - \hat{\beta}'X'y - y'X\hat{\beta} + \hat{\beta}'X'X\hat{\beta} \\
... \\
\hat{\beta} &= (X'X)^{-1}(X'y)
\end{aligned}
\end{equation}
This solution is well-defined if there is no perfect collinearity among variables (that is, __X__ has full rank).
(b) Text long enough to show that it runs off the page. Why would it do that? After all the width options I set for it... Show that the conditional expectation function yadda yadda etc. etc..
The Zero Conditional Mean Assumption sucks. Since the fitted value $\hat{y}$ is created using OLS estimation and $\hat{y} = X\beta$, E[y|X] = $X\beta$ when the Zero Conditional Mean assumption holds.
(c) Express the values in terms of things.
a. Express the values in terms of the conditional expectations of X and Y:
B = E[Y|X=1]
C = E[Y|X=0]
D = B-C = unit change in Y per increase of 1 in X
b. Express the values in terms of $\beta_0$ and $\beta_1$:
B = $\beta_0 + \beta_1$
C = $\beta_0$
D = $\beta_1$
c. Use the data to estimate B, C, D, $\beta_0$ and $\beta_1$:
```{r echo=FALSE, results="asis"}
datathing <- data.frame(X=c(0,0,1,1), Y=c(1,3,5,7))
print(xtable(summary(lm(datathing$Y ~ datathing$X))), comment=FALSE)
```
B = $\beta_0 + \beta_1$ = 2 + 4 = 6
C = $\beta_0$ = 2
D = $\beta_1$ = 4