%\documentclass{article}
%\usepackage{amsmath}
%\begin{document}

\section{Turbulence}
{\bf \Large
\begin{tabular}{ccc}
\hline
  Corresponding author & : & Seiya Nishizawa\\
\hline
\end{tabular}
}

\def\half{\frac{1}{2}}

\subsection{Spatial filter}

The governing equations are the following:
\begin{align}
  \frac{\partial\rho}{\partial t} + \frac{\partial u_i \rho}{\partial x_i}
  &= 0 \\
  \frac{\partial\rho u_i}{\partial t}
  + \frac{\partial u_j \rho u_i}{\partial x_j}
  &= -\frac{\partial p}{\partial x_i} + g \rho \delta_{i3} \\
  \frac{\partial\rho \theta}{\partial t}
  + \frac{\partial u_i \rho \theta}{\partial x_i}
  &= Q
\end{align}

Spatially filtering the continuity equation yields:
\begin{equation}
  \frac{\partial \overline{\rho}}{\partial t} + \frac{\partial \overline{u_i \rho}}{\partial x_i} = 0, \label{eq: spatial filtered rho}
\end{equation}
where $\overline{\phi}$ indicates the spatially filtered quantity of an arbitrary variable $\phi$.
Favre filtering \citep{Favre_1983}, defined by:
\begin{equation}
  \widetilde{\phi} = \frac{\overline{\rho \phi}}{\overline{\rho}}
\end{equation}
renders the equation (\ref{eq: spatial filtered rho}):
\begin{equation}
  \frac{\partial \overline{\rho}}{\partial t} + \frac{\partial \widetilde{u_i}\overline{\rho}}{\partial x_i} = 0.
\end{equation}

The momentum equations become:
\begin{align}
  \frac{\partial \overline{\rho u_i}}{\partial t} + \frac{\partial \overline{u_j\rho u_i}}{\partial x_j} &= -\frac{\partial \overline{p}}{\partial x_i} + \overline{\rho} g\delta_{i3} \\
  \frac{\partial \overline{\rho}\widetilde{u_i}}{\partial t} + \frac{\partial \widetilde{u_j}\:\overline{\rho}\widetilde{u_i}}{\partial x_j} &= -\frac{\partial \overline{p}}{\partial x_i} + g\overline{\rho} \delta_{i3}
    -\frac{\partial}{\partial x_j}\left(\overline{u_i \rho u_j} - \widetilde{u_j}\overline{\rho}\widetilde{u_i}\right) \\
  \frac{\partial \overline{\rho}\widetilde{u_i}}{\partial t} + \frac{\partial \widetilde{u_j}\:\overline{\rho}\widetilde{u_i}}{\partial x_j} &= -\frac{\partial \overline{p}}{\partial x_i} + g\overline{\rho} \delta_{i3}
    -\frac{\partial}{\partial x_j}\overline{\rho}\left(\widetilde{u_i u_j} - \widetilde{u_j}\widetilde{u_i}\right).
\end{align}

As the same matter, the thermal equation becomes:
\begin{equation}
  \frac{\partial \overline{\rho}\widetilde{\theta}}{\partial t}
  + \frac{\partial \widetilde{u_i}\overline{\rho}\widetilde{\theta}}{\partial x_i}
  = Q -\frac{\partial}{\partial x_i}\overline{\rho}\left(\widetilde{u_i\theta}-\widetilde{u_i}\widetilde{\theta}\right).
\end{equation}

The govering equations for the prognostic variables
($\overline{\rho}, \overline{\rho}\widetilde{u_i}, $ and $\overline{\rho}\widetilde{\theta}$) are:
\begin{align}
  \frac{\partial \overline{\rho}}{\partial t}
  + \frac{\partial \widetilde{u_i}\overline{\rho}}{\partial x_i} &= 0, \\
  \frac{\partial \overline{\rho}\widetilde{u_i}}{\partial t}
  + \frac{\partial \widetilde{u_j}\overline{\rho}\widetilde{u_i}}{\partial x_j}
  &= -\frac{\partial \overline{p}}{\partial x_i} + g\overline{\rho}\delta_{i3}
  -\frac{\partial \overline{\rho}\tau_{ij}}{\partial x_j}, \\
  \frac{\partial \overline{\rho}\widetilde{\theta}}{\partial t}
  + \frac{\partial \widetilde{u_i}\overline{\rho}\widetilde{\theta}}{\partial x_i}
  &= Q -\frac{\partial \overline{\rho}\tau^D_{i}}{\partial x_i},
\end{align}
where:
\begin{align}
  \tau_{ij} &= \widetilde{u_iu_j}-\widetilde{u_i}\widetilde{u_j}, \\
  \tau^D_{i} &= \widetilde{u_i\theta}-\widetilde{u_i}\widetilde{\theta}.
\end{align}

Hereafter, we omit the overline and tilde representing the spatial and Favre filters.

\subsection{SGS model}
\subsubsection{Smagorinsky-Lilly model}
The eddy momentum flux is:
\begin{equation}
  \tau_{ij} - \frac{1}{3}\tau_{kk}\delta_{ij} = -2\nu_{SGS}\left(S_{ij}-\frac{1}{3}S_{kk}\delta_{ij}\right),
\end{equation}
where $S_{ij}$ is the strain tensor:
\begin{equation}
  S_{ij} = \frac{1}{2}\left(\frac{\partial u_i}{\partial x_j} + \frac{\partial u_j}{\partial x_i}\right),
  \label{eq:strain tensor}
\end{equation}
and:
\begin{equation}
  \nu_{SGS} = \left(C_s\lambda\right)^2 \left|S\right|.
\end{equation}
$C_s$ is the Smagorinsky constant,
$\lambda$ is a characteristic SGS length scale,
and $\left|S\right|$ is scale of the tensor $S$,
\begin{equation}
  \left|S\right| = \sqrt{2S_{ij}S_{ij}}.
  \label{eq:|S|}
\end{equation}

The eddy momentum flux is then:
\begin{equation}
  \tau_{ij} = -2\nu_{SGS}\left(S_{ij}-\frac{1}{3}S_{kk}\delta_{ij}\right)
             + \frac{2}{3} TKE\delta_{ij},
  \label{eq:tau}
\end{equation}
where:
\begin{equation}
  TKE = \frac{1}{2}\tau_{ii}
   = \left(\frac{\nu_{SGS}}{C_k\lambda}\right)^2,
   \label{eq:tke}
\end{equation}
where $C_k$ is a SGS constant and assumed to be 0.1, following \citet{Deardorff_1980} and \citet{Moeng_Wynggard_1988}.

The eddy heat flux is:
\begin{equation}
  \tau^D_i = -D_{SGS} \frac{\partial \theta}{\partial x_i},
  \label{eq:tau*}
\end{equation}
where:
\begin{equation}
  D_{SGS} = \frac{1}{Pr}\nu_{SGS}.
\end{equation}
$Pr$ is the turbulent Prandtl number.
For other scalar constants such as water vapor,
$D_{SGS}$ is also used as their diffusivity.

To include buoyancy effects, the extension of the basic Smagorinsky constant developed by \citet{Brown_etal_1994}
is used.
\begin{equation}
  \nu_{SGS} = (C_s\lambda)^2 |S| \sqrt{1-Rf},
\end{equation}
where $Rf$ is the flux Richardson number ($Rf = Ri/Pr$).
$Ri$ is the local (pointwise) gradient Richardson number,
\begin{equation}
  Ri = \frac{N^2}{|S|^2},
  \label{eq:Ri}
\end{equation}
and $N^2$ is the Brunt-Visala frequency,
\begin{equation}
  N^2 = \frac{g}{\theta}\frac{\partial\theta}{\partial z}.
  \label{eq:N^2}
\end{equation}
The Prandtl number is an unknown parameter that depends on the Richardson number,
though it is often assumed to have a constant value.
For  unstable conditions ($Ri < 0$),
\begin{align}
  \nu_{SGS} &= \left(C_s\lambda\right)^2 |S| \sqrt{1 - c Ri}, \label{eq:nu unstable} \\
  D_{SGS} &= \frac{1}{Pr_N} \left(C_s\lambda\right)^2 |S| \sqrt{1 - b Ri} \label{eq:nu^* unstable},
\end{align}
where $Pr_N$ is the Prandtl number for neutral condtions.
The values of $c, b, Pr_N$ are set to 16, 40, and 0.7, respectively.
The Prandtl number is then:
\begin{equation}
  Pr = Pr_N \sqrt{\frac{1-c Ri}{1-b Ri}}.
\end{equation}
For stable conditions, when the Richardson number is smaller than the critical Richardson number, $Ri_c (=0.25)$,
\begin{align}
  \nu_{SGS} &= \left(C_s\lambda\right)^2 |S| \left(1-\frac{Ri}{Ri_c}\right)^4, \label{eq:nu stable} \\
  D_{SGS} &= \frac{1}{Pr_N}\left(C_s\lambda\right)^2 |S| \left(1-\frac{Ri}{Ri_c}\right)^4\left(1-g Ri\right). \label{eq:nu^* stable}
\end{align}
The constant $g$ is determined as the Prandtl number becomes 1
in the limit of $Ri \to Ri_C$ and is then $(1-Pr_N)/Ri_c$.
The Prandtl number is
\begin{equation}
  Pr = Pr_N \left\{1-(1-Pr_N)\frac{Ri}{Ri_c}\right\}^{-1}.
\end{equation}
For  strongly stable conditions ($Ri > Ri_c$), eddy viscosity and diffusivity for scalars are 0;
\begin{align}
  \nu_{SGS} &= 0, \label{eq:nu strong stable} \\
  D_{SGS} &= 0. \label{eq:nu^* strong stable}
\end{align}
The Prandtl number is $Pr = 1$.

