# How to write linear mixed model in latex?

How to write the following model in latex code? I am struggling with that part. I used begin{align*} and end{align*}. How to make a column vector inside the align command? I need to write (Vij1,Vij2)^T ~MVN(0,gamma) where ^T means transpose!! Thanks!!

• what you try so far? where you stuck? or you expected that someone will retype this equation system? welcome to tex.se! – Zarko Mar 2 '18 at 13:28
• Are you related to John Doe-Nut, perhaps? :P – Phelype Oleinik Mar 2 '18 at 13:28
• see en.wikibooks.org/wiki/LaTeX/Advanced_Mathematics. there are explained use of the most from existed math environments, also align and cases, which you need in your system of equations. – Zarko Mar 2 '18 at 13:42
• \stackrel{\scriptsize\textrm{Ind}}{\sim} might be useful. – John Kormylo Mar 2 '18 at 14:02
• Hi Zarko, How to make a column vector inside the align command? I need to write (Vij1,Vij2)^T ~MVN(0,gamma) where ^T means transpose!! – John Doe Mar 2 '18 at 14:03

I'd avoid aligning at the relation symbol, first because the equations are unbalanced by length of their sides, second because those relation signs are not really related to one another.

Define the commands you need, such as \cov, \isim and \MVN.

The three \! are needed for overriding a thin space that is automatically inserted in those cases.

\documentclass{article}
\usepackage{amsmath}

\DeclareMathOperator{\cov}{cov}
\DeclareMathOperator{\MVN}{MVN}
\newcommand{\isim}{\overset{\mathrm{ind}}{\sim}}

\begin{document}

\begin{align*}
& Y_{ijk}|U,V,A \isim N(\mu_{ijk},\tau^2) \\
& \mu_{ijk} = X_{ijk}\beta + U_i + V_{ij1} + V_{ij2}W_{ijk} + A_{ijk} \\
&\! \cov(A_{ijk},A_{lmn}) =
\begin{cases}
0 & \text{$i\ne l$ or $j\ne m$} \\
\sigma_A^2\exp(-|t_{ijk}-t_{lmn}|/\phi) & \text{$i=l$ and $j=m$}
\end{cases} \\
&\! \begin{pmatrix} V_{ij1} & V_{ij2} \end{pmatrix}^T = \MVN(0,\Gamma) \\
&\! \begin{pmatrix} V_{ij1} \\ V_{ij2} \end{pmatrix} = \MVN(0,\Gamma) \\
& U_i \isim N(0,\sigma_U^2)
\end{align*}

\end{document}


Another choice could be gather*, but it's less appealing to my eye.

\documentclass{article}
\usepackage{amsmath}

\DeclareMathOperator{\cov}{cov}
\DeclareMathOperator{\MVN}{MVN}
\newcommand{\isim}{\overset{\mathrm{ind}}{\sim}}

\begin{document}

\begin{gather*}
Y_{ijk}|U,V,A \isim N(\mu_{ijk},\tau^2) \\
\mu_{ijk} = X_{ijk}\beta + U_i + V_{ij1} + V_{ij2}W_{ijk} + A_{ijk} \\
\cov(A_{ijk},A_{lmn}) =
\begin{cases}
0 & \text{$i\ne l$ or $j\ne m$} \\
\sigma_A^2\exp(-|t_{ijk}-t_{lmn}|/\phi) & \text{$i=l$ and $j=m$}
\end{cases} \\
\begin{pmatrix} V_{ij1} & V_{ij2} \end{pmatrix}^T = \MVN(0,\Gamma) \\
\begin{pmatrix} V_{ij1} \\ V_{ij2} \end{pmatrix} = \MVN(0,\Gamma) \\
U_i \isim N(0,\sigma_U^2)
\end{gather*}

\end{document}


In both cases, I've added the two ways of representing the column vector. Choose the one you like better.