\documentclass[../Main.tex]{subfiles}

\begin{document}
%\subsection{Data Exploration} %TODO: fill this out later.
%look at trial 
\subsection{Model Fitting}
In this section we examine the results from fitting the econometric model using
mc-stan (\cite{mc-stan}) through the rstan (\cite{rstan}) interface.

%describe 
The model was based on the hierarchal logistic regression model 
presented in the Stan Users Guide (\cite{mc-stan}), 
and was run with 2,500 warmup iterations and
2,500 sampling iterations in six chains.
There were various issues, including 160 divergent transitions and the R-hat 
measure was 1.49. 
Overall these suggest that the econometric model is incorrect as 
written or requires reparameterization.
%TODO: and info about how I learned about these diagnostics


\subsubsection{Diagnostics}
%Examine trank plots
To identify which parameters were problematic, I first looked at trace rank 
histograms.
Under idea circumstances, each line (representing a chain) should exchange 
places with the other lines frequently.
In both \cref{fig:mu_trank} and \cref{fig:sigma_trank}, most parameters seem
to mix well but there are a couple of exceptions.
This warrants further investigation.

\begin{figure}[H]
    \includegraphics[width=\textwidth]{../assets/img/mu_trank.png}
    \caption{Trace Rank Histogram: Mu values}
	\label{fig:mu_trank}
\end{figure}

\begin{figure}[H]
    \includegraphics[width=\textwidth]{../assets/img/sigma_trank.png}
    \caption{Trace Rank Histogram: Sigma values}
	\label{fig:sigma_trank}
\end{figure}

%Take a look at batman and points for mu
In the case of the Mu values, a parallel coordinates plot 
doesn't seem to indicate any parameters as likely candidates
for causing the issues with divergent transitions.
\begin{figure}[H]
    \includegraphics[width=\textwidth]{../assets/img/mu_batman.png}
    \caption{Parallel Coordinate Plot: Mu values}
	\label{fig:mu_batman}
\end{figure}
Note that at each parameter, there is some level of dispersion between 
values that diverged.

On the other hand, in the parallel coordinates plot for sigma values,
it appears that most divergent transitions occur with values of 
sigma[1], sigma[3], sigma[6], and sigma[7] close to zero.
\begin{figure}[H]
    \includegraphics[width=\textwidth]{../assets/img/sigma_batman.png}
    \caption{Parallel Coordinate Plot: Sigma values}
	\label{fig:sigma_batman}
\end{figure}
Overall this suggests that there is an issue with the specification
of the covariance structures of the hyperparameters.

Additional evidence that the covariance structure is incorrect comes from 
plotting pairs of parameter values and examining the chains with divergent
transitions.

\begin{figure}[H]
    \includegraphics[width=\textwidth]{../assets/img/sigma_pairs_5-9.png}
	\caption{Parameter Pairs plots: Sigma[5] through Sigma[9]}
	\label{fig:sigma_pairs_5-9.png}
\end{figure}
From this we can see that divergent pairs are highly correlated with the cases
where sigma[6] or sigma[7] are equal to zero.
This has an impact on the shape of both of those estimated parameters, causing
both to be bimodal.


\subsection{Interpretation}

Ignoring the diagnosed issues with the model, we do see some interesting
preliminary results.

%in mu, mu[5] shifted strongly
In \cref{fig:mu_posterior} we see that mu[5], the parameter corresponding
to enrollment appears to be strongly negative.
This is consistent with the idea that enrollment close to planned enrollment
decreases the probability of terminating the trial.
In \cref{fig:sigma_posterior}, sigma[2] (corresponding to the number of brands
selling the drug of interest) has a large variance covers some relatively 
high values.
This suggests that the impact of how frequently the drug is sold varies greatly
across different ICD-10 categories of disease.


\begin{figure}[H]
    \includegraphics[width=\textwidth]{../assets/img/mu_posterior.png}
	\caption{Posterior Parameter Estimates: Mu}
	\label{fig:mu_posterior}
\end{figure}

% Sigma[2] suggests there is a high variance in the impact that the number of drugs on the market has.
\begin{figure}[H]
    \includegraphics[width=\textwidth]{../assets/img/sigma_posterior.png}
	\caption{Posterior Hyperparameter Estimates: Sigma}
	\label{fig:sigma_posterior}
\end{figure}

Due to the deficiencies in the data and model, this is the limit of the 
analysis I will perform at this time.

\end{document}