\citet{Scotti_1993} suggested that the length scale should depend on the grid aspect ratio.
Under equilibrium conditions with the universal Kolmogorov spectrum, energy cascaded to the SGS turbulence, which is equal to SGS dissipation, must not depend on the grid aspect ratio.
The energy flux or dissipation can be written as function of $S_{ij}$ and the length scale, $\lambda$.
The $S_{ij}$ depends on the grid aspect ratio, so the length scale should have dependency on the aspect ratio, cancelling the dependency of $S_{ij}$.
With some approximations, the authors obtained an approximate function of the length scale
\footnote{They considered two grid aspect ratios, while we consider only one, i.e. $\Delta x = \Delta y$.}
:
\begin{equation}
\lambda = f(a) \Delta,
\end{equation}
%\begin{equation}
%  \frac{1}{\lambda^2} = \frac{1}{\lambda_0^2} + \frac{1}{(kz)^2},
%\end{equation}
%where $k$ is the Karman constant ($k=0.4$), and $\lambda_0 = f(a) \Delta$.
where $f(a)$ is a function of grid aspect ratio, $a$, and
\begin{align}
  f(a) &= 1.736 a^{1/3} \{ \nonumber\\
  & 4P_1(b_1)a^{1/3} + 0.222P_2(b_1)a^{-5/3} + 0.077P_3(b_1)a^{-11/3} \nonumber\\
  & - 3b_1 + 4P_1(b_2) + 0.222P_2(b_2) + 0.077P_3(b_2)- 3b_2 \nonumber\\
  & \}^{-3/4}. \label{eq: f}
\end{align}
Here $b_1 = \arctan(1/a), b_2 = \arctan(a) = \pi/2 - b_1$, and
\begin{align}
  P_1(z) &= 2.5P_2(z) - 1.5 (\cos(z))^{2/3} \sin(z), \\
  P_2(z) &= 0.98z + 0.073z^2 -0.418z^3 + 0.120z^4, \\
  P_3(z) &= 0.976z + 0.188z^2 + 1.169z^3 + 0.755z^4 - 0.151z^5.
\end{align}
For instance, $f(2) = 1.036, f(5) = 1.231, f(10) = 1.469$, and $f(20) = 1.790$.
%For instance, $f(2) = 1.036, f(5) = 1.231, f(10) = 1.469, f(20) = 1.790$, and $f(50) = 2.368$.
$\Delta$ is the filter length, and is here defined to be proportional to $(\Delta x \Delta y \Delta z)^{1/3}$.
In this model, we introduce a numerical filter to reduce two-grid noise discussed above.
This filter also reduces two-grid scale physical variability. This means that two-grid scale would be preferred for the filter length in this model rather than grid spacing itself; that is:
\begin{equation}
  \Delta = 2 (\Delta x \Delta y \Delta z)^{1/3}. \label{eq: delta}
\end{equation}

\subsubsection{Terrain-following coordinates}
Tendencies representing effect of sub-grid scale turbulence with terrain-following coordinates are as follows:
\footnote{Equationsthat are not changed in the terrain-following coordinates are ommited.};
\begin{align}
  \frac{\partial G^{\frac{1}{2}}\rho u}{\partial t}
  &=
  - \frac{\partial G^{\frac{1}{2}}\rho\tau_{11}}{\partial x^*}
  - \frac{\partial G^{\frac{1}{2}}\rho\tau_{12}}{\partial y^*}
  - \frac{\partial J_{13}G^{\frac{1}{2}}\rho\tau_{11} + J_{23}G^{\frac{1}{2}}\rho\tau_{12} + J_{33}G^{\frac{1}{2}}\rho\tau_{13}}{\partial \xi}, \\
  \frac{\partial G^{\frac{1}{2}}\rho v}{\partial t}
  &=
  - \frac{\partial G^{\frac{1}{2}}\rho\tau_{21}}{\partial x^*}
  - \frac{\partial G^{\frac{1}{2}}\rho\tau_{22}}{\partial y^*}
  - \frac{\partial J_{13}G^{\frac{1}{2}}\rho\tau_{21} + J_{23}G^{\frac{1}{2}}\rho\tau_{22} + J_{33}G^{\frac{1}{2}}\rho\tau_{23}}{\partial \xi}, \\
  \frac{\partial G^{\frac{1}{2}}\rho w}{\partial t}
  &=
  - \frac{\partial G^{\frac{1}{2}}\rho\tau_{31}}{\partial x^*}
  - \frac{\partial G^{\frac{1}{2}}\rho\tau_{32}}{\partial y^*}
  - \frac{\partial J_{13}G^{\frac{1}{2}}\rho\tau_{31} + J_{23}G^{\frac{1}{2}}\rho\tau_{32} + J_{33}G^{\frac{1}{2}}\rho\tau_{33}}{\partial \xi}, \\
  \frac{\partial G^{\frac{1}{2}} \rho \theta}{\partial t}
  &=
  - \frac{\partial G^{\frac{1}{2}}\rho\tau^D_1}{\partial x^*}
  - \frac{\partial G^{\frac{1}{2}}\rho\tau^D_2}{\partial y^*}
  - \frac{\partial J_{13}G^{\frac{1}{2}}\rho\tau^D_1 + J_{23}G^{\frac{1}{2}}\rho\tau^D_2 + J_{33}G^{\frac{1}{2}}\rho\tau^D_3}{\partial \xi}
\end{align}
\begin{align}
  G^{\frac{1}{2}}S_{11} &= \frac{\partial G^{\frac{1}{2}}u}{\partial x^*} + \frac{\partial J_{13}G^{\frac{1}{2}}u}{\partial \xi}, \\
  G^{\frac{1}{2}}S_{22} &= \frac{\partial G^{\frac{1}{2}}v}{\partial y^*} + \frac{\partial J_{23}G^{\frac{1}{2}}v}{\partial \xi}, \\
  G^{\frac{1}{2}}S_{33} &= \frac{\partial J_{33}G^{\frac{1}{2}}w}{\partial \xi}, \\
  G^{\frac{1}{2}}S_{12} &= \frac{1}{2}\left(\frac{\partial G^{\frac{1}{2}}u}{\partial y^*} + \frac{\partial G^{\frac{1}{2}}v}{\partial x^*} + \frac{\partial J_{23}G^{\frac{1}{2}}u + J_{13}G^{\frac{1}{2}}v}{\partial \xi}\right), \\
  G^{\frac{1}{2}}S_{23} &= \frac{1}{2}\left(\frac{\partial G^{\frac{1}{2}}w}{\partial y^*} + \frac{\partial J_{33}G^{\frac{1}{2}}v + J_{23}G^{\frac{1}{2}}w}{\partial \xi}\right), \\
  G^{\frac{1}{2}}S_{31} &= \frac{1}{2}\left(\frac{\partial G^{\frac{1}{2}}w}{\partial x^*} + \frac{\partial J_{13}G^{\frac{1}{2}}w + J_{33}G^{\frac{1}{2}}u}{\partial \xi}\right), \\
  G^{\frac{1}{2}}\tau^D_1 &= -D_{SGS}\left(
   \frac{\partial G^{\frac{1}{2}}\theta}{\partial x^*}
  +\frac{\partial J_{13}G^{\frac{1}{2}}\theta}{\partial \xi} \right), \\
  G^{\frac{1}{2}}\tau^D_2 &= -D_{SGS}\left(
   \frac{\partial G^{\frac{1}{2}}\theta}{\partial y^*}
  +\frac{\partial J_{23}G^{\frac{1}{2}}\theta}{\partial \xi} \right), \\
  G^{\frac{1}{2}}\tau^D_3 &= -D_{SGS}
  \frac{\partial J_{33}G^{\frac{1}{2}}\theta}{\partial \xi}, \\
  G^{\frac{1}{2}} N^2 &= \frac{g}{\theta}\frac{\partial J_{33}G^{\frac{1}{2}}\theta}{\partial \xi}.
\end{align}

\subsection{Discretization}

\subsubsection{Spatial discretization}
We use the 4th order difference scheme for the advection term, as mentioned
in the chapter \ref{chap:discretization dynamics}.
The $\tau_{ij}$ and $\tau^D_{i}$ are proportional to
the square of the grid spacing ($\Delta^2$).
Due to consistency with the advection term
in terms of order for spatial difference,
the second order central difference scheme
is used for terms of sub-grid scale turbulence.
In the following part of this sub-section,
overline, and $i,j,k$ have the same meaning
as in the chapter \ref{chap:discretization dynamics}.

\paragraph{Momentum equation}
The tendencies in the momentum equation related to the sub-grid scale mode are:
\begin{align}
  \frac{\partial G^{\frac{1}{2}}\rho u}{\partial t}_{i+\half,j,k} =
  &-\frac{(G^{\frac{1}{2}}\rho\tau_{11})_{i+1,j,k}-(G^{\frac{1}{2}}\rho\tau_{11})_{i,j,k}}{\Delta x} \nonumber \\
  &- \frac{(G^{\frac{1}{2}}\overline{\rho}\tau_{12})_{i+\half,j+\half,k}-(G^{\frac{1}{2}}\overline{\rho}\tau_{12})_{i+\half,j-\half,k}}{\Delta y} \nonumber \\
  &- \frac{\{G^{\frac{1}{2}}\overline{\rho}(J_{13}\tau_{11}+J_{23}\tau_{12}+J_{33}\tau_{13})\}_{i+\half,j,k+\half}
          -\{G^{\frac{1}{2}}\overline{\rho}(J_{13}\tau_{11}+J_{23}\tau_{12}+J_{33}\tau_{13})\}_{i+\half,j,k-\half}}{\Delta z}, \\
  \frac{\partial G^{\frac{1}{2}}\rho v}{\partial t}_{i,j+\half,k} =
  &- \frac{(G^{\frac{1}{2}}\overline{\rho}\tau_{21})_{i+\half,j+\half,k}-(G^{\frac{1}{2}}\overline{\rho}\tau_{21})_{i-\half,j+\half,k}}{\Delta x} \nonumber \\
  &- \frac{(G^{\frac{1}{2}}\rho\tau_{22})_{i,j+1,k}-(G^{\frac{1}{2}}\rho\tau_{22})_{i,j,k}}{\Delta y} \nonumber \\
  &- \frac{\{G^{\frac{1}{2}}\overline{\rho}(J_{13}\tau_{21}+J_{23}\tau_{22}+J_{33}\tau_{23})\}_{i,j+\half,k+\half}
          -\{G^{\frac{1}{2}}\overline{\rho}(J_{13}\tau_{21}+J_{23}\tau_{22}+J_{33}\tau_{23})\}_{i,j+\half,k-\half}}{\Delta z}, \\
  \frac{\partial G^{\frac{1}{2}}\rho w}{\partial t}_{i,j,k+\half} =
  &- \frac{(G^{\frac{1}{2}}\overline{\rho}\tau_{31})_{i+\half,j,k+\half}-(G^{\frac{1}{2}}\overline{\rho}\tau_{31})_{i-\half,j,k+\half}}{\Delta x} \nonumber \\
  &- \frac{(G^{\frac{1}{2}}\overline{\rho}\tau_{32})_{i,j+\half,k+\half}-(G^{\frac{1}{2}}\overline{\rho}\tau_{32})_{i,j-\half,k+\half}}{\Delta y} \nonumber \\
  &- \frac{\{(G^{\frac{1}{2}}\rho(J_{13}\tau_{31}+J_{23}\tau_{32}+J_{33}\tau_{33})\}_{i,j,k+1}
          -\{(G^{\frac{1}{2}}\rho(J_{13}\tau_{31}+J_{23}\tau_{32}+J_{33}\tau_{33})\}_{i,j,k}}{\Delta z}.
\end{align}
The $\overline{\rho}$ is:
\begin{align}
  \overline{\rho}_{i,j+\half,k+\half} &=
  \frac{\rho_{i,j+1,k+1} + \rho_{i,j+1,k} + \rho_{i,j,k+1} + \rho_{i,j,k}}{4}, \\
  \overline{\rho}_{i+\half,j,k+\half} &=
  \frac{\rho_{i+1,j,k+1} + \rho_{i+1,j,k} + \rho_{i,j,k+1} + \rho_{i,j,k}}{4}, \\
  \overline{\rho}_{i+\half,j+\half,k} &=
  \frac{\rho_{i+1,j+1,k} + \rho_{i+1,j,k} + \rho_{i,j+1,k} + \rho_{i,j,k}}{4}.
\end{align}

\paragraph{Thermal equation}
The tendency in the thermal equation related to the sub-grid scale model is:
\begin{align}
  \frac{\partial G^{\frac{1}{2}}\rho \theta}{\partial t}_{i,j,k} =
  &- \frac{(G^{\frac{1}{2}}\overline{\rho}\tau^D_1)_{i+\half,j,k}-(G^{\frac{1}{2}}\overline{\rho}\tau^D_1)_{i-\half,j,k}}{\Delta x} \nonumber \\
  &- \frac{(G^{\frac{1}{2}}\overline{\rho}\tau^D_2)_{i,j+\half,k}-(G^{\frac{1}{2}}\overline{\rho}\tau^D_2)_{i,j-\half,k}}{\Delta y} \nonumber \\
  &- \frac{\{G^{\frac{1}{2}}\overline{\rho}(J_{13}\tau^D_1+J_{23}\tau^D_2+J_{33}\tau^D_3)\}_{i,j,k+\half}
          -\{G^{\frac{1}{2}}\overline{\rho}(J_{13}\tau^D_1+J_{23}\tau^D_2+J_{33}\tau^D_3)\}_{i,j,k-\half}}{\Delta z}.
\end{align}
The $\overline{\rho}$ at half-level is eq.(\ref{eq:rho half i})-(\ref{eq:rho half k}).

The eddy diffusion flux, $\tau^D$, at half-level is:
\begin{align}
  (G^{\frac{1}{2}}\tau^D_1)_{i+\half,j,k} &= -D_{SGS,i+\half,j,k} \left\{
  \frac{(G^{\frac{1}{2}}\theta)_{i+1,j,k}-(G^{\frac{1}{2}}\theta)_{i,j,k}}{\Delta x}
  + \frac{(J_{13}G^{\frac{1}{2}}\overline{\theta})_{i+\half,j,k+\half}-(J_{13}G^{\frac{1}{2}}\overline{\theta})_{i+\half,j,k-\half}}{\Delta z} \right\}, \\
  (G^{\frac{1}{2}}\tau^D_2)_{i,j+\half,k} &= -D_{SGS,i,j+\half,k} \left\{
  \frac{(G^{\frac{1}{2}}\theta)_{i,j+1,k}-(G^{\frac{1}{2}}\theta)_{i,j,k}}{\Delta y}
  + \frac{(J_{23}G^{\frac{1}{2}}\overline{\theta})_{i,j+\half,k+\half}-(J_{23}G^{\frac{1}{2}}\overline{\theta})_{i,j+\half,k-\half}}{\Delta z} \right\}, \\
  (G^{\frac{1}{2}}\tau^D_3)_{i,j,k+\half} &= -D_{SGS,i,j,k+\half} \frac{J_{33}G^{\frac{1}{2}}\theta_{i,j,k+1}-J_{33}G^{\frac{1}{2}}\theta_{i,j,k}}{\Delta z}.
\end{align}

\paragraph{Strain tensor}
All the strain tensors, eq.(\ref{eq:strain tensor}), have to be calculated at full-level (grid cell center), and some are at cell edges.

\begin{itemize}
  \item cell center ($i,j,k$)
    \begin{align}
      (G^{\frac{1}{2}}S_{11})_{i,j,k} &=
      \frac{(G^{\frac{1}{2}}\overline{u})_{i+\half,j,k}-(G^{\frac{1}{2}}\overline{u})_{i-\half,j,k}}{\Delta x}
     +\frac{(J_{13}G^{\frac{1}{2}}\overline{u})_{i+\half,j,k+\half}-(J_{13}G^{\frac{1}{2}}\overline{u})_{i+\half,j,k-\half}}{\Delta z}, \\
     (G^{\frac{1}{2}}S_{22})_{i,j,k} &=
      \frac{(G^{\frac{1}{2}}\overline{v})_{i,j+\half,k}-(G^{\frac{1}{2}}\overline{v})_{i,j-\half,k}}{\Delta y}
     +\frac{(J_{23}G^{\frac{1}{2}}\overline{v})_{i,j+\half,k+\half}-(J_{23}G^{\frac{1}{2}}\overline{v})_{i,j+\half,k-\half}}{\Delta z}, \\
     (G^{\frac{1}{2}}S_{33})_{i,j,k} &=
      \frac{J_{33}G^{\frac{1}{2}}\overline{w}_{i,j,k+\frac{1}{2}}-J_{33}G^{\frac{1}{2}}\overline{w}_{i,j,k-\frac{1}{2}}}{\Delta z}, \\
      (G^{\frac{1}{2}}S_{12})_{i,j,k} &= \frac{1}{2}\left\{
      \frac{(G^{\frac{1}{2}}\overline{u})_{i,j+\frac{1}{2},k}-(G^{\frac{1}{2}}\overline{u})_{i,j-\frac{1}{2},k}}{\Delta y}
     +\frac{(G^{\frac{1}{2}}\overline{v})_{i+\frac{1}{2},j,k}-(G^{\frac{1}{2}}\overline{v})_{i-\frac{1}{2},j,k}}{\Delta x}  \right.\nonumber \\ &\left.
     +\frac{(J_{23}G^{\frac{1}{2}}\overline{u})_{i,j,k+\half}-(J_{23}G^{\frac{1}{2}}\overline{u})_{i,j,k-\half} + (J_{13}G^{\frac{1}{2}}\overline{v})_{i,j,k+\half}-(J_{13}G^{\frac{1}{2}}\overline{v})_{i,j,k-\half}}{\Delta z}
      \right\}, \\
      (G^{\frac{1}{2}}S_{23})_{i,j,k} &= \frac{1}{2}\left\{
      \frac{(G^{\frac{1}{2}}\overline{w})_{i,j+\frac{1}{2},k}-(G^{\frac{1}{2}}\overline{w})_{i,j-\frac{1}{2},k}}{\Delta y} \right. \nonumber \\ & \left.
      + \frac{J_{33}G^{\frac{1}{2}}\overline{v}_{i,j,k+\frac{1}{2}}-J_{33}G^{\frac{1}{2}}\overline{v}_{i,j,k-\frac{1}{2}} + (J_{23}G^{\frac{1}{2}}\overline{w})_{i,j,k+\half}-(J_{23}G^{\frac{1}{2}}\overline{w})_{i,j,k-\half}}{\Delta z}
      \right\}, \\
      (G^{\frac{1}{2}}S_{31})_{i,j,k} &= \frac{1}{2}\left\{
      \frac{(G^{\frac{1}{2}}\overline{w})_{i+\frac{1}{2},j,k}-(G^{\frac{1}{2}}\overline{w})_{i-\frac{1}{2},j,k}}{\Delta x} \right. \nonumber \\ & \left.
     +\frac{J_{33}G^{\frac{1}{2}}\overline{u}_{i,j,k+\frac{1}{2}}-J_{33}G^{\frac{1}{2}}\overline{u}_{i,j,k-\frac{1}{2}} + (J_{13}G^{\frac{1}{2}}\overline{w})_{i,j,k+\half}-(J_{13}G^{\frac{1}{2}}\overline{w})_{i,j,k-\half}}{\Delta z}
      \right\}.
    \end{align}

  \item $z$ edge ($i+\half,j+\half,k$)
    \begin{align}
      (G^{\frac{1}{2}}S_{12})_{i+\half,j+\half,k} &= \frac{1}{2}\left\{
      \frac{(G^{\frac{1}{2}}\overline{u})_{i+\half,j+1,k}-(G^{\frac{1}{2}}\overline{u})_{i+\half,j,k}}{\Delta y}
     +\frac{(G^{\frac{1}{2}}\overline{v})_{i+1,j+\half,k}-(G^{\frac{1}{2}}\overline{v})_{i,j+\half,k}}{\Delta x}  \right.\nonumber \\ &\left.
     +\frac{(J_{23}G^{\frac{1}{2}}\overline{u})_{i+\half,j+\half,k+\half}-(J_{23}G^{\frac{1}{2}}\overline{u})_{i+\half,j+\half,k-\half} + (J_{13}G^{\frac{1}{2}}\overline{v})_{i+\half,j+\half,k+\half}-(J_{13}G^{\frac{1}{2}}\overline{v})_{i+\half,j+\half,k-\half}}{\Delta z}.
      \right\}
    \end{align}

  \item $x$ edge ($i,j+\half,k+\half$)
    \begin{align}
      (G^{\frac{1}{2}}S_{23})_{i,j+\half,k+\half} &= \frac{1}{2}\left\{
      \frac{(G^{\frac{1}{2}}\overline{w})_{i,j+1,k+\half}-(G^{\frac{1}{2}}\overline{w})_{i,j,k+\half}}{\Delta y} \right. \nonumber \\ & \left.
      + \frac{J_{33}G^{\frac{1}{2}}\overline{v}_{i,j+\half,k+1}-J_{33}G^{\frac{1}{2}}\overline{v}_{i,j+\half,k} + (J_{23}G^{\frac{1}{2}}\overline{w})_{i,j+\half,k+1}-(J_{23}G^{\frac{1}{2}}\overline{w})_{i,j+\half,k}}{\Delta z}.
      \right\}
    \end{align}

  \item $y$ edge ($i+\half,j,k+\half$)
    \begin{align}
      (G^{\frac{1}{2}}S_{31})_{i+\half,j,k+\half} &= \frac{1}{2}\left\{
      \frac{(G^{\frac{1}{2}}\overline{w})_{i+1,j,k+\half}-(G^{\frac{1}{2}}\overline{w})_{i,j,k+\half}}{\Delta x} \right. \nonumber \\ & \left.
     +\frac{J_{33}G^{\frac{1}{2}}\overline{u}_{i+\half,j,k+1}-J_{33}G^{\frac{1}{2}}\overline{u}_{i+\half,j,k} + (J_{13}G^{\frac{1}{2}}\overline{w})_{i+\half,j,k+1}-(J_{13}G^{\frac{1}{2}}\overline{w})_{i+\half,j,k}}{\Delta z}.
      \right\}.
    \end{align}

\end{itemize}

\paragraph{velocity}
Calculation of the strain tensor requires velocity value at cell center, plane center, edge center, and vertex. The velocities at cell center (full-level) are eq.(\ref{eq:u full}-\ref{eq:w full}):

\begin{itemize}
  \item $x$-$y$ plane center ($i,j,k+\frac{1}{2}$)
    \begin{align}
      \overline{u}_{i,j,k+\frac{1}{2}} &=
      \frac{\overline{u}_{i,j,k+1}+\overline{u}_{i,j,k}}{2}, \\
      \overline{v}_{i,j,k+\frac{1}{2}} &=
      \frac{\overline{v}_{i,j,k+1}+\overline{v}_{i,j,k}}{2}, \\
      \overline{w}_{i,j,k+\frac{1}{2}} &=
      \frac{(\rho w)_{i,j,k+\frac{1}{2}}}{\overline{\rho}_{i,j,k+\frac{1}{2}}}.
    \end{align}

  \item $y$-$z$ plane center ($i+\frac{1}{2},j,k$)
    \begin{align}
      \overline{u}_{i+\frac{1}{2},j,k} &=
      \frac{(\rho u)_{i+\frac{1}{2},j,k}}{\overline{\rho}_{i+\frac{1}{2},j,k}}, \\
      \overline{v}_{i+\frac{1}{2},j,k} &=
      \frac{\overline{v}_{i+1,j,k}+\overline{v}_{i,j,k}}{2}, \\
      \overline{w}_{i+\frac{1}{2},j,k} &=
      \frac{\overline{w}_{i+1,j,k}+\overline{w}_{i,j,k}}{2}.
    \end{align}

  \item $z$-$x$ plane center ($i,j+\frac{1}{2},k$)
    \begin{align}
      \overline{u}_{i,j+\frac{1}{2},k} &=
      \frac{\overline{u}_{i,j+1,k}+\overline{u}_{i,j,k}}{2}, \\
      \overline{v}_{i,j+\frac{1}{2},k} &=
      \frac{(\rho v)_{i,j+\frac{1}{2},k}}{\overline{\rho}_{i,j+\frac{1}{2},k}}, \\
      \overline{w}_{i,j+\frac{1}{2},k} &=
      \frac{\overline{w}_{i,j+1,k}+\overline{w}_{i,j,k}}{2}.
    \end{align}

  \item $x$ edge center ($i,j+\frac{1}{2},k+\half$)
    \begin{align}
      \overline{u}_{i,j+\half,k+\half} &=
      \frac{\overline{u}_{i,j+1,k+1}+\overline{u}_{i,j+1,k}+\overline{u}_{i,j,k+1}+\overline{u}_{i,j,k}}{4}, \\
      \overline{v}_{i,j+\half,k+\half} &=
      \frac{\overline{v}_{i,j+\half,k+1}+\overline{v}_{i,j+\half,k}}{2}, \\
      \overline{w}_{i,j+\half,k+\half} &=
      \frac{\overline{w}_{i,j+1,k+\half}+\overline{w}_{i,j,k+\half}}{2}.
    \end{align}

  \item $y$ edge center ($i+\half,j,k+\half$)
    \begin{align}
      \overline{u}_{i+\half,j,k+\half} &=
      \frac{\overline{u}_{i+\half,j,k+1}+\overline{u}_{i+\half,j,k}}{2}, \\
      \overline{v}_{i+\half,j,k+\half} &=
      \frac{\overline{v}_{i+1,j,k+1}+\overline{v}_{i+1,j,k}+\overline{v}_{i,j,k+1}+\overline{v}_{i,j,k}}{4}, \\
      \overline{w}_{i+\half,j,k+\half} &=
      \frac{\overline{w}_{i+1,j,k+\half}+\overline{w}_{i,j,k+\half}}{2}.
    \end{align}

  \item $z$ edge center ($i+\half,j+\half,k$)
    \begin{align}
      \overline{u}_{i+\half,j+\half,k} &=
      \frac{\overline{u}_{i+\half,j+1,k}+\overline{u}_{i+\half,j,k}}{2}, \\
      \overline{v}_{i+\half,j+\half,k} &=
      \frac{\overline{v}_{i+1,j+\half,k}+\overline{v}_{i,j+\half,k}}{2}, \\
      \overline{w}_{i+\half,j+\half,k} &=
      \frac{\overline{w}_{i+1,j+1,k}+\overline{w}_{i+1,j,k}+\overline{w}_{i,j+1,k}+\overline{w}_{i,j,k}}{4}.
    \end{align}

  \item vertex ($i+\half,j+\half,k+\half$)
    \begin{align}
      \overline{u}_{i+\half,j+\half,k+\half} &=
      \frac{\overline{u}_{i+\half,j+1,k+1}+\overline{u}_{i+\half,j+1,k}+\overline{u}_{i+\half,j,k+1}+\overline{u}_{i+\half,j,k}}{4}, \\
      \overline{v}_{i+\half,j+\half,k+\half} &=
      \frac{\overline{v}_{i+1,j+\half,k+1}+\overline{v}_{i+1,j+\half,k}+\overline{v}_{i,j+\half,k+1}+\overline{v}_{i,j+\half,k}}{4}, \\
      \overline{w}_{i+\half,j+\half,k+\half} &=
      \frac{\overline{w}_{i+1,j+1,k+\half}+\overline{w}_{i+1,j,k+\half}+\overline{w}_{i,j+1,k+\half}+\overline{w}_{i,j,k+\half}}{4}.
    \end{align}
\end{itemize}

\paragraph{Eddy viscosity/diffusion coefficient}
The eddy viscosity/diffusion coefficient, $\nu_{SGS}$ / $D_{SGS}$, is calculated at full-level with $S$ and $Ri$ at full-level; at half-level, it is interpolated to full-level.

\paragraph{Brunt-Visala frequency}
The Brunt-Visala frequency, $N^2$ is required to calculate the Richardson number
at full-level.

\begin{equation}
  (G^{\half}N^2)_{i,j,k} = \frac{g}{\theta_{i,j,k}}
  \frac{J_{33}G^{\half}\theta_{i,j,k+1}-J_{33}G^{\half}\theta_{i,j,k-1}}{2\Delta z}.
\end{equation}

%\end{document}


\documentclass[english,notitlepage,longbibliography,showpacs,preprintnumbers,amsmath,amssymb,aps,prx,nofootinbib,12pt,superscriptaddress]{revtex4-1}
\usepackage{geometry}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{commath}
\usepackage{comment}
\usepackage{hyperref}

\hypersetup{
 unicode=false,                 % non-Latin characters in Acrobat’s bookmarks
 pdftoolbar=true,               % show Acrobat’s toolbar?
 pdfmenubar=true,               % show Acrobat’s menu?
 pdffitwindow=false,            % window fit to page when opened
 pdfstartview={FitH},           % fits the width of the page to the window
 pdftitle={PTR derivations},    % title
 pdfauthor={Matthew Charbonneau},        % author
 pdfsubject={},       % subject of the document
 pdfcreator={pdflatex},         % creator of the document
 pdfproducer={vim},             % producer of the document
 pdfkeywords={PTR} {BCR}, % list of keywords
 pdfnewwindow=true,             % links in new window
 colorlinks=true,               % false: boxed links; true: colored links
 linktoc=page,                  % defines which part of an entry in the table of contents is made into a link
%%%%%%%%% colored links
 linkcolor=blue,                % color of internal links       (red)
 citecolor=blue,                % color of links to bibliography
 filecolor=magenta,             % color of file links
 urlcolor=blue                  % color of external links
}
%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage[inline]{showlabels}
\renewcommand{\showlabelfont}{\footnotesize\ttfamily\color{OliveGreen}}

%%%%%%%%%%%%%%%%%%%%%%%%

\newcommand{\ceil}[1]{\lceil #1 \rceil}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document}

\section{\large PTR Derivations}

Binary variables: $x_1,x_2,\dots,x_n\in\{0,1\}$,
and let $X = |x|:=\sum_{i=1}^n x_i$

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{PTR-BG}
\noindent We begin with the equation for the quadratization of negative monomials:
(Equations 5 and 6, \cite{Boros2014})

\begin{equation}
  f(x) = \min_{w\in B}w\left((d-1) - \sum_{j=1}^dx_j\right)
\end{equation}

\noindent However, by introducting negated literals $\overline{x_i} = 1-x_i$ the quadratization can be extended for polynomials.

\begin{equation}
  f(x) = \min_{w\in B^{d-2}}\sum_{i=1}^{d-2}w_i\left(d-i-\overline{x_i} - \sum_{j=i+1}^dx_j\right)
\end{equation}

\noindent Substituting for the negated literal we get

\begin{equation}
  f(x) = \min_{w\in B^{d-2}}\sum_{i=1}^{d-2}w_i\left(d-i-1+x_i - \sum_{j=i+1}^dx_j\right)
\end{equation}

\noindent Dictionary:\\
$d\mapsto k$,\\
$x_{i,j}\mapsto b_{i,j}$,\\
$w_i\mapsto b_{a_i}$\\

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{PTR-BCR-1}

Let's begin with the equation for the quadratization. (In the formulas, summations for $i,i' = 1,2,\dots,n$ are understood unless stated otherwise.)\\
(Theorem 4.3, \cite{Anthony2014})
\begin{equation}
\begin{split}
  \left.
  g(x,y)
  \right.
  &= -2\left[n - \frac{1}{2} - l\right]^{-} + E''(l)\\
  &= \frac{l(l+1)}{2} + \sum_{\substack{i = 1:\\ i\:odd}}^{n-2}2y_i\left[i-\frac{1}{2}-l\right]^-\\
  &= \sum_i x_i + \sum_{1\leq i<j\leq n}x_ix_j + \min_y\sum_{\substack{i = 1:\\ i\:odd}}^{n-2}2y_i\left(i-\frac{1}{2}-l\right)
  \end{split}
\end{equation}

\noindent Using the relationship $l = \sum_{j=1}^n x_j$ we get
\begin{equation}
  g(x,y) = \sum_i x_i + \sum_{1\leq i<j\leq n}x_ix_j + \min_y\sum_{\substack{i = 1:\\ i\:odd}}^{n-2}2y_i\left(i-\frac{1}{2}-\sum_j x_j\right)
\end{equation}

\noindent Finally, after rearranging we end with the equation
\begin{equation}
  g(x,y) = \sum_i x_i + \sum_{2i - 1}\left(2(2i - 1)-1\right)y_{2i - 1} + \sum_{1\leq i<j\leq n}x_ix_j - \sum_{2i - 1}\sum_jy_{2i - 1} x_j
\end{equation}

\noindent Dictionary:\\
$x_{i,j}\mapsto b_{i,j}$,\\
$y_{2i-1}\mapsto b_{a_{2i-1}}$\\

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{PTR-BCR-2}

To begin, we start with the following equation: (In the formulas, summations for $i,i' = 1,2,\dots,n$ and $j,j' = 0,1,\dots,m$ are understood.)\\
(Theorem 10, \cite{Boros2018boundsPaper})
\begin{equation}
  g(x,y) = \frac{1}{2}\left(\abs{x} - 2\abs{y} - (N - 2)y_1\right)\left(\abs{x} - 2\abs{y} - (N - 2)y_1 - 1\right)
\end{equation}

\noindent \\Substituting for x, y, and N using $\sum_i x_i$, $\sum_j y_j$, and $n - 2m$, respectively, we get
\begin{equation}
  g(x,y) = \frac{1}{2}\left(\sum_i x_i - 2\sum_j y_j - (n - 2m - 2)y_1\right)\left(\sum_i x_i - 2\sum_j y_j - (n - 2m - 2)y_1 - 1\right)
\end{equation}

\noindent \\After expanding and simplifying, the equation becomes
\begin{equation}
\begin{split}
  \left.
  g(x,y)
  \right.
  = -\frac{1}{2}\sum_i x_i + \sum_j y_j + \frac{1}{2}\left(n-2m-2\right)y_1\\
  + \frac{1}{2}\sum_{i,i'}x_i x_{i'} -2\sum_i \sum_j x_i y_j -\left(n-1m-2\right)\sum_i x_i y_{1}\\
  + 2\sum_{j,j'} y_j y_{j'} + 2\left(n-2m-2\right)\sum_{j,j'} y_j y_{1} + \frac{1}{2}\left((n-2m-2)y_1\right)^2
\end{split}
\end{equation}

\noindent Because $y_{1}\in\{0,1\}$, we have $y_{1}^2=y_{1}$, so we can join the two terms,
\begin{equation}
  \frac{1}{2}(n-2m-2)y_1 + \frac{1}{2}((n-2m-2)y_1)^2 = \frac{1}{2}(-3n + 6m + n^2 - 4mn + 4m^2 + 2)y_1
\end{equation}

\noindent \\Thus we are left with
\begin{equation}
\begin{split}
  \left.
  g(x,y)
  \right.
  = \underbrace{-\frac{1}{2}}_{\alpha^b}\sum_i x_i
  + \underbrace{1}_{\alpha^{b_{a,1}}}\sum_j y_j
  + \underbrace{\frac{1}{2}\left(-3n + 6m + n^2 - 4mn + 4m^2 + 2\right)}_{\alpha^{b_{a,2}}}y_1\\
  + \underbrace{\frac{1}{2}}_{\alpha^{bb}}\sum_{i,i'}x_i x_{i'}
  + \underbrace{-2}_{\alpha^{bb_{a,1}}}\sum_i \sum_j x_i y_j
  + \underbrace{-\left(n-2m-2\right)}_{\alpha^{bb_{a,2}}}\sum_i x_i y_{1}\\
  + \underbrace{2}_{\alpha^{b_{a,1}b_{a,1}}}\sum_{j,j'} y_j y_{j'}
  + \underbrace{2\left(n-2m-2\right)}_{\alpha^{b_{a,1}b_{a,1}}}\sum_{j,j'} y_j y_{1}
\end{split}
\end{equation}

\noindent The coefficients are
\begin{subequations}
\begin{align}
\alpha^b &= -\frac{1}{2}\\
\alpha^{b_{a,1}} &= 1\\
\alpha^{b_{a,2}} &= \frac{1}{2}\left(-3n + 6m + n^2 - 4mn + 4m^2 + 2\right)\\
\alpha^{bb} &= \frac{1}{2}\\
\alpha^{bb_{a,1}} &= -2\\
\alpha^{bb_{a,2}} &= -(n-2m-2)\\
\alpha^{b_{a,1}b_{a,1}} &= 2\\
\alpha^{b_{a,1}b_{a,2}} &= 2(n-2m-2)
\end{align}
\end{subequations}

\noindent Dictionary:\\
$y_{1}\mapsto b_{a_m}$,\\
$x_i\mapsto b_i$,\\
$y_j\mapsto b_{a_i}$\\

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{PTR-BCR-3} %From Theorem 4: [22].

We begin with the following equation:
(In the formulas, summations for $i,i' = 1,2,\dots,n$ and $j,j' = 0,1,\dots,k-1$ are understood.)
\\(Theorem 4, \cite{Boros2018boundsPaper})

\begin{equation}
  g(x,y) = \Big(K + X - \sum_{j} 2^j y_j\Big)^2
\end{equation}

\noindent Knowing that $X = \sum_{i=1}^n x_i$ and $K = 2^k - n$, we substitute to get
\begin{equation}
  g(x,y) = \Big(2^k - n + \sum_i x_i - \sum_{j} 2^j y_j\Big)^2
\end{equation}

\noindent Expanding the square and collecting like terms we end with
\begin{equation}
\begin{comment}
  Full expansion w/o rearranging or collecting like terms
  = 2^{2k} - 2^kn + 2^k\sum_{i'} x_{i'} - \sum_{j'} 2^j y_j - 2^kn + n^2 - n\sum_{i'} x_{i'}\\
  + n\sum_{j'} 2^j y_j + 2^k\sum_{i} x_{i} - n\sum_{i} x_{i} + \sum_{i}\sum_{i'}x_ix_{i'}\\
  + \sum_{i}\sum_{j'}2^{j'}x_iy_{j'} - \sum_j 2^{j+k}y_j + n\sum_j 2^j y_j\\
  - \sum_{i'}\sum_j 2^j x_{i'}y_j + \sum_j\sum_{j'}2^{j+j'}y_j y_j'
\end{comment}
\begin{split}
\left.
g(x,y)
\right.
= \underbrace{(2^k-n)^2}_{\alpha}
+ \underbrace{2\left(2^k-n\right)}_{\alpha^b}\sum_i x_i
+ \underbrace{-2\left(2^k-n\right)}_{\alpha^{b_a}}\sum_j 2^j y_j\\
+ \underbrace{1}_{\alpha^{bb}}\sum_{i,i'}x_i x_{i'}
+ \sum_i\sum_j\underbrace{2^{j-1}}_{\alpha^{bb_a}}x_i y_j
+ \sum_{j,j'}\underbrace{2^{j+j'}}_{\alpha^{b_ab_a}}y_j y_{j'}
\end{split}
\end{equation}

\noindent The coefficients are
\begin{subequations}
\begin{align}
\alpha &= (2^k-n)^2\\
\alpha^b &= 2(2^k-n)\\
\alpha^{b_a} &= -2(2^k-n)\\
\alpha^{bb} &= 1\\
\alpha^{bb_a} &= 2^{j-1}\\
\alpha^{b_ab_a} &= 2^{j+j'}
\end{align}
\end{subequations}

\noindent Dictionary:

\noindent $k\mapsto m$,\\
$n\mapsto k,$\\
$x_i\mapsto b_i$,\\
$x_{i'}\mapsto b_j$,\\
$y_j\mapsto b_{a_i}$,\\
$y_{j'}\mapsto b_{a_j}$\\

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{PTR-BCR-4} %From Theorem 9: [23]

We start with the following equation for the quadratization of PTR-BCR-4: (In the formulas, summations for $i,i' = 1,2,\dots,n$ and $j,j' = 0,1,\dots,l-1$ are understood.)
\\(Theorem 9, \cite{Boros2018boundsPaper})

\begin{equation}
g(x,y) = \frac{1}{2}\left(\abs{x} - 2^l - n - \sum_j 2^j y_j\right)\left(\abs{x} - 2^l - n - \sum_j 2^j y_j - 1\right)
\end{equation}

\noindent After substituting for X, we end with
\begin{equation}
g(x,y) = \frac{1}{2}\left(-2^l - n + \sum_i x_i - \sum_j 2^j y_j\right)\left(-2^l - n + \sum_i x_i - \sum_j 2^j y_j - 1\right)
\end{equation}

\noindent Dictionary:
\noindent $l\mapsto m + 1$,\\
$n\mapsto k$,\\
$x_i\mapsto b_i$,\\
$y_j\mapsto b_{a_i}$,\\

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{PTR-BCR-5} %From Remark 5: [23]
With $log(n)$ auxiliary variables we have the equation:
(In the formulas, summations for $i,i' = 1,2,\dots,n$ and $j,j' = 0,1,\dots,l-1$ are understood.)
\\(Remark 5 from Theorem 9, \cite{Boros2018boundsPaper})

\begin{equation}
  g'(x,y) = \left(\abs{x} - \sum_{j}2^jy_j\right)^2
\end{equation}
We can express x using the formula $\abs{x} = \sum_i x_i$

\begin{equation}
  g'(x,y) = \left(\sum_{i}x_i - \sum_{j}2^jy_j\right)^2
\end{equation}

\noindent By expanding and collecting like terms the equation finally becomes
\begin{equation}
\begin{split}
\left.
g'(x,y)
\right.
= \underbrace{1}_{\alpha^{bb}}\sum_{i,i'}x_i x_{i'}
+ \sum_{i,j}\underbrace{2^{j-1}}_{\alpha^{bb_a}} x_i y_j
+ \sum_{j,j'}\underbrace{2^{j+j'}}_{\alpha^{b_ab_a}}y_j y_{j'}
\end{split}
\end{equation}

\noindent The coefficients are
\begin{subequations}
\begin{align}
\alpha^{bb} &= 1\\
\alpha^{bb_a} &= 2^{j-1}\\
\alpha^{b_ab_a} &= 2^{j+j'}
\end{align}
\end{subequations}

\noindent Dictionary:\\
$l\mapsto m+1$,\\
$x_i\mapsto b_i$,\\
$y_j\mapsto b_{a_i}$\\

\bibliography{PTRBibliography}

\end{document}


\documentclass[letterpaper,11pt]{article}

\usepackage{afterpage}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{bm}
\usepackage[hmargin=1.25in,vmargin=1in]{geometry}
\usepackage{booktabs}
\usepackage{graphicx}
\usepackage{hyperref}
\usepackage{lmodern}
\usepackage{microtype}
\usepackage{pdflscape}
\usepackage{subcaption}

\title{Coursework 7: STAT 570}
\author{Philip Pham}
\date{\today}

\begin{document}
\maketitle
\begin{enumerate}
\item Create a binary variable $Z_i$, with $Z_i = 0$ corresponding to
  $Y_i \in \{0,1\}$ and $Z_i = 1$ corresponding to $Y_i \in \{2,3\}$. Let
  $q\left(x_i\right) = \mathbb{P}(Z_i = 1 \mid x_i)$, with
  $\mathbf{x}_i = \begin{pmatrix} 1 & x_{1i} & x_{2i}
  \end{pmatrix}^\intercal$, represent the probability of mental impairment being
  \emph{Moderate} or \emph{Impaired}, given covariates $\mathbf{x}_i$,
  $i = 1,\ldots,n = 40$.  Provide a single plot that shows the association
  between $q\left(x_i\right)$ and $x_{1i}$ and $x_{2i}$, on a response scale
  you feel is appropriate. Comment on the plot.

  \begin{figure}[h]
    \centering
    \includegraphics{p1_descriptive.pdf}
    \caption{Orange denotes $Z_i = 1$ and blue denotes $Z_i = 0$.}
    \label{fig:p1_descriptive}
  \end{figure}

  \begin{description}
  \item[Solution:] See Figure \ref{fig:p1_descriptive}. Conditioned on SES,
    those that are impaired ($Z_i = 1$) have a greater number of life events on
    average.
  \end{description}
\item Suppose $Z_i \mid q_i \sim \operatorname{Binomial}\left(1, q_i\right)$
  independently for $i = 1,\ldots, n = 40$, where $q_i =
  q\left(x_i\right)$. Consider the logistic regression model,
  \begin{equation}
    q\left(x_i\right) = \log\left(
      \frac{q\left(\mathbf{x}_i\right)}{1 - q\left(\mathbf{x}_i\right)}
    \right)
    =
    \mathbf{x}_i^\intercal \bm{\gamma}
    = \gamma_0 + \gamma_1 x_{1i} + \gamma_2 x_{2i},
    \label{eqn:p2_model}
  \end{equation}
  where $\bm{\gamma} = \begin{pmatrix}\gamma_0 & \gamma_1 & \gamma_2
  \end{pmatrix}^\intercal$. Write down the log-likelihood
  $l\left(\bm{\gamma}\right)$ for the sample $z_i$, $i = 1,\ldots, n$.

  \begin{description}
  \item[Solution:] Solving for $q\left(\mathbf{x}_i\right)$ in Equation
    \ref{eqn:p2_model}, we find
    \begin{equation}
      q\left(\mathbf{x}_i\right)
      = \frac{\exp\left(\mathbf{x}_i^\intercal \bm{\gamma}\right)}
      {1 + \exp\left(\mathbf{x}_i^\intercal \bm{\gamma}\right)}
      = \frac{1}
      {1 + \exp\left(-\mathbf{x}_i^\intercal \bm{\gamma}\right)}.
      \label{eqn:p2_qi}
    \end{equation}

    The likelihood function is
    $L\left( \bm{\gamma} \right) = \prod_{i=1}^n
    \left(q\left(\mathbf{x}_i\right)\right)^{z_i} \left(1 -
      q\left(\mathbf{x}_i\right)\right)^{1 - z_i}$, so the log-likelihood
    function becomes
    \begin{align}
      l\left(\bm{\gamma}\right)
      &= \log L\left( \bm{\gamma} \right)
        = \sum_{i=1}^n \left(
        z_i \log q\left(\mathbf{x}_i\right)
        +
        \left(1 - z_i \right) \log\left(1 - q\left(\mathbf{x}_i\right)\right)
        \right)
        \label{eqn:p2_log_likelihood}\\
      &= \sum_{i=1}^n\left(
        z_i\log\frac{q\left(\mathbf{x}_i\right)}{1 -q\left(\mathbf{x}_i\right)}
        + \log\left(1 -q\left(\mathbf{x}_i\right)\right)
        \right) \nonumber\\
      &= \sum_{i=1}^n
        \left(
        z_i\mathbf{x}_i^\intercal\bm{\gamma} +
        \log\frac{1}{1 + \exp\left(\mathbf{x}_i^\intercal\bm{\gamma}\right)}
        \right)
        = \sum_{i=1}^n
        -\log\left(
        1 + \exp\left(\left(1 - 2z_i\right)\mathbf{x}_i^\intercal\bm{\gamma}\right)
        \right). \nonumber
    \end{align}
  \end{description}
\item Fit the model described in the previous part, and give confidence
  intervals for the odds ratios.

  Carefully interpret these odds ratios.

  \begin{table}[!h]
    \centering
    \input{p3_gamma_hat.tex}
    \caption{Estimates and confidence intervals for $\hat{\bm\gamma}$ using
      maximum likelihood estimation.}
    \label{tab:p3_gamma_hat}
  \end{table}

  \begin{description}
  \item[Solution:] Taking the derivative of Equation
    \ref{eqn:p2_log_likelihood}, we have the score function:

    \begin{align}
      S\left(\bm\gamma\right)
      = \nabla^\intercal l\left(\bm\gamma\right)
      &= \sum_{i=1}^n \frac{2z_i - 1}{1 + \exp\left(
        \left(1 - 2z_i\right)\mathbf{x}_i^\intercal\bm{\gamma}
        \right)}\exp\left(
        \left(1 - 2z_i\right)\mathbf{x}_i^\intercal\bm{\gamma}
        \right)\mathbf{x}_i.
        \nonumber\\
      &= \sum_{i=1}^n \frac{2z_i - 1}{1 + \exp\left(
        \left(2z_i - 1\right)\mathbf{x}_i^\intercal\bm{\gamma}
        \right)}\mathbf{x}_i
      = X^\intercal\left(
        \mathbf{z} - \mathbf{q}\left(X\right)
        \right),
    \label{eqn:p3_score_function}
    \end{align}
    where
    $\mathbf{z} = \begin{pmatrix}z_1 & z_2 & \cdots & z_n\end{pmatrix}^\intercal$ and
    $\mathbf{q}\left(X\right) = \begin{pmatrix}q_1 & q_2 &
      \cdots & q_n\end{pmatrix}^\intercal$.

    From Equation \ref{eqn:p3_score_function}, we have the Fisher information
    matrix:
    \begin{align}
      I_n\left(\bm\gamma\right)
      &= \operatorname{var}\left(S\left(\bm\gamma\right) \mid \bm\gamma\right)
        = \mathbb{E}\left[
        S\left(\bm\gamma\right)
        S\left(\bm\gamma\right)^\intercal
        \mid \bm\gamma
        \right] \nonumber\\
      &= \mathbb{E}\left[
        X^\intercal\left(
        \mathbf{z} - \mathbf{q}\left(X\right)
        \right)
        \left(
        \mathbf{z} - \mathbf{q}\left(X\right)
        \right)^\intercal
        X \mid \bm\gamma
        \right] \nonumber \\
      &= X^\intercal\mathbb{E}\left[
        \left(
        \mathbf{z} - \mathbf{q}\left(X\right)
        \right)
        \left(
        \mathbf{z} - \mathbf{q}\left(X\right)
        \right)^\intercal
        \mid \bm\gamma
        \right]X \nonumber\\
      &= \sum_{i=1}^n
        q\left(\mathbf{x}_i\right)
        \left(1 - q\left(\mathbf{x}_i\right)\right)
        \mathbf{x}_i\mathbf{x}_i^\intercal
        =
        \sum_{i=1}^n
        \frac{1}{2 + \exp\left(
        -\mathbf{x}_i^\intercal \bm\gamma
        \right) + \exp\left(
        \mathbf{x}_i^\intercal \bm\gamma
        \right)}
        \mathbf{x}_i\mathbf{x}_i^\intercal
        ,
        \label{eqn:p3_fisher_information}
    \end{align}
    where we have used independence of the observations and variance of the
    binomial distribution to get the last line.

    We solve Equation \ref{eqn:p3_score_function},
    $S\left(\hat{\bm{\gamma}}\right) = \mathbf{0}$, to get an estimate for
    $\bm\gamma$. Using Equation \ref{eqn:p3_fisher_information}, we have that
    \begin{equation}
      \hat{\bm\gamma}
      \xrightarrow{\mathcal{D}}
      \mathcal{N}\left(
        \gamma,
        I_n^{-1}\left(\hat{\bm\gamma}\right)
      \right),
      \label{eqn:p3_gamma_hat_dist}
    \end{equation}
    that is, $\hat{\bm\gamma}$ is asymptotically normal.

    Using Equation \ref{eqn:p3_gamma_hat_dist}, we obtain the estimates and
    intervals in Table \ref{tab:p3_gamma_hat}.

    The predicted log odds ratio given some $\mathbf{x}_i$ is
    \begin{equation}
      \hat\theta_i = \mathbf{x}_i^\intercal\hat{\bm\gamma},
      \label{eqn:p3_prediction}
    \end{equation}
    which will have variance
    \begin{equation}
      \operatorname{var}\left(\hat\theta_i\right)
      = \mathbf{x}_i^\intercal\operatorname{var}\left(\hat{\bm\gamma}\right)
      \mathbf{x}_i
      \approx \mathbf{x}_i^\intercal I_n^{-1}\left(\hat{\bm\gamma}\right)
      \mathbf{x}_i,
      \label{eqn:p3_prediction_variance}
    \end{equation}
    using Equation \ref{eqn:p3_gamma_hat_dist}.

    From Equation \ref{eqn:p3_prediction_variance}, we can compute confidence
    intervals for the log odds ratio and exponentiate to get confidence
    intervals for the odds ratio since $\log$ is a monotonic
    transformation. Doing so results in the estimates in Table
    \ref{tab:p3_odds_ratios}.

    The odds ratio is how much more likely one is to have \emph{Moderate} or
    \emph{Impaired} mental impairment. Exponentiating Equation
    \ref{eqn:p3_prediction}, we have
    \begin{equation}
      \exp\left(\theta_i\right) =
      \exp\left(\gamma_0\right)
      \exp\left(\gamma_1x_{1i}\right)
      \exp\left(\gamma_2x_{2i}\right).
    \end{equation}

    $\exp\left(\gamma_0\right)$ is the expected odds ratio for a subject with
    $0$ SES and no life events. $\exp\left(\gamma_1\right)$ is the expected odds
    ratio between a subject with SES 1 and SES 0.
    $\exp\left(\hat{\gamma}_1\right) < 1$, so SES is associated with less mental
    impairment. $\exp\left(\gamma_2\right)$ is the expected odds ratio for a
    subject with an additional life event.
    $\exp\left(\hat{\gamma}_2\right) > 1$, so life events are associated with
    more severe mental impairment.
  \end{description}
  \begin{table}
    \scriptsize
    \centering
    \input{p3_odds_ratios.tex}
    \caption{Estimates for the odds ratios given $\mathbf{x}_i$ with
      $\hat{\bm\gamma}$.}
    \label{tab:p3_odds_ratios}
  \end{table}

\item We will now consider analyses that do not coarsen the data. We begin by
  defining notation in a generic situation. Suppose the random variable, $Y_i$,
  for individual $i$, $i = 1,\ldots,n$, can take values $0,1,2,\ldots,J-1$ (so
  that that there are $J$ levels). Assume that for individual $i$, the data
  follow a multinomial distribution,
  $Y_i \mid p_i \sim \operatorname{Multinomial}\left(1,\mathbf{p}_i\right)$
  independently, where $p_i = \begin{pmatrix}p_{i0} & \cdots & p_{i,J-1}
  \end{pmatrix}^\intercal$, and $p_{ij}$ represents the probability
  \begin{equation}
    p_{ij} = \mathbb{P}\left(Y_i = j \mid \mathbf{x}_i\right),
    ~\text{for}~j=0,1,\ldots,J-1,
    \label{eqn:p4_pij}
  \end{equation}
  where $\mathbf{x}_i = \begin{pmatrix} 1 & x_{1i} & x_{2i} & \cdots & x_{ki}
  \end{pmatrix}^\intercal$ for $i = 1,\ldots,n$.

  Suppose the response categories re nominal, that is, have no ordering. In this
  case, we may consider the \emph{generalized logit model}:
  \begin{equation}
    p_{ij} = \frac{\exp\left(\mathbf{x}_i^\intercal\bm\beta_j\right)}{
      \sum_{l=0}^{J-1}\exp\left(\mathbf{x}_i^\intercal\bm\beta_l\right)
    },~\text{for}~j=0,\ldots,J-1,
  \end{equation}
  where
  $\bm\beta_j = \begin{pmatrix} \beta_{j0} & \beta_{j1} & \cdots & \beta_{jk}
  \end{pmatrix}^\intercal$.

  Identifiability may be enforced by taking $\bm\beta_{J-1} = \mathbf{0}$, to
  give
  \begin{equation}
    \log\frac{p_{ij}}{p_{i,J-1}} = \mathbf{x}_i^\intercal\bm\beta_j,
    ~\text{for}~j=0,\ldots,J-2,
    \label{eqn:p4_log_odds_ratio}
  \end{equation}
  with $p_{i,J-1} = 1 - \sum_{j=0}^{J-2} p_{ij}$. Consider the case of $j = 3$
  levels and a single binary covariate $x$ so that that
  $\mathbf{x}_i = \begin{pmatrix} 1 & x_i \end{pmatrix}^\intercal$. Give a
  $3 \times 2$ table containing the probabilities of
  $\mathbb{P}\left(Y = j \mid x\right)$ in terms the $\beta_{jx}$ coefficients
  for rows $j = 0,1,2$ and columns $x=0,1$. Hence, give interpretations of
  $\exp\left(\beta_{jx}\right)$ for $j = 0,1,2$ and $x = 0,1$.

  Is the generalized logit model suitable for ordinal data?

  \begin{table}[h]
    \small
    \centering
    \begin{tabular}{lcc}
      \toprule
      $j$ & $x = 0$ & $x = 1$ \\
      \midrule
      $0$ & $\displaystyle\frac{\exp\left(\beta_{00}\right)}{1 + \exp\left(\beta_{00}\right) + \exp\left(\beta_{10}\right)}$ & $\displaystyle\frac{\exp\left(\beta_{00} + \beta_{01}\right)}{1 + \exp\left(\beta_{00} + \beta_{01}\right) + \exp\left(\beta_{10} + \beta_{11}\right)}$ \\
      $1$ & $\displaystyle\frac{\exp\left(\beta_{10}\right)}{1 + \exp\left(\beta_{00}\right) + \exp\left(\beta_{10}\right)}$ & $\displaystyle\frac{\exp\left(\beta_{10} + \beta_{11}\right)}{1 + \exp\left(\beta_{00} + \beta_{01}\right) + \exp\left(\beta_{10} + \beta_{11}\right)}$ \\
      $2$ & $\displaystyle\frac{1}{1 + \exp\left(\beta_{00}\right) + \exp\left(\beta_{10}\right)}$ & $\displaystyle\frac{1}{1 + \exp\left(\beta_{00} + \beta_{01}\right) + \exp\left(\beta_{10} + \beta_{11}\right)}$ \\
      \bottomrule
    \end{tabular}
    \caption{Multinomial probabilities for various $j$ and $x$.}
    \label{tab:p4_multinomial_probability}
  \end{table}

  \begin{description}
  \item[Solution:] See Table \ref{tab:p4_multinomial_probability} for the table
    of probabilities.

    Equation \ref{eqn:p4_log_odds_ratio} provides a way to interpret the
    $\beta_{jx}$. Let $p_{0j}$ and $p_{1j}$ denote the probabilities when
    $x = 0$ and $x = 1$, respectively. In this case, we have the odds ratios:
    \begin{align*}
      \frac{p_{0j}}{p_{02}} &= \exp\left(\beta_{j0}\right) \\
      \frac{p_{1j}}{p_{12}} &= \exp\left(\beta_{j0}\right)\exp\left(\beta_{j1}\right).
    \end{align*}

    Thus, the coefficients $\beta_{j0}$ are the expected log odds ratio for
    level $j$ relative to level $J - 1 = 2$ when the $x = 0$. $\beta_{j1}$ is
    the expected increase in this log odds ratio when $x = 1$. In this sense, we
    can consider the level $J - 1$ the default case, and the
    $\exp\left(\beta_{jx}\right)$ express how much more likely we are to
    observe level $j$.

    This model isn't suitable for ordinal data, for it is agnostic to the order
    of the data. From the above interpretation, it's more similar to fitting
    $J - 1$ individual logisitic regression models. For an ordinal model, we
    might want behavior like the most probable level varies monotonically with
    some covariate. There's no way to model such behavior with the
    \emph{generalized logit model} since each class has separate paramters.
  \end{description}
\item Let
  \begin{equation}
    \pi_{ij} = \mathbb{P}\left(Y_i \leq j \mid \mathbf{x}_i\right),
    \label{eqn:p5_pi_ij}
  \end{equation}
  for $j=0,\ldots,J-2$ and with $\mathbf{x}_i = \begin{pmatrix}
    1 & x_{1i} & x_{2i} & \cdots & x_{ki}
  \end{pmatrix}^\intercal$. Consider the proportional odds model
  \begin{equation}
    \log\frac{\pi_{ij}}{1 - \pi_{ij}} = \alpha_j - \mathbf{x}_i^\intercal\bm\beta,
  \end{equation}
  for $j = 0,1,J - 2$, and where $\bm\beta = \begin{pmatrix}
    \beta_0 & \beta_1 & \cdots & \beta_k
  \end{pmatrix}^\intercal$. Write down, in as simplified a form as possible, the
  log-likelihood $l\left(\bm\alpha,\bm\beta\right)$ where
  $\bm\alpha = \begin{pmatrix}
    \alpha_0 & \alpha_1 & \cdots & \alpha_{J - 2}
  \end{pmatrix}^\intercal$, for the sample $y_i$, $i = 1,\ldots,n$.
  \begin{description}
  \item[Solution:] Let $\alpha_{J-1} = \infty$ and
    $\alpha_{-1} = -\infty$. In this case, we have that
    \begin{align}
      p_{ij}
      &= \pi_{i,j} - \pi_{i,j-1}
        =  \frac{1}{1 + \exp\left(\mathbf{x}_i^\intercal\bm\beta - \alpha_j\right)} -
        \frac{1}{1 + \exp\left(\mathbf{x}_i^\intercal\bm\beta - \alpha_{j-1}\right)}
      \label{eqn:p5_pij}\\
      &= \begin{cases}
        \frac{
          \exp\left(\alpha_{j}\right) - \exp\left(\alpha_{j - 1}\right)
        }{
          \exp\left(-\mathbf{x}_i^\intercal\bm\beta + \alpha_{j-1} + \alpha_j\right) +
          \exp\left(\alpha_{j-1}\right) + \exp\left(\alpha_{j}\right) +
          \exp\left(\mathbf{x}_i^\intercal\bm\beta\right)
        }, &j=0,1,\ldots,J-2; \\
        \frac{1}{1 + \exp\left(\alpha_{J-2} - \mathbf{x}_i^\intercal\bm\beta\right)}, &j=J-1.
    \end{cases}\nonumber
    \end{align}
    Note that we must have
    $\alpha_0 \leq \alpha_1 \leq \cdots \leq \alpha_{J-2}$ for each class to
    have nonnegative probability.

    Then, likelihood function is
    \begin{equation}
      L\left(\bm\alpha, \bm\beta\right)
      = \prod_{i=1}^n \prod_{j=0}^{J-1} p_{ij}^{\mathbf{1}_{\{j\}}\left(y_i\right)},
      \label{eqn:p5_likelihood}
    \end{equation}
    where
    \begin{equation}
      \mathbf{1}_A\left(x\right) = \begin{cases}
        1,&x \in A; \\
        0,&\text{otherwise}.
      \end{cases}
      \label{eqn:p5_indicator}
    \end{equation}

    Taking the $\log$ of Equation \ref{eqn:p5_likelihood}, we have the
    log-likelihood function
    \begin{equation}
      l\left(\bm\alpha,\bm\beta\right)
      = \sum_{i=1}^n\sum_{j=0}^{J-1}\mathbf{1}_{\{j\}}\left(y_i\right) \log p_{ij}.
    \end{equation}
  \end{description}
\item For the data in Table \ref{tab:p1_data}, provide a single plot that shows
  the association between $\mathbf{p}\left(\mathbf{x}_i\right)$ and $x_{1i}$ and
  $x_{2i}$, on a scale you feel is appropriate.
  \label{part:p6}

  \begin{figure}
    \centering
    \includegraphics{p6_descriptive.pdf}
    \caption{Boxplots showing the relationship between mental impairment, SES
      and life events.}
    \label{fig:p6_descriptive}
  \end{figure}

  \begin{description}
  \item[Solution:] See Figure \ref{fig:p6_descriptive}. Conditioned on SES, the
    expected probability of having a more severe form of mental impairment
    increases with life events.

    The effect of SES on observed mental impairment is more ambiguous. When
    looking at the \emph{Well} and \emph{Moderate} levels, it seems that SES
    may have a slight protective effect against mental impairment, for we
    observe many subjects with a high number of life events but no mental
    impairment or less severe impairment. There doesn't seem to be much evidence
    of this phenomenon in the \emph{Mild} level. Ultimately, there's probably
    not enough data to come to any conclusion about SES.
  \end{description}
\item \label{part:p7} Fit the proportional odds models:
  \begin{align}
    \log\frac{\pi_{ij}}{1 - \pi_{ij}}
    &= \alpha_j^{(0)}
      \label{eqn:p7_model_1} \\
    \log\frac{\pi_{ij}}{1 - \pi_{ij}}
    &= \alpha_j^{(1)} - x_{1i}\beta_1^{(1)}
      \label{eqn:p7_model_2} \\
    \log\frac{\pi_{ij}}{1 - \pi_{ij}}
    &=  \alpha_j^{(2)} - x_{2i}\beta_2^{(2)}
      \label{eqn:p7_model_3} \\
    \log\frac{\pi_{ij}}{1 - \pi_{ij}}
    &= \alpha_j^{(12)} - x_{1i}\beta_1^{(12)} - x_{2i}\beta_2^{(12)}.
      \label{eqn:p7_model_4}
  \end{align}
  Compare models using likelihood ratio statistics, and summarize the
  association between mental impairment, SES and life events, using your favored
  model.

  \input{p7_model_summary.tex}

  \begin{description}
  \item[Solution:] The results of fitting the models can be seen in Table
    \ref{tab:p7_model_summary}. The coefficient estimates agree with what we saw
    in Figure \ref{fig:p6_descriptive} and the discussion in the solution of
    Part \ref{part:p6}: positive $\beta_2$ indicate that observed severity of
    mental impairment increases with life events, and negative $\beta_1$
    indicate that SES lessens the observed severity of mental impairment.

    Wilks' theorem tells us how to compute a test statistic for a log-likelihood
    ratio test:
    \begin{equation}
      D = 2\left(
        l\left(\bm\alpha^{(p)}, \bm\beta^{(p)}\right) -
        l\left(\bm\alpha^{(q)}, \bm\beta^{(q)}\right)
      \right) \xrightarrow{\mathcal{D}} \chi^2_{p - q},
      \label{eqn:p7_deviance}
    \end{equation}
    where $p > q$ and $\bm\beta^{(p)}$ and $\bm\beta^{(q)}$ each have
    dimensionality $p$ and $q$, respectively. That is, the deviance converges
    asymptotically to a chi-squared distribution with $p-q$ degrees of freedom.

    The test statistic in Equation \ref{eqn:p7_deviance} can be computed for
    various pairs of models with the last column of Table
    \ref{tab:p7_model_summary} when the two models are nested.

    Results of the tests on pairs of nested models can be seen in Table
    \ref{tab:p7_likelihood_ratio_test}. Since we are testing multiple
    hypotheses, we might consider apply the Bonferroni correction and rejecting
    at significance level $\alpha/m$, where $m$ is the number of tests and
    $\alpha$ is the desired familywise error rate (FWER). In this case, for
    $\alpha = 0.05$, we would reject the null hypothesis in tests with a
    $p$-value of less than $0.01$.

    \input{p7_likelihood_ratio_test.tex}

    From the first test that compares the model in Equation \ref{eqn:p7_model_2}
    against the null model in Equation \ref{eqn:p7_model_1}, SES alone does not
    improve the fit very much. From the second test that tests the model in
    Equation \ref{eqn:p7_model_3} against the null model, we see that life
    events improves fit more: the $p$-value of 0.01070 is the on the border of
    statistical significance. The improved fit from the model in Equation
    \ref{eqn:p7_model_4} that incorporates both SES and life events is found to
    be statistically significant when compared against the null model and the
    model only containing SES. However, when tested against the model containing
    only life events, it doesn't quite meet statistical significance.

    Despite the last test not rejecting the model in Equation
    \ref{eqn:p7_model_3}, I'd still favor the model in Equation
    \ref{eqn:p7_model_4} that includes both SES and life events with the caveat
    that an additional experiment should be done. If possible, an additional
    experiment should be done with higher power (more subjects) that tests the
    null model in Equation \ref{eqn:p7_model_3} against the alternate model in
    Equation \ref{eqn:p7_model_4}.
  \end{description}

\item Provide a plot of fitted probabilities under the model in Equation
  \ref{eqn:p7_model_4}, as a function of $x_1$ and $x_2$.

  \begin{figure}[h]
    \centering
    \caption{Fitted probabilities of mental impairment levels using the model
      described in Equation \ref{eqn:p7_model_4}.}
    \includegraphics{p8_fitted_probabilities.pdf}
    \label{fig:p8_fitted_probabilities}
  \end{figure}

  \begin{description}
  \item[Solution:] See Figure \ref{fig:p8_fitted_probabilities}. As described in
    the solution of Part \ref{part:p7}, life events increases the expected
    observed level of mental impairment. SES lessens the severity so curves of
    the same color are shifted downward.
  \end{description}
\end{enumerate}

\clearpage

\section*{Appendix}

\subsection*{Code}

Code for the logistic regression model and boxplots can be found in
\href{http://nbviewer.jupyter.org/github/ppham27/stat570/blob/master/hw7/mental_impairment.ipynb}{\texttt{mental\_impairment.ipynb}}. Code
for the proportional odds models and Figure \ref{fig:p8_fitted_probabilities}
can be found in
\href{http://nbviewer.jupyter.org/github/ppham27/stat570/blob/master/hw7/proportional\_odds.ipynb}{\texttt{proportional\_odds.ipynb}}.

\subsection*{Data}

The raw mental impairment data is in Table \ref{tab:p1_data}.

\begin{table}[h]
  \scriptsize
  \centering
  \input{p1_data.tex}
  \caption{Data on mental impairment, socioeconomic status (SES) and life
    events, for 40 subjects.}
  \label{tab:p1_data}
\end{table}

\end{document}


\section{Conclusions}

We proposed BSC, a novel Bayesian approach to aggregating sequence labels
that can be combined with several different models of annotator noise and bias.
To model the effect of dependencies between labels on annotator noise and bias, we introduced
the \emph{seq} annotator model.
Our results demonstrated the benefits of BSC over established non-sequential methods, such
as MACE, Dawid-Skene (DS), and IBCC.
%reinforce previous work that has demonstrated the benefits of modeling annotator reliability when aggregating noisy data, such as crowdsourced labels.
We also showed the advantages of a Bayesian approach for active learning,
and that the combination of \emph{BSC} with the \emph{seq} annotator model improves
the state-of-the-art over HMM-crowd on three NLP tasks with different types of span annotations.

In future work, we plan to adapt active learning methods for easy deployment on crowdsourcing platforms,
and to investigate techniques for automatically selecting good hyperparameters without recourse to a development
set, which is often unavailable at the start of a crowdsourcing process.
%Its performance depends on the combination of sequential annotator model, label transition matrix, and
%text model.
%To enable more efficient training data collection,
% We further improved the quality of aggregated labels,
% by integrating existing
% sequence taggers into our variational inference approach as black-box training and prediction functions.
% This technique performed well with larger amounts of labeled data, but may benefit from the use of pre-trained neural sequence taggers
% when the dataset is very small.
%We also found that including a simple conditional independence model of text features enables us to learn BSC-seq more effectively.
% Future work will evaluate integrating sequence taggers built on
% Bayesian deep learning,
% which may improve active learning.
% We will also investigate
% %alternative data selection strategies to bootstrap active learning,
% %and
% how to set priors for %reduce over-confidence in predictions by including
% the reliability of black-box methods by testing them
% on other training sets of similar size.

%how to adapt hyper-parameters of the NN automatically in low-resource state?

% % In future, BSC-Seq could be applied to other sequential classification tasks beside span annotation.
% For example, the order of tasks that are intended to be exchangeable may affect the likelihood
% of the labels provided by the annotators\cite{mathur2017}. Seq-BCC could be applied to model the
% propensity of the workers to choose certain labels given their previous labels, while the
% ground truth sequence may be ignored.