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)\\
$$
```