# Latex is not knitting

I have a lot of latex code that appears just fine in the .Rmd file on Rstudio, but it does not compile properly. I am attaching an image of what the html output looks like

. This is the code in question:

$$\text{Let} \\ \hat{\beta} = \text{argmin}_{\beta \epsilon \mathbb{R}^2} \Bigg\{ \sum_{k=i}^nw_i(y_i-\beta_0 - \beta_1x_i)^2 \Bigg\}\\ \text{we want to show that} \ w_i \ \text{are weights that correspond to the maximum-liklihood solution under heterskedastic Gausian error}\\ \hat\beta=\text{argmax}_{\beta \epsilon \mathbb{R}^2} \Bigg\{ \prod_{k=i}^np(y_i|\beta,\sigma_i^2) \Bigg\} \\$$

$$\text{where} \\ p(y_i|\beta,\sigma_i^2) = N(\beta_0+\beta_1x_i, \sigma_i^2)\\$$

$$\text{Recall from part a) that we can transform the maximum liklihood function to log-liklihood} \\ L[Y|\beta, \sigma_i^2] = \prod_{i=1}^n\bigg( (2\pi\sigma_i^2)^{-\frac{1}{2}}e^{-\frac{1}{2} \bigg( \frac{y_i-\hat\beta_0-\hat\beta_1x_i}{\sigma_i}\bigg)^2} \bigg) \\ L[Y|\beta, \sigma_i^2] = \prod_{i=1}^n\bigg( (2\pi\sigma_i^2)^{-\frac{1}{2}}\bigg) e^{-\frac{1}{2} \sum_{i=1}^n \bigg( \frac{y_i-\hat\beta_0-\hat\beta_1x_i}{\sigma_i}\bigg)^2} \\ \ln(L[Y|\beta, \sigma_i^2] ) =- \frac{1}{2} \ln \bigg(\prod_{i=1}^n\bigg( (2\pi\sigma_i^2)\bigg)\bigg) -\frac{1}{2}\sum_{i=1}^n \bigg( \frac{y_i-\hat\beta_0-\hat\beta_1x_i}{\sigma_i}\bigg)^2 \bigg)\\$$


It's not abundantly clear what's causing the issue based on your screenshot and your code snippet. And your code-chunk doesn't appear to match your screenshot.

Based on what I see, the best solution I can suggest is to be sure to treat your text as text in your RMarkdown doc and your math as math, for example,

---
title: "reprex"
output: pdf_document
---

Let

$$\hat\beta = \text{argmin}_{\beta \epsilon \mathbb{R}^2} \Bigg\{ \sum_{k=i}^nw_i(y_i-\beta_0 - \beta_1x_i)^2 \Bigg\}\$$

we want to show that $w_i$ are weights that correspond to the maximum-liklihood solution under heterskedastic Gausian error

$$\hat\beta=\text{argmax}_{\beta \epsilon \mathbb{R}^2} \Bigg\{ \prod_{k=i}^np(y_i|\beta,\sigma_i^2) \Bigg\} \\$$



This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.