Why does RStudio return a "perhaps a missing \item" error with this code?

25 Views Asked by At

For some reason, when I try to knit this to a pdf in Rstudio it returns a missing \item error.

\begin{enumerate}[series=numbers]
  \item
  \begin{enumerate}[series=letters1]
    \item D$_i$ $\sim$ Binomial(n=6, p=$\pi$), 1$\leq$ i $\leq$ n, i.e. whether the k-th O-ring is distressed is modelled by O$_k$ $\stackrel{iid}{\sim}$ Bernoulli($\pi$), 1 $\leq$ k $\leq$ 6, in each observation.
    \item Let \textbf{D} = (D$_1$, \ldots, D$_n$) with realisation \textbf{d} = (d$_1$, \ldots, d$_n$). Then
$$L(\pi|\textbf{D}=\textbf{d})=\prod_{i=1}^n\textrm{P}(D_i=d_i)=\prod_{i=1}^n\frac{6!}{d_i!(6-d)!}\pi^{d_i}(1-\pi)^{6-d_i}$$
since D$_1$,\ldots,D$_n$ are iid.
    \item $$\textrm{log}L(\pi|\textbf{D}=\textbf{d})=\sum_{i=1}^n\left(\textrm{log}\left(\frac{6!}{d_i!(6-d)!}\right)+d_i\textrm{log}(\pi)+(6-d_i)\textrm{log}(1-\pi)\right).$$
Differentiating and equating to 0 gives
$$\frac{\partial}{\partial\pi}\textrm{log}L(\pi|\textbf{D}=\textbf{d})=\sum_{i=1}^n\left(0+\frac{d_i}{\pi}-\frac{6-d_i}{1-\pi}\right)=\frac{\sum_{i=1}^nd_i}{\pi}-\frac{6n-\sum_{i=1}^nd_i}{1-\pi}\stackrel{!}{=}0.$$
This gives $\hat{\pi}=\frac{\sum_{i=1}^nd_i}{6n}$ as a candidate for the MLE of $\pi$.
      \begin{equation*}
        \begin{aligned}
\frac{\partial^2}{\partial\pi^2}\textrm{log}L(\hat{\pi}|\textbf{D}=\textbf{d})&=-\frac{\sum_{i=1}^nd_i}{\hat{\pi}^2}-\frac{6n-\sum_{i=1}^nd_i}{(1-\hat{\pi})^2}\\&=-\frac{\sum_{i=1}^nd_i}{(\frac{\sum_{i=1}^nd_i}{6n})^2}-\frac{6n-\sum_{i=1}^nd_i}{(1-\frac{\sum_{i=1}^nd_i}{6n})^2}\\&=-\frac{36n^2}{\sum_{i=1}^nd_i}-\frac{6n-\sum_{i=1}^nd_i}{(1-\frac{\sum_{i=1}^nd_i}{6n})^2}\\&<0
        \end{aligned}
      \end{equation*}
The second derivative of log$L(\pi|\textbf{D}=\textbf{d})$ evaluated at $\hat{\pi}$ is
since both terms are negative. Hence $\hat{\pi}$ is confirmed as the MLE of $\pi$. The following code computes the maximum likelihood estimate for our data:
\end{enumerate}
\end{enumerate}

```{r, comment=''}
D.challenger<-read.csv('challenger.csv')['D']
n<-23
MLE.pi<-sum(D.challenger)/(6*n)
message(MLE.pi)

```