% ---------------------------------------------------------
% Project: PhD KAPPA
% File: background.ipd.tex
% Author: Andrea Discacciati
%
% Purpose: Section IPD (background)
% ---------------------------------------------------------

\section{Survival analysis of primary data}
\label{section:saipd}

Survival analysis refers to the analysis of time from a specific time point until the occurrence of a well-defined event (survival time).\footnote{The terms `event', `outcome', and `disease' are equivalent and therefore they are used interchangeably in this thesis.} A unique characteristic of survival data is that observations may be censored --- that is, for some study individuals the event time is unknown. There are different censoring mechanisms, but right-censoring --- arguably the most common in epidemiologic studies --- is the only type of censoring considered in this thesis. Furthermore, we will make the assumption that survival time and censoring time are independent, possibly conditional on a vector of known, fixed covariates.

With no censoring, survival time can be analyzed as any other numeric variable, for example using Wilcoxon's rank-sum test or standard quantile regression.
When censoring is present, a number of statistical tools is available to deal with this mechanism. However, one should always remember that the ultimate goal is to describe the distribution of survival time, and how this is affected by a vector of covariates.

Lastly, the term `primary data' (or `individual patient data') refers to the availability of raw data for each participant in an epidemiologic study or clinical trial, as opposed to aggregated data.

\subsection{Basic statistical concepts}
\label{section:basicstatconcepts}

The statistical concepts introduced in this section are standard and therefore only a brief overview will be given. See for example \citet{kleinbaum_survival_2012} for a more rigorous and detailed exposition.

Let $T$ be a continuous, non-negative random variable with probability density function (p.d.f.) $f(t)$, and cumulative density function (c.d.f.) $F(t) = \Pr(T \le t)$, which gives the probability that the event has occurred by time $t$. Usually, one observes the possibly right-censored random variable $Y = \min(T, C)$, where $C$ is the censoring random variable. In addition to the p.d.f. and the c.d.f., there are three  alternative but equivalent  functions to describe the distribution of $T$. These are the survival function, the hazard function, and the cumulative hazard function.

The survival function $S(t)$ gives the probability that the survival time is larger than $t$ --- that is, the probability of being event-free at time $t$. It is a non-decreasing function of $t$ and can take values between 0 and 1. $S(t)$ is equal to 1 minus the c.d.f.:
\begin{equation}
S(t) = \Pr(T > t) = 1 - F(t) = \int_t^{+\infty}f(s)ds.
\label{eq:survivalfunction}
\end{equation}

A common non-parametric estimator for the survival function is the Kaplan-Meier product-limit estimator \citep{kaplan_nonparametric_1958}.

A different characterization of the distribution of $T$ is given by the hazard function $h(t)$, which is defined as:
\begin{equation}
h(t) = \lim_{dt \rightarrow 0} \frac{\Pr(t < T \le t + dt | T > t)}{dt}.
\label{eq:hazardrate}
\end{equation}

The numerator of the hazard function is the conditional probability that the event of interest will happen in the time interval $(t,t+dt)$, given that it has not occurred before. The denominator is the width $dt$ of such a time interval. By dividing the first by the second, one obtains the event rate per unit of time, and taking the limit as $dt$ goes to 0, the instantaneous event rate. Therefore, $h(t)dt$, for an infinitesimal $dt$, is akin to the conditional probability that the event will occur in the time interval $(t,t+dt)$ given $S(t)$. However, the hazard itself is not a probability (and in fact it is not bounded between 0 and 1). The key feature of the hazard function is its conditional nature. Contrast, for example, the unconditional probability, for all the men born on a given year, of dying after 40 years of age [$S(40)$], with the probability of dying in the time interval $(39 < T \le 40 \textrm{ years } | \textrm{ alive at 39 years})$. For example, $S(40)$ was estimated to be around 60\% for men born in 1861 in Sweden. However, given survival up to 39 years of age, the probability of being alive at age 40 years was much higher, roughly 98\% \citep{scb_cohort_2010}.

Lastly, the cumulative hazard function is the integrated hazard function:
\begin{equation*}
H(t)=\int_0^t h(s)ds.
\end{equation*}

All the functions described above are mathematically related and in particular,
\begin{align}
S(t) &= \exp\left(-H(t)\right) = \exp\left(-\int_0^t h(s)ds\right). \label{eq:SfromH}
\end{align}

\subsection{The proportional-hazards approach to survival modeling}
\label{sec:phapproach}

In the previous section we focused on how to characterize the distribution of $T$. However, a major objective in epidemiologic research is to describe the variation in the distribution of $T$ --- and therefore in survival --- among individuals, given a vector of covariates. Different ``classical'' approaches to survival modeling are available, the most common probably being Accelerated Failure Time models and proportional-hazards (PH) models. An additional  approach was recently introduced by \citet{royston_flexible_2002}.\footnote{Royston-Parmar models include, but are not limited to, PH models.} In this section we will give a brief overview of the PH model. The literature on this topic is enormous and the reader can refer for example to \citet{therneau_modeling_2000}, \citet{kalbfleisch_statistical_2002}, and \citet{vanhouwelingen_cox_2013} for a more complete discussion.

\subsubsection{The proportional-hazards model}
The PH model focuses directly on the hazard function. In particular, the hazard at time $t$, for a given individual $i$ with covariate vector $\mathbf{x}_i=(x_{i1},\ldots,x_{ik})$ (not including a constant), is assumed to be:
\begin{equation}
h_i(t|\mathbf{x}_i) = h_0(t)\exp\left(\mathbf{x}_i^\top\boldsymbol{\beta}\right),
\label{eq:phmodels}
\end{equation}
where $ h_0(t)$ is the baseline hazard for all individuals with $\mathbf{x}_i = \left(0,\ldots,0\right)$, $\boldsymbol{\beta} = \left( \beta_1,\ldots,\beta_k \right)$ is the vector of unknown model coefficients, and $\exp\left(\mathbf{x}_i^\top\boldsymbol{\beta}\right)$ is a proportional (multiplicative) increase or reduction of the baseline hazard associated with the covariates $\mathbf{x}_i$ --- that is, the Hazard Rate Ratio (HRR). Of note, this proportional increase or reduction in baseline hazard is constant over $t$. In other words, PH models assume that the relative effect of a covariate is the same at all time points.

An immediate consequence of models written in the form of equation (\ref{eq:phmodels}), is that the cumulative hazards are proportional too. In fact, integrating both sides of the equation from 0 to $t$ gives the following result:
\begin{equation}
H_i\left(t|\mathbf{x}_i\right) = \int_0^t h_0(s)\exp\left(\mathbf{x}_i^\top\boldsymbol{\beta}\right)ds = H_0(t)\exp\left(\mathbf{x}_i^\top\boldsymbol{\beta}\right).
\label{eq:phcumhazard}
\end{equation}
Moreover, given equation (\ref{eq:SfromH}), the following relation for the survival function is immediately obtained:
\begin{equation}
S_i(t|\mathbf{x}_i) = S_0(t)^{\exp\left(\mathbf{x}_i^\top\boldsymbol{\beta}\right)}.
\label{eq:phmodelssurv}
\end{equation}

This important result says that, for PH models, the effect of the covariate vector $\mathbf{x}_i$ on the survival function is to raise $S_0(t)$ (the baseline survival function) to a power equal to the constant $\exp\left(\mathbf{x}_i^\top\boldsymbol{\beta}\right)$. As \citet[pg.~118]{kalbfleisch_statistical_2002} pointed out ``note that the assumed model constraints the estimates so that one survivor function dominates the other. Such graphs can give a misleading impression that one of the treatments is consistently preferable and suggest significant differences even when they are not present.''

%TODO: Left truncation?

\subsubsection{Time-dependent coefficients}
The PH model lends itself to extensions, such as time-varying covariates and time-dependent coefficients. In particular, time-dependent coefficients are useful to relax the assumption of proportionality of the hazards over time. To accommodate time-dependent coefficients, the PH model can be rewritten as:
\begin{equation}
h_i(t|\mathbf{x}_i) = h_0(t)\exp \left(\mathbf{x}_i^\top\boldsymbol{\beta}(t)\right),
\label{eq:timedepph}
\end{equation}
and the time-dependent coefficients are modeled using $b$ transformations of time. For example, suppose that only one coefficient $\beta(t)$ is included in the model, then
\begin{equation}
\beta(t) = \sum_{j=1}^b \gamma_j g_j(t).
\label{eq:timevcoef}
\end{equation}

This extended model --- sometimes referred to as `extended PH model' or `general hazard rate model' ---  implies that the HRR is free to vary over time (time-dependent HRR). Another consequence is that the simple equation (\ref{eq:phmodelssurv}) does not longer apply, as the coefficients are now a function of time and therefore they cannot be taken out of the integral in equation (\ref{eq:phcumhazard}). The survival curve for the $i$-th individual is now given by:
\begin{equation}
S_i(t|\mathbf{x}_i) = \exp\left(-\int_0^t h_0(s)\exp \left(\mathbf{x}_i^\top\boldsymbol{\beta}(s)\right) ds \right).
\label{eq:tvphmodelssurv}
\end{equation}

Calculation of the survival curve is still possible, but is now more complicated. The integral in equation (\ref{eq:tvphmodelssurv}) can be derived analytically (in simple parametric situations) or numerically, as a cumulative sum of predictions. The latter approach is described in detail by \citet[section 4]{carstensen_demography_2005}. The complexity in the calculation of model-based survival curves is certainly a drawback of PH models with time-dependent coefficients. At the same time, one should keep in mind that these models put the focus on the HRR, which on the other hand is quite simple to calculate even in the presence of time-dependent coefficients \citep{heinzl_gaining_1997}.

The consequences on the HRR of the omission of time-dependent coefficients  when actually needed are numerous in the literature \citep[see, for example,][]{royston_use_2011, uno_moving_2014}. Figure \ref{fig:phnophsurvcurve}, on the other hand, shows an example of such consequences on model-based predicted survival curves. In particular, in panel A the hazards were forced to be proportional [equation (\ref{eq:phmodelssurv}) for the survival curves applies], whereas in panel B this assumption was relaxed by including a time-dependent coefficient [equation (\ref{eq:tvphmodelssurv}) for the survival curves applies].

\begin{figure}[p]
\begin{center}
\includegraphics[width=\linewidth]{figures/phnophsurvcurve.pdf}
\end{center}
\caption[Survival curves from proportional-hazards models]{Consequences of the violation of the PH assumption on the predicted survival curves. In panel A, a PH model without time-dependent coefficients was employed. The model-based predicted survival curves for women in the active treatment (red solid line) and in the placebo arm (blue solid line) were far off from the corresponding non-parametric Kaplan-Meier estimates (dashed lines). In panel B, the time-dependent coefficient for the binary variable indicating the treatment group was modeled using restricted cubic splines with 5 knots. As a result, the model-based predicted survival curves  followed closely the corresponding non-parametric estimates. Note how in panel B the model-based survival curves cross after around 3.5 years, following the behavior of the Kaplan-Meier estimates. See \citet{hulley_randomized_1998} for more information about the data.}
\label{fig:phnophsurvcurve}
\end{figure}

\subsubsection{Model fitting}
There are different possible approaches to fitting hazard rate models. %, and the ubiquitous Cox model is just one of them.

The first is the `pure' parametric approach, where the time variable $T$ is assumed to follow a specific distribution. Consequently, a specific functional form is assumed for the baseline hazard $h_0(t)$. Examples of distributions used to characterize $T$ are the exponential, Weibull, and Gompertz distribution.

The second approach might be referred to as the `flexible' parametric approach.\footnote{Not to be confused with the flexible parametric survival model by Royston and Parmar \citep{royston_flexible_2002, royston_flexible_2011}, which is not covered in this thesis.} With this approach, time is split into non-overlapping intervals and the assumption that the baseline hazard $h_0(t)$ is constant within each interval is made, leading to a so-called piece-wise exponential model. If time is split finely enough, one can use a smooth, flexible function of time to model $h_0(t)$. Time-dependent HRRs are easily accommodated by including interactions (product terms) between covariates and transformations of time.\footnote{This shows that, practically, models with time-dependent coefficients can be handled in the same way as models with time-varying covariates \citep{vanhouwelingen_cox_2013}.} Since an exponential distribution for $T$ is assumed within each time interval, these models are closely related to Poisson regression \citep[section 4.2]{breslow_statistical_1987}.

The third approach is the `semi-parametric' approach, where the association between the covariates and the hazard is modeled parametrically --- similarly to the other two approaches --- but the baseline hazard $h_0(t)$ is left unspecified. This approach is based on a partial likelihood function introduced by \citet{cox_regression_1972}. Non-parametric estimates, following a Cox model, of the baseline survival function and of the cumulative hazard function can be calculated as described by \citet[section~4.3]{kalbfleisch_statistical_2002}. A smooth estimate of the baseline hazard can then be obtained by smoothing the cumulative hazard function using a kernel estimator as described for example in \citet[section~5.3]{breslow_statistical_1987} and \citet[section~8.4]{cleves_introduction_2010}, or by simple parametric modeling of the estimated cumulative hazard function \citep{royston_estimating_2011}.
%In this case, it is  possible to obtain a non-parametric estimate of the baseline cumulative hazard via, for example, the Kalbfleisch and Prentice estimator \citep[section 4.3]{kalbfleisch_statistical_2002}. The baseline survival curve can then be obtained using equation (\ref{eq:SfromH}), while the baseline hazard can be calculated by smoothing the cumulative hazard  using a kernel estimator and numerical differentiation techniques.

The boundaries between the approaches described above are not clear-cut. In fact, the `flexible' parametric approach is ultimately a `pure' parametric approach. Likewise, conditional Poisson regression is equivalent to Cox regression --- that is, the contribution of each subject to the the profile log-likelihood for $\boldsymbol{\beta}$ of a Poisson model, where time is split at each failure time, is the same as the contribution of the $j$-th event time to the partial log-likelihood of a Cox model. This extends to the more general case where tied events are present \citep{carstensen_demography_2005, royston_flexible_2011}.

\subsection{The percentile approach to survival modeling}

Due to the widespread use of PH models, the HRR --- time-varying or otherwise --- has become the standard summary for comparing the survival between different groups of individuals. An alternative, complementary approach to compare such differences is to focus on survival percentiles and, specifically, on percentile differences (PDs).

\subsubsection{Survival percentiles}
The $100p$-th survival percentile of the previously defined random variable variable $T$ is the time $t$ by which $100p$\% of the study population has experienced the event of interest (where $0<p<1$ is the survival quantile). For example, 25th survival percentile is the time $t$ by which 25\% of the study population has experienced the event. Likewise, one could say that a randomly selected individual from this study population has 0.25 probability of experiencing the event within time $t$ (and consequently 0.75  probability of experiencing it after time $t$). Therefore, survival percentiles provide the link between a given probability of experiencing the outcome and the time by which that probability is reached.

\begin{figure}[tb]
\begin{center}
\includegraphics[width=.8\linewidth]{figures/kmpercentile.pdf}
\end{center}
\caption[Survival curve and 5th survival percentile]{Non-parametric survival curve estimate for all the women enrolled in the HERS trial (solid line) \citep{hulley_randomized_1998}. The dashed line illustrates the 5th survival percentile (around 1.4 years).}
\label{fig:kmpercentile}
\end{figure}

More formally, the $100p$-th survival percentile is defined as:
\begin{equation*}
Q_T(p) =  \inf \left\{ t: \Pr\left(T \le t\right) \ge p \right\}.
\end{equation*}
The function $Q_T(\cdot)$ is the quantile function, and is defined as that function such that $1-S\left(Q_T(p)\right) = F\left(Q_T(p)\right) = p$, where $F(\cdot)$ is the c.d.f. of $T$ introduced at the beginning of section \ref{section:basicstatconcepts}. Of note, not all the survival percentiles are always estimable. It is not possible for example to calculate the 25th survival percentile for the survival curves presented in figure \ref{fig:kmpercentile}. This is because at the end of the follow-up time, only around 15\% of the individuals  had experienced the event of interest (coronary heart disease). However, all the percentiles up to the 15th are estimable. For example, the 5th survival percentile obtained from the Kaplan-Meier estimate of the survival curve was around 1.4 years (dashed line).

One might want to estimate the $100p$-th survival percentile conditional on a given covariate vector $\mathbf{x}$. In this case, the definition of survival percentiles easily extends to:
\begin{equation*}
Q_{T}(p|\mathbf{x}) =  \inf \left\{ t: \Pr\left(T \le t|\mathbf{x}\right) \ge p \right\},
\end{equation*}
and comparisons between groups of individuals (for example, exposed and unexposed) in terms of time elapsed before a certain proportion of individuals has experienced the event can be made. For example, in figure \ref{fig:phnophsurvcurve}, the 5th survival percentile for those women in the active treatment arm (red dashed line) was around 1.3 years, whereas the same percentile was around 1.6 years for those women in the placebo arm (blue dashed line). As a result, the 5th PD between the placebo and treatment arm was 0.3 years. On the other hand, the 15th PD was practically equal to 0 years.

A statistical method that combines the flexibility of a modeling approach with the simplicity of focusing directly on survival percentiles is quantile regression for censored data.

\subsubsection{Quantile regression for censored data}

The idea behind quantile regression for censored data is to link the conditional $100p$-th survival percentile $Q_{T_i}(p|\mathbf{x}_i)$ to the covariate vector $\mathbf{x}_i=\left(x_{i1},\ldots,x_{ik}\right)$ (generally including an intercept) though a linear, additive model. In particular:
\begin{equation}
Q_{T_i}(p|\mathbf{x}_i) = \mathbf{x}_i^\top\boldsymbol{\beta}(p) = \sum_{j=0}^k \beta_j(p)  x_{ij}.
\label{eq:quantilemod}
\end{equation}

Some considerations regarding this model are necessary. First, the notation $\boldsymbol{\beta}(p)$ underlines the important characteristic that the model coefficients are not constrained to be equal for different survival percentiles. Therefore, no assumptions similar to the proportionality of the hazards are made.

Second, the linear predictor $\mathbf{x}_i^\top\boldsymbol{\beta}(p)$ can include flexible transformations of continuous covariates (such as splines of fractional polynomials), product terms, and the like. This model is perfectly suited for the analysis of epidemiologic data, where it is important to be able to model continuous covariates and adjust for confounding.

Third, by estimating multiple percentiles, one can thoroughly describe the distribution of $T$, conditionally on $\mathbf{x}$.

Fourth, the interpretation of the coefficients is particularly useful and straightforward, and it is strictly related to how one would interpret the coefficients of a classical linear regression. For example, just like in linear regression one would interpret a coefficient for a continuous variable $z$ as ``the change in the mean response variable for every 1-unit increase in $z$, adjusting for the other covariates in the model'', the interpretation of a similar coefficient from a quantile regression for survival data is ``the change in the $100p$-th survival percentile for every 1-unit increase in $z$, adjusting for the other covariates in the model''. The model coefficients are, in other words, PDs (and therefore absolute measures of association).\footnote{With the usual exception regarding the coefficient for the intercept, for the product terms, and for splines or other non-linear transformations of continuous variables.}

Lastly, and most importantly, the model coefficients are now expressed in the metric of time, which means that they provide an intuitive measure of association between the covariates and the event of interest. This in contrast with the HRR, which is a dimensionless measure of association and possibly more difficult to interpret \citep{uno_moving_2014}.

Different methods have been proposed to deal with the model-based estimation of conditional percentiles when data is censored \citep{powell_censored_1986, portnoy_censored_2003, peng_survival_2008, wang_locally_2009, bottai_laplace_2010}. A description of the methods by Powell, Portnoy, and Peng and Huang can be found in \citet{koenker_censored_2008}. In this thesis and in \citetalias{bellavia_using_2015}, however, we will deal with the approach developed by \citet{bottai_laplace_2010} and known as `Laplace regression'.

\subsubsection{Laplace regression}

Re-introducing the notation used before, let $Y_i=\min(T_i,C_i)$ be the observed survival time measured on the $i$-th out of $n$ individuals. Moreover, let $d_i$ be indicator variable which takes value 1 if the survival time $Y_i$ is not censored and value 0 otherwise.

Assume that
\begin{equation}
T_i = \mathbf{x}_i^\top\boldsymbol{\beta}(p) + \epsilon_i,
\label{eq:laplacemodel}
\end{equation}
where $\mathbf{x}_i$ is the covariate vector, $\boldsymbol{\beta}(p)$ is the vector of unknown model coefficients, and $\epsilon_i$ are independently and identically distributed errors that follow a standard Laplace distribution, which is equivalent to an asymmetric Laplace (AL) distribution with location parameter 0 and scale parameter 1. For any given $p$, the $p$-th quantile of the conditional distribution of $T_i$ given $\mathbf{x}_i$ is $\mathbf{x}_i^\top\boldsymbol{\beta}(p)$ --- that is, $Q_{T_i}(p|\mathbf{x}_i) = \Pr(T_i \le \mathbf{x}_i^\top\boldsymbol{\beta}(p) | \mathbf{x}_i) = p$ \citep{bottai_laplace_2010}.

The AL distribution has a location parameter $\mu(p)$ and a scale parameter $\sigma(p)$. This notation underlines the fact that, in the specific situation presented in this thesis, $p$ is not a parameter to be estimated, rather it is treated as fixed. The AL distribution has the following p.d.f.:
\begin{equation}
f_{\textrm{AL}}\left(s\right) = \frac{p\left(1-p\right)}{\sigma(p)}\exp\left(-\frac{s-\mu(p)}{\sigma(p)}\left[p-I\left(s\le\mu(p)\right)\right] \right),
\label{eq:ald}
\end{equation}
where $\sigma(p)>0$, $-\infty < \mu(p) < +\infty$, and $I(\cdot)$ is the indicator function \citep{yu_threeparameter_2005}.

Therefore, since the asymmetric Laplace in (\ref{eq:ald}) is a location-scale family of densities, $T_i$ follows an AL distribution with p.d.f conditional to $\mathbf{x}_i$ equal to:
\begin{equation}
f_{\textrm{AL}}\left(t_i|\mathbf{x}_i\right) = \frac{p\left(1-p\right)}{\sigma(p)}\exp\left(-\frac{t_i-\mathbf{x}_i^\top\boldsymbol{\beta}(p)}{\sigma(p)}\left[p-I\left(t_i\le\mathbf{x}_i^\top\boldsymbol{\beta}(p)\right)\right] \right),
\label{eq:pdf}
\end{equation}
and c.d.f.
\begin{align}
\begin{split}
F_{\textrm{AL}}\left(t_i|\mathbf{x}_i\right) = &\exp\left(-\frac{t_i-\mathbf{x}_i^\top\boldsymbol{\beta}(p)}{\sigma(p)}\left[p-I\left(t_i\le\mathbf{x}_i^\top\boldsymbol{\beta}(p)\right) \right] \right) \left[p-I\left(t_i>\mathbf{x}_i^\top\boldsymbol{\beta}(p)\right)\right]  \label{eq:cdf} \\
&+ I\left(t_i>\mathbf{x}_i^\top\boldsymbol{\beta}(p)\right)
\end{split}
\end{align}
as derived by \citet{bottai_laplace_2010}. The subscript AL in $f_{\textrm{AL}}(\cdot)$ and $F_{\textrm{AL}}(\cdot)$ is used to distinguish these functions from the p.d.f. and c.d.f. of $T$, respectively.  Heteroskedasticity of the error term can be accommodated by allowing the scale parameter $\sigma(p)$ to depend on a vector of covariates.

The contribution to the likelihood function $L$ of an uncensored observation ($d_i=1$) is given by the p.d.f. in (\ref{eq:pdf}) evaluated at the observed survival time $y_i$ --- that is $L_i=f_{\textrm{AL}}(y_i)$. On the other hand --- under the assumption of non-informative censoring conditionally on $\mathbf{x}_i$ --- a censored observation ($d_i=0)$  carries only the information that his/her event time $t_i$ is larger than $y_i$. The contribution to the likelihood function is therefore $L_i=1-F_{\textrm{AL}}(y_i)$. Consequently, the likelihood function is proportional to:\footnote{Note that this way of constructing the likelihood function also applies to parametric PH models under conditional independent right-censoring. See for example \citet[chapter~5]{lawless_statistical_2003} or \citet[chapter~3]{kalbfleisch_statistical_2002}.}
\begin{equation*}
L(\boldsymbol{\beta}(p), \sigma(p);y_i, \mathbf{x}_i, d_i)= \prod_{i=1}^n f_{\textrm{AL}}(y_i|\mathbf{x}_i)^{d_i} \left(1-F_{\textrm{AL}}(y_i|\mathbf{x}_i)\right)^{(1-d_i)}.
\end{equation*}

The log-likelihood function is obtained as usual by taking the logarithm of the likelihood:
\begin{equation}
l(\boldsymbol{\beta}(p), \sigma(p);y_i, \mathbf{x}_i, d_i)= \sum_{i=1}^n \left[ d_i \log f_{\textrm{AL}}(y_i|\mathbf{x}_i) + \left(1-d_i\right) \log \left(1-F_{\textrm{AL}}(y_i|\mathbf{x}_i)\right) \right].
\label{eq:logliklap}
\end{equation}

Lastly, by substituting equations (\ref{eq:pdf}) and (\ref{eq:cdf}) in (\ref{eq:logliklap}), and after some algebraic manipulations, the log-likelihood function becomes:
\begin{align}
\begin{split}
l(\boldsymbol{\beta}(p), \sigma(p)&;y_i, \mathbf{x}_i, d_i)= d_i \left[ -\frac{y_i-\mathbf{x}_i^\top\boldsymbol{\beta}(p)}{\sigma(p)} \left(p-I\left(y_i\le\mathbf{x}_i^\top\boldsymbol{\beta}(p)\right) \right) + \log\frac{p\left(1-p\right)}{\sigma(p)} \right] \\
&+\left(1-d_i\right) I\left(y_i\le\mathbf{x}_i^\top\boldsymbol{\beta}(p)\right) \log\left[1 - p \exp\left( (1-p)  \frac{y_i-\mathbf{x}_i^\top\boldsymbol{\beta}(p)}{\sigma(p)} \right) \right] \\
&+ \left(1-d_i\right) \left(1-I\left(y_i\le\mathbf{x}_i^\top\boldsymbol{\beta}(p)\right)\right) \left[ \log \left(1-p\right) - p \frac{y_i-\mathbf{x}_i^\top\boldsymbol{\beta}(p)}{\sigma(p)} \right].
\label{eq:logliklapexpanded}
\end{split}
\end{align}

The maximum likelihood (ML) estimators for the model parameters $\hat{\boldsymbol{\beta}}(p)$ and $\hat{\sigma}(p)$ are defined as the maximizers of the log-likelihood (\ref{eq:logliklapexpanded}), which can be directly maximized using, for example, the gradient search algorithm recently proposed by \citet*{bottai_gradient_2015}. %This algorithm showed remarkable computational speed both in a simulation study and in real-data applications. This maximization algorithm overcomes the limitations of the Nelder-Mead algorithm used in the original paper on Laplace regression \citep[see also][]{bottai_authors_2011}.
Inference on the parameters can be obtained through bootstrapping, as initially proposed in \citet{bottai_laplace_2010}, or following standard asymptotic theory, as shown in  \citet{bottai_command_2013}.

Note that when censoring occurs with zero probability before the survival percentile being estimated, Laplace regression reduces to traditional quantile regression \citep{bottai_laplace_2010}.

Thanks also to the development of a user-friendly command to estimate Laplace regression with Stata \citep{bottai_command_2013}, quantile regression for censored data has been repeatedly employed in the recent years to analyze survival data in epidemiology \citep[see, for example,][]{rizzuto_lifestyle_2012, bellavia_sleep_2014, rahman_relationship_2014}. %For example, quantile regression was employed to evaluate the association between physical activity and the 8th percentile of heart failure--free survival time \citep{rahman_relationship_2014}, or between the 15th percentile of time-to-death and physical activity by categories of sleep duration \citep{bellavia_sleep_2014}.
Moreover, quantile regression for censored data has been proposed as a tool to evaluate additive interaction in survival analysis \citep{bellavia_evaluating_2016}, and to estimate conditional and marginal survival curves \citep{bellavia_adjusted_2015}.

Lastly, we recently proposed to use quantile regression for censored data --- and in particular Laplace regression --- as a flexible and intuitive approach to estimate survival percentiles of age at the event (for example, age at prostate cancer death). This extends the use of this statistical tool, especially in epidemiologic research. In fact, investigators are often more interested in describing the distribution of age at the event for a group of individuals rather than the distribution of time elapsed between some arbitrary baseline event (for example, filling in a questionnaire) and the occurrence of a disease \citepalias{bellavia_using_2015}.

\subsection{Risk and rate advancement periods}

One of the most interesting features of quantile regression is probably that the exposure-outcome association is expressed in the metric of time as PDs. %, which makes PDs very appealing in communicating study results.
Other methods have been proposed in the literature to express the impact of an exposure  on the time of disease onset, such as risk and rate advancement periods (RAP) or `expected years of (disease-free) life lost'.

RAP, in particular, was introduced by \citet*{brenner_risk_1993} to measure the age difference at which exposed subjects reach the same rate/risk as unexposed subjects, assuming a monotonic increase in event rate/risk over age, independence of the outcome of interest from competing risks, and conditional on disease-free survival to some baseline age. In this section we will refer to the rate advancement period only.\footnote{To be consistent with the previous sections, the notation used in this thesis is slightly different from that used in \citetalias{discacciati_interpretation_2015}.} The risk advancement period is defined in a similar fashion and is presented in \citetalias{discacciati_interpretation_2015}.

This measure has been recently given special attention by the CHANCES consortium,\footnote{\href{http://www.chancesfp7.eu}{\texttt{http://www.chancesfp7.eu}}} which is an international pooling project of primary data from cohort studies [including the Cohort of Swedish Men (COSM), see section~\ref{section:cosm}] \citep{boffetta_consortium_2014}.  The quantification of RAP to assess the impact of health-related characteristics on chronic diseases (including cancer) and overall mortality is the principal research aim of published papers \citep{mons_impact_2015, muezzinler_smoking_2015} and research proposals \citetext{Orsini, personal communication}.

\subsubsection{Definition}

Suppose one wants to assess in a cohort study the association between an exposure $e$ and the rate $R$ of a binary event of interest $d$. Let $h(a,e,\mathbf{c})$ be the hazard of the outcome $d$ at baseline age $a$ among those at exposure level $e$ with a fixed covariate vector $\mathbf{c}=(c_1, \ldots, c_k)$. Suppose also that one is interested in two fixed exposure levels in particular, say $e_0$ and $e_1$. For any given baseline age $a_1$, the idea behind the RAP is to seek the earliest age $a_0$ such that:
\begin{equation}
h(a_0, e_0, \mathbf{c}) = h(a_1, e_1, \mathbf{c}).
\label{eq:definitionrap}
\end{equation}

If an $a_0$ satisfying the preceding equation exists, one can define the difference in baseline ages $a_0-a_1$ as the RAP among $e_1$-exposed as compared with $e_0$-exposed, starting from the baseline age $a_1$. The existence of a unique value $a_0$ (and therefore the uniqueness of RAP) is guaranteed by the assumption that the hazard function of $d$ increases monotonically with age, given $e$ and $\mathbf{c}$.

For example, if RAP is equal to 20 years starting from a baseline age of 40 years, then $e_1$-exposed individuals that were 40 years of age at baseline experienced the same rate of the disease than $e_0$-exposed subjects who were 60 years of age at baseline.

\subsubsection{The form of risk and rate advancement periods under PH models}

RAP can be estimated parametrically directly from PH models. In fact, by taking the logarithm of both sides of equation \ref{eq:phmodels}, one obtains:
\begin{equation}
\log\left[h(t|\mathbf{x})\right] = \log \left[ h_0(t) \right] +\mathbf{x}^\top\boldsymbol{\beta} = \log \left[ h_0(t) \right] + \beta_1 e + \beta_2 g(a) + \sum_{i=1}^k \beta_{i+2}c_i,
\label{eq:parametricrap}
\end{equation}
where $g(\cdot)$ is a smooth, monotonically increasing function of baseline age. The usual default transform of age is the identity function $g(a) = a$.

Under the assumptions previously introduced, a group of $e_1$-exposed individuals who have a certain rate at baseline age $a_1$ would be expected to have reached the same rate at age $a_0$, had they been $e_0$-exposed, given that all the other covariates $\mathbf{c}$ are kept constant. Therefore, according to (\ref{eq:parametricrap}),
\begin{align}
\begin{split}
\log \left[ h_0(t) \right] + \beta_1 e_1 + \beta_2 g(a_1) + \sum_{i=1}^k \beta_{i+2}c_i &= \log \left[ h_0(t) \right] + \beta_1 e_0 + \beta_2 g(a_0) + \sum_{i=1}^k \beta_{i+2}c_i \\
\beta_1 e_1 + \beta_2 g(a_1) &=  \beta_1 e_0 + \beta_2 g(a_0). \label{eq:rapsimplified}
\end{split}
\end{align}

Thus, if $e_1-e_0=1$, $\beta_2 \neq 0$, and $g(\cdot)$ is the identity function,
\begin{equation}
\mathrm{RAP} = a_0 - a_1 = \frac{\beta_1}{\beta_2},
\label{eq:para_rap}
\end{equation}
which is the RAP for a 1-unit increase in $e$, expressed in the time scale of $a$ (for example years, if baseline age is expressed in years).

Note that if $g(\cdot)$ is not the identity function, RAP is no longer constant over baseline age and it will depend on $a_1$. For example, if $g(a) = \log(a)$, RAP becomes
\begin{equation}
\mathrm{RAP}(a_1) = a_0 - a_1 = \left[ \exp \left( \frac{\beta_1}{\beta_2} \right) - 1 \right] a_1.
\label{eq:para_log_rap}
\end{equation}

Unfortunately, this measure has been misinterpreted in  studies, commentaries, and editorials published in major epidemiologic and medical journals. Moreover, important aspects regarding RAP estimation have often been overlooked. These aspects are covered in detail in \citetalias{discacciati_interpretation_2015}.


\lab{The Simplex Method}{The Simplex Method}
\label{lab:Simplex}
\objective{
The \emph{Simplex Method} is a straightforward algorithm for finding optimal solutions to optimization problems with linear constraints and cost functions.
Because of its simplicity and applicability, this algorithm has been named one of the most important algorithms invented within the last 100 years.
In this lab we implement a standard Simplex solver for the primal problem. %s that are feasible at the origin.
}

% The algorithm obtains the solution by traversing the edges of the feasible region defined by the constraints.
% The theory of convex optimization guarantees that the optimal point will be found among the vertices of the feasible region, and so a carefully implemented Simplex Algorithm will discover the exact solution in a finite number of steps.

\section*{Standard Form} % ====================================================

The Simplex Algorithm accepts a linear constrained optimization problem, also called a \emph{linear program}, in the form given below:

\begin{align*}
\text{minimize}\qquad &\c\trp\x \\
\text{subject to}\qquad & A\x \preceq \b \\
 &\x \succeq \0
\end{align*}

Note that any linear program can be converted to standard form, so there is no loss of generality in restricting our attention to this particular formulation.

Such an optimization problem defines a region in space called the \emph{feasible region}, the set of points satisfying the constraints.
Because the constraints are all linear, the feasible region forms a geometric object called a \emph{polytope}, having flat faces and edges (see Figure \ref{fig:polytope}).
The Simplex Algorithm jumps among the vertices of the feasible region searching for an optimal point.
It does this by moving along the edges of the feasible region in such a way that the objective function is always increased after each move.

\begin{figure}[H]
\captionsetup[subfigure]{justification=centering}
\centering
\begin{subfigure}{.5\textwidth} % 2-d feasible polytope.
    \centering
    \includegraphics[width=\linewidth]{figures/feasiblePolytope.pdf}
    \caption{The feasible region for a linear program with 2-dimensional constraints.}
\end{subfigure}%
\begin{subfigure}{.5\textwidth} % 3-d feasible polytope.
    \begin{center}
    \begin{tikzpicture}[dot/.style={circle,fill=blue,minimum size=3pt,inner sep=0pt, outer sep=-1pt}, >=stealth']

    \draw[blue!10!, fill=blue!5!](3,1)--(1.5,2.3)--(1.75,1.3)--cycle;
    \draw[blue!25!, fill = blue!15!](3,1)--(1.75,1.3)--(2.3,-1)--cycle;
    \draw[blue!55!, fill = blue!40!](1.75,1.3)--(2.3,-1)--(.8,-1)--cycle;
    \draw[blue!80!, fill = blue!65!](.8,-1)--(-.05,-.2)--(.25,.6)--(1.22,.06)--cycle;
    \draw[blue!85!, fill = blue!73!](-.05, -.2)--(-.3,0)--(.1, 1.65)--(.25, .6)--cycle;
    \draw[blue!65!, fill = blue!50!](.1,1.7)--(.25,.6)--(1.22,.07)--(1.75,1.3)--cycle;
    \draw[blue!40!, fill = blue!15!](.1,1.7)--(1.75,1.3)--(1.5,2.3)--cycle;

    \draw[-,thick](-.3,0)--(.1,1.7)--(1.5, 2.3)--(3, 1)--(2.3,-1)--(.8,-1)--cycle;

    \draw[-,thick](.1,1.7)--(3,1);
    \draw[-,thick](1.5, 2.3)--(2.3,-1);
    \draw[-,thick](.8,-1)--(1.74,1.3);
    \draw[-,thick](.1,1.7)--(.25,.6);
    \draw[-,thick](1.24,.07)--(.25,.6);
    \draw[-,thick](-.05,-.24)--(.25,.6);

    \draw[->](.37,.63)--(.22,1.61);
    \draw[->](.31,1.55)--(1.63,1.23);
    \draw[->](.75,-.85)--(1.12,.05);
    \draw[->](1.05,.05)--(.25,.48);
    \draw[->](1.83,1.35)--(1.65,2.1);

    \node[draw=none](x*)at(1.8,2.45){$\x^*$};

    \end{tikzpicture}
    \end{center}
    \caption{The feasible region for a linear program with 3-dimensional constraints.}
\end{subfigure}
\caption{If an optimal point exists, it is one of the vertices of the polyhedron.
The simplex algorithm searches for optimal points by moving between adjacent vertices in a direction that increases the value of the objective function until it finds an optimal vertex.}
\label{fig:polytope}
\end{figure}

% \begin{figure}[htb] % 3-d feasible polytope.
% \end{figure}

% % TODO: subfigure for 3-d polytope from book.

Implementing the Simplex Algorithm is straightforward, provided one carefully follows the procedure.
We will break the algorithm into several small steps, and write a function to perform each one.
To become familiar with the execution of the Simplex algorithm, it is helpful to work several examples by hand.

\section*{The Simplex Solver} % ===============================================

Our program will be more lengthy than many other lab exercises and will consist of a collection of functions working together to produce a final result.
It is important to clearly define the task of each function and how all the functions will work together.
If this program is written haphazardly, it will be much longer and more difficult to read than it needs to be.
We will walk you through the steps of implementing the Simplex Algorithm as a Python class.
% Since the Simplex Algorithm assumes that all the variables are non-negative, we do not need any special logic for it.
% what is this previous statement saying? What 'special logic' would you need if the variables were negative?

For demonstration purposes, we will use the following linear program.
\begin{align*}
\text{minimize}\qquad & -3x_0 - 2x_1 \\
\text{subject to}\qquad
& x_0 - x_1 \leq 2 \\
& 3x_0 + x_1 \leq 5 \\
& 4x_0 + 3x_1 \leq 7 \\
& x_0, x_1 \geq 0.
\end{align*}

\subsection*{Accepting a Linear Program} % ------------------------------------

Our first task is to determine if we can even use the Simplex algorithm.
Assuming that the problem is presented to us in standard form, we need to check that the feasible region includes the origin.  For now, we only check for feasibility at the origin. A more robust solver sets up the auxiliary problem and solves it to find a starting point if the origin is infeasible.

\begin{problem} % Check feasibility at the origin.
Write a class that accepts the arrays $\c$, $A$, and $\b$ of a linear optimization problem in standard form.
In the constructor, check that the system is feasible at the origin.
That is, check that $A\x \preceq \b$ when $\x = \0$. Raise a \li{ValueError} if the problem is not feasible at the origin. \label{prob:initsolver}
\end{problem}

\subsection*{Adding Slack Variables} % ----------------------------------------

The next step is to convert the inequality constraints $A\x \preceq \b$ into equality constraints by introducing a slack variable for each constraint equation.
If the constraint matrix $A$ is an $m \times n$ matrix, then there are $m$ slack variables, one for each row of $A$.
Grouping all of the slack variables into a vector $\w$ of length $m$, the constraints now take the form $A\x + \w = \b$.
In our example, we have \[\w = \left[\begin{array}{c}x_2\\x_3 \\x_4\end{array}\right]\]

% TODO: change the representation of the slack variables to match the book.
When adding slack variables, it is useful to represent all of your variables, both the original primal variables and the additional slack variables, in a convenient manner.
One effective way is to refer to a variable by its subscript.
For example, we can use the integers $0$ through $n-1$ to refer to the original (non-slack) variables $x_0$ through $x_{n-1}$, and we can use the integers $n$ through $n+m-1$ to track the slack variables (where the slack variable corresponding to the $i$th row of the constraint matrix is represented by the index $n+i-1$).

We also need some way to track which variables are \emph{independent} (non-zero) and which variables are \emph{dependent} (those that have value $0$). This can be done using the objective function. At anytime during the optimization process, the non-zero variables in the objective function are \emph{independent} and all other variables are \emph{dependent}.

%A useful representation for the variables is a Python list (or NumPy array), where the elements of the list are integers.
%Since we know how many dependent variables we have ($m$), we can partition the list so that all the dependent variables are kept in the first $m$ locations, and all the independent variables are stored at the end of the list.
%The ordering of this list is important.
%In particular, if $i \leq m$, the $i$th element of the list represents the dependent variable corresponding to the $i$th row of $A$.
%Henceforth we will refer to this list as the \emph{index list}.

%Initially, the dependent variables are simply the slack variables, and their values correspond to the values of %the vector $\b$.
%In our example, we have 2 primal variables $x_0$ and $x_1$, and we must add 3 slack variables.
%Thus, we instantiate the following index list:

%\begin{lstlisting}
%>>> L = [2, 3, 4, 0, 1]
%\end{lstlisting}

%Notice how the first $3$ entries of the index list are $2, 3, 4$, the indices representing the slack variables.
%This reflects the fact that the dependent variables at this point are exactly the slack variables.

%As the Simplex Algorithm progresses, however, the dependent variables change, and it will be necessary to swap
%elements in our index list.
%For example, suppose the variable represented by the index $4$ becomes independent, while the variable %represented by index $0$ becomes dependent.
%In this case we swap these two entries in the index list.

%\begin{lstlisting}
%>>> L[2], L[3] = L[3], L[2]
%>>> L
%[2, 3, 0, 4, 1]
%\end{lstlisting}

%Now our index list tells us that the current dependent variables $2, 3, 0$.

%\begin{problem} % Slack variables. % TODO: this problem is worthless...
%Design and implement a way to store and track all of the dependent and independent variables.

%Hint: Using integers that represent the index of each variable is useful for Problem \ref{prob:blands}.
%\label{prob:slackvars}
%\end{problem}

\subsection*{Creating a Dictionary} % --------------------------------------------

After we have determined that our program is feasible, we need to create the \emph{dictionary} (sometimes called the \emph{tableau}), a matrix to track the state of the algorithm.
%Remember that your dictionary will need to include in some way the slack variables that you created in Problem \ref{prob:slackvars}.

There are many different ways to build your dictionary.
One way is to mimic the dictionary that is often used when performing the Simplex Algorithm by hand. To do this we will set the corresponding dependent variable equations to 0. For example, if $x_5$ were a dependent variable we would expect to see a -1 in the column that represents $x_5$.
Define \[\bar{A} = \left[\begin{array}{cc} A & I_m \end{array}\right],\]
where $I_m$ is the $m \times m$ identity matrix we will use to represent our slack variables, and define
\[\bar{\c} = \left[\begin{array}{c}\c\\ \0\end{array}\right].\]
That is, $\bar{\c} \in \mathbb{R}^{n+m}$ such that the first $n$ entries are $\c$ and the final $m$ entries are zeros.
Then the initial dictionary has the form
\begin{equation}
D =
\left[\begin{array}{ccc}
0  & \bar{\c}\trp \\
\b &  -\bar{A}
\end{array}\right]
\label{eqn:hand_tab}
\end{equation}

The columns of the dictionary correspond to each of the variables (both primal and slack), and the rows of the dictionary correspond to the dependent variables.
%Using the convention introduced above of representing the variables by indices in the index list, we have the following correspondence:
%\[
%\text{column } i \Leftrightarrow \text{index } i-2, \qquad i = 2, 3, \ldots, n+m+1,
%\]
%and
%\[
%\text{row } j \Leftrightarrow L_{j-1}, \qquad j = 2, 3, \ldots, m+1,
%\]
%where $L_{j-1}$ refers to the $(j-1)$th entry of the index list.

%For our example problem, the initial index list is
%\[
%L = (2, 3, 4, 0, 1),
%\]
For our example the initial dictionary is
\begin{equation*}
D = \begin{bmatrix}
    0 & -3 & -2 & 0 & 0 & 0\\
    2 & -1 & 1 & -1 & 0 & 0\\
    5 & -3 & -1 & 0 & -1 & 0\\
    7 & -4 & -3 & 0 & 0 & -1
    \end{bmatrix}.
\end{equation*}
%The third column corresponds to index $1$, and the fourth row corresponds to index $4$, since this is the
%third entry of the index list.

The advantage of using this kind of dictionary is that it is easy to check the progress of your algorithm by hand.
%The disadvantage is that pivot operations require careful bookkeeping to track the variables and constraints.

% This dictionary is less intuitive, and I think could lead to more confusion.
\begin{comment}
We can also use a dictionary of the format:
\begin{equation}
T = \begin{bmatrix}
    0 & \c\trp  & 0 \\
    \0 & I_n & \0\\
    \b & -A  & \0
\end{bmatrix}.
\label{eqn:matrix_tab}
\end{equation}
Here, $T$ is a square matrix of size $(n+m+1) \times (n+m+1)$.
The advantage of this form of the dictionary is that all the pivot bookkeeping is built into the matrix.
For our example problem, the initial dictionary of this form is
\begin{equation}
T = \begin{bmatrix}
        0 & 3 & 2 & 0 & 0 & 0 \\
        0 & 1 & 0 & 0 & 0 & 0 \\
        0 & 0 & 1 & 0 & 0 & 0 \\
        2 &-1 & 1 & 0 & 0 & 0 \\
        5 &-3 &-1 & 0 & 0 & 0 \\
        7 &-4 &-3 & 0 & 0 & 0
\end{bmatrix}.
\label{eqn:matrix_inittab}
\end{equation}
\end{comment}

\begin{problem} % Initialize the dictionary.
Add a method to your Simplex solver that takes in arrays c, A, and b to create the initial dictionary (D) as a NumPy array.
\label{prob:makedictionary}
\end{problem}

\subsection*{Pivoting} % ------------------------------------------------------

Pivoting is the mechanism that really makes Simplex useful.
Pivoting refers to the act of swapping dependent and independent variables, and transforming the dictionary appropriately.
This has the effect of moving from one vertex of the feasible polytope to another vertex in a way that increases the value of the objective function.
Depending on how you store your variables, you may need to modify a few different parts of your solver to reflect this swapping.

When initiating a pivot, you need to determine which variables will be swapped.
In the dictionary representation, you first find a specific element on which to pivot, and the row and column that contain the pivot element correspond to the variables that need to be swapped.
Row operations are then performed on the dictionary so that the pivot column becomes a negative elementary vector.

Let's break it down, starting with the pivot selection.
We need to use some care when choosing the pivot element.
To find the pivot column, search from left to right along the top row of the dictionary (ignoring the first column), and stop once you encounter the first negative value.
The index corresponding to this column will be designated the \emph{entering index}, since after the full pivot operation, it will enter
the basis and become a dependent variable.

Using our initial dictionary $D$ in the example, we stop at the second column:
\[ D = \left[ \:
\begin{array}{*{7}{c}}
\cline{2-2}
0 & \multicolumn{1}{|c}{-3} & \multicolumn{1}{|c}{-2} & 0 & 0 & 0\\
2 & \multicolumn{1}{|c}{-1} & \multicolumn{1}{|c}{1} & -1 & 0 & 0\\
5 & \multicolumn{1}{|c}{-3} & \multicolumn{1}{|c}{-1} & 0 & -1 & 0\\
7 & \multicolumn{1}{|c}{-4} & \multicolumn{1}{|c}{-3} & 0 & 0 & -1\\
\cline{2-2}
\end{array}
\right] \]
We now know that our pivot element will be found in the second column.
The entering index is thus $1$.

Next, we select the pivot element from among the negative entries in the pivot column (ignoring the entry in the first row).
\emph{If all entries in the pivot column are non-negative, the problem is unbounded and has no solution.}
In this case, the algorithm should terminate.
Otherwise, assuming our pivot column is the $j$th column of the dictionary and that the negative entries of this column are
$D_{i_1, j}, D_{i_2, j}, \ldots, D_{i_k, j}$, we calculate the ratios
\[
\frac{-D_{i_1,0}}{D_{i_1,j}}, \frac{-D_{i_2,0}}{D_{i_2,j}}, \ldots, \frac{-D_{i_k,0}}{D_{i_k,j}},
\]
and we choose our pivot element to be one that minimizes this ratio.
If multiple entries minimize the ratio, then we utilize \emph{Bland's Rule}, which instructs us to choose the entry in the row corresponding to the smallest index (obeying this rule is important, as it prevents the possibility of the algorithm cycling back on itself infinitely).
The index corresponding to the pivot row is designated as the \emph{leaving index}, since after the full pivot operation, it will leave the basis and become a independent variable.

In our example, we see that all entries in the pivot column (ignoring the entry in the first row, of course) are negative, and hence they are all potential choices for the pivot element.
We then calculate the ratios, and obtain
\[
\frac{-2}{-1} = 2,\quad \frac{-5}{-3} = 1.66...,\quad \frac{-7}{-4} = 1.75.
\]
We see that the entry in the third row minimizes these ratios.
Hence, the element in the second column (index 1), third row (index 2) is our designated
pivot element.

\[ D = \left[ \:
\begin{array}{*{7}{c}}

0 & -3 & -2 & 0 & 0 & 0\\
2 & -1 & 1 & -1 & 0 & 0\\\cline{2-2}
5 & \multicolumn{1}{|c}{-3} & \multicolumn{1}{|c}{-1} & 0 & -1 & 0\\\cline{2-2}
7 & -4 & -3 & 0 & 0 & -1\\
\end{array}
\right] \]

\begin{comment}
If we are using the dictionary representation in equation \ref{eqn:matrix_tab}, pivot operations are reduced to a simple matrix equation:
\[T = T + T_m \otimes T_n,\]
where $T_m$ is the column corresponding to the variable entering the basis and $T_n$ is a normalized vector corresponding to the variable leaving the basis.
The result of the equation is the new dictionary.

For example, for the initial dictionary, \ref{eqn:matrix_inittab}, we will demonstrate the first pivot operation.
We can do the entire pivot with a single outer product.
The first pivot should occur with $x_1$ leaving and $x_4$ entering.
In other words, we want to pivot at row $i = 4$ and column $j = 1$ in the dictionary (the indices are offset by one because of the objective function and the row of constraints).

The row corresponding to $x_4$ is
\[
\begin{bmatrix} 5 &-3 &-1 & 0 & 0 & 0\end{bmatrix}.
\]
This represents the equation
\[
x_4 = 5 - 3x_1 - x_2.
\]
Our eventual goal is to solve for $x_1$ and substitute into the remaining rows of the dictionary.
A simple method to accomplish this is to rewrite the equation so that we have zero on the left-hand side:
\[
0 = 5 - 3x_1 - x_2 - x_4.
\]
Now, we can normalize this equation so that the coefficient of $x_1$ is $-1$.
This is always accomplished by dividing the equation by the negative of the coefficient of $x_1$:
\begin{equation}
0 = \frac{5}{3} - x_1 - \frac{1}{3}x_2 - \frac{1}{3}x_4.
\label{eq:zero-equation}
\end{equation}
This is represented by the vector
\[
\begin{bmatrix} 5/3 & -1 & -1/3 & 0 & -1/3 & 0\end{bmatrix}.
\]
Since this left-hand side is zero, I can add any scalar multiple of this equation to any of the equations for $x_i$ and still have an equation for $x_i$.
For example, the equation for $x_5$ is
\[
x_5 = 7 - 4x_1 - 3x_2.
\]
Thus, I can add $-4$ times \eqref{eq:zero-equation} to this equation without changing the left-hand side:
\[ x_5 = 7 - 4x_1 - 3x_2 = 7 - 4x_1 - 3x_2 + -4\left(\frac{5}{3} - x_1 - \frac{1}{3}x_2 - \frac{1}{3}x_4\right) = \frac{1}{3} - \frac{5}{3}x_2 + \frac{4}{3} x_4.
\]
Notice that we end up with an equation that does not include $x_1$ and now has $x_4$, just like we wanted.
In fact, this works in all of our equations, including those for the objective function and even for $x_1$!
Since the coefficient of $x_1$ in \eqref{eq:zero-equation} is $-1$, when we scale it by the coefficient of $x_1$ in any particular row, the $x_1$ cancels out.
\[
T = T + \begin{bmatrix}3 \\ 1 \\ 0 \\ -1 \\ -3 \\ -4\end{bmatrix}\begin{bmatrix} 5/3 & -1 & -1/3 & 0 & -1/3 & 0\end{bmatrix}.
\]
The column vector is just the second column of $T$, which is the column containing the coefficients of $x_1$ in each row.
When we compute this sum, we obtain the dictionary.
\[
T = \begin{bmatrix}
        5 &  0 & 1 & 0 & -1 & 0 \\
        5/3 & 0 &-1/3 & 0 &-1/3 & 0 \\
        0 & 0 & 1 & 0 & 0 & 0 \\
        1/3 & 0 & 4/3 & 0 & 1/3 & 0 \\
        0 & 0 & 0 & 0 & 1 & 0 \\
        1/3 & 0 & -5/3 & 0 & 4/3 & 0
\end{bmatrix}.
\]
\end{comment}
\begin{problem}
Write a method that will determine the pivot row and pivot column according to Bland's Rule.
% \begin{comment}
\begin{definition}[Bland's Rule]
Choose the independent variable with the smallest index that has a negative coefficient in the objective function
as the leaving variable.
Choose the dependent variable with the smallest index among all the binding dependent variables.
\end{definition}

Bland's Rule is important in avoiding cycles when performing pivots.
This rule guarantees that a feasible Simplex problem will terminate in a finite number of pivots. \emph{Hint:} Avoid dividing by zero.
% \end{comment}
\label{prob:blands}
\end{problem}

%The next step is to swap the entering and leaving indices in our index list.
%In the example, we determined above that these indices are $0$ and $3$.
%We swap these two elements in our index list,
%and the updated index list is now
%\[
%L = (2, 0, 4, 3, 1),
%\]
%so the dependent variables are now given by the indices $2, 0, 4$.

Finally, we perform row operations on our dictionary in the following way: divide the pivot row by the negative value of the pivot entry.
Then use the pivot row to zero out all entries in the pivot column above and below the pivot entry.
In our example, we first divide the pivot row by -3, and then zero out the two entries above the pivot element and the single entry below it:
\begin{align*}
\begin{bmatrix}
    0 & -3 & -2 & 0 & 0 & 0\\
    2 & -1 & 1 & -1 & 0 & 0\\
    5 & -3 & -1 & 0 & -1 & 0\\
    7 & -4 & -3 & 0 & 0 & -1
    \end{bmatrix} &\rightarrow
\begin{bmatrix}
    0 & -3 & -2 & 0 & 0 & 0\\
    2 & -1 & 1 & -1 & 0 & 0\\
    5/3 & -1 & -1/3 & 0 & -1/3 & 0\\
    7 & -4 & -3 & 0 & 0 & -1
    \end{bmatrix}\rightarrow\\
\begin{bmatrix}
    -5 & 0 & -1 & 0 & 1 & 0\\
    2 & -1 & 1 & -1 & 0 & 0\\
    5/3 & -1 & -1/3 & 0 & -1/3 & 0\\
    7 & -4 & -3 & 0 & 0 & -1
    \end{bmatrix} &\rightarrow
\begin{bmatrix}
    -5 & 0 & -1 & 0 & 1 & 0\\
    1/3 & 0 & -4/3 & 1 & -1/3 & 0\\
    5/3 & -1 & -1/3 & 0 & -1/3 & 0\\
    7 & -4 & -3 & 0 & 0 & -1
    \end{bmatrix}\rightarrow\\
\begin{bmatrix}
    -5 & 0 & -1 & 0 & 1 & 0\\
    1/3 & 0 & 4/3 & -1 & 1/3 & 0\\
    5/3 & -1 & -1/3 & 0 & -1/3 & 0\\
    1/3 & 0 & -5/3 & 0 & 4/3 & -1
    \end{bmatrix}.
\end{align*}
The result of these row operations is our updated dictionary, and the pivot operation is complete.

\begin{problem} % Pivoting
Add a method to your solver that checks for unboundedness and performs a single pivot operation from start to completion.
If the problem is unbounded, raise a \li{ValueError}.
\end{problem}

\vspace{2mm}

\subsection*{Termination and Reading the Dictionary} % ---------------------------

Up to this point, our algorithm accepts a linear program, adds slack variables, and creates the initial dictionary.
After carrying out these initial steps, it then performs the pivoting operation iteratively until the optimal point is found.
But how do we determine when the optimal point is found? The answer is to look at the top row of the dictionary, which represents the objective function.
More specifically, before each pivoting operation, check whether all of the entries in the top row of the dictionary (ignoring the entry in the first column) are nonnegative.
If this is the case, then we have found an optimal solution, and so we terminate the algorithm.

The final step is to report the solution.
The ending state of the dictionary and index list tells us everything we need to know.
The minimal value attained by the objective function is found in the upper leftmost entry of the dictionary.
The dependent variables all have the value $0$ in the objective function or first row of our dictionary array. The independent variables have values given by the first column of the dictionary.
Specifically, the independent variable whose index is located at the $i$th entry of the index list has the value $T_{i+1, 0}$.

In our example, suppose that our algorithm terminates with the dictionary and index list in the following state:
\[
D = \begin{bmatrix}
-5.2 & 0 & 0 & 0 & 0.2 & 0.6\\
0.6 & 0 & 0 & -1 & 1.4 & -0.8\\
1.6 & -1 & 0 & 0 & -0.6 & 0.2\\
0.2 & 0 & -1 & 0 & 0.8 & -0.6\\
\end{bmatrix}
\]
%\[
%L = (2, 0, 1, 3, 4).
%\]
Then the minimal value of the objective function is $-5.2$.
The independent variables have indices $4, 5$ and have the value $0$.
The dependent variables have indices $3, 1,$ and $2$, and have values $.6, 1.6$, and $.2$, respectively.
In the notation of the original problem statement, the solution is given by
\begin{align*}
x_0 &= 1.6\\
x_1 &= .2.
\end{align*}

% SimplexSolver.solve()
\begin{problem}
Write an additional method in your solver called \li{solve()} that obtains the optimal solution, then returns the minimal value, the dependent variables, and the independent variables.
The dependent and independent variables should be represented as two dictionaries that map the index of the variable to its corresponding value.

For our example, we would return the tuple

\li{(-5.2, \{0: 1.6, 1: .2, 2: .6\}, \{3: 0, 4: 0\})}.
%The correct format of this tuple is critical, as this tuple of information will be used judge whether or not your solver works!
\end{problem}

\vspace{5mm}

At this point, you should have a Simplex solver that is ready to use.
The following code demonstrates how your solver is expected to behave:

\vspace{5mm}

\begin{lstlisting}
>>> import SimplexSolver

# Initialize objective function and constraints.
>>> c = np.array([-3., -2.])
>>> b = np.array([2., 5, 7])
>>> A = np.array([[1., -1], [3, 1], [4, 3]])

# Instantiate the simplex solver, then solve the problem.
>>> solver = SimplexSolver(c, A, b)
>>> sol = solver.solve()
>>> print(sol)
(-5.2,
 {0: 1.6, 1: 0.2, 2: 0.6},
 {3: 0, 4: 0})
\end{lstlisting}

If the linear program were infeasible at the origin or unbounded, we would expect the solver to alert the user by raising an error.

Note that this simplex solver is \emph{not} fully operational.
It can't handle the case of infeasibility at the origin.
This can be fixed by adding methods to your class that solve the \emph{auxiliary problem}, that of finding an initial feasible dictionary when the problem is not feasible at the origin.
Solving the auxiliary problem involves pivoting operations identical to those you have already implemented, so adding this functionality
is not overly difficult.

\section*{The Product Mix Problem}
We now use our Simplex implementation to solve the \emph{product mix problem}, which in its dependent form can be expressed as a simple linear program.
Suppose that a manufacturer makes $n$ products using $m$ different resources (labor, raw materials, machine time available, etc).
The $i$th product is sold at a unit price $p_i$, and there are at most $m_j$ units
of the $j$th resource available.
Additionally, each unit of the $i$th product requires $a_{j,i}$ units of resource $j$.
Given that the demand for product $i$ is $d_i$ units per a certain time period, how do we choose the optimal amount
of each product to manufacture in that time period so as to maximize revenue, while not exceeding the available resources?

Let  $x_1, x_2, \ldots, x_n$ denote the amount of each product to be manufactured.
The sale of product $i$ brings revenue in the amount of $p_ix_i$.
Therefore our objective function, the profit, is given by
\[
\sum_{i=1}^n p_ix_i.
\]
Additionally, the manufacture of product $i$ requires $a_{j,i}x_i$ units of resource $j$.
Thus we have the resource constraints
\[
\sum_{i=1}^n a_{j,i}x_i \leq m_j  \text{ for } j = 1, 2, \ldots, m.
\]

Finally, we have the demand constraints which tell us not to exceed the demand for the products:
\[
x_i \leq d_i \text{ for } i = 1, 2, \ldots, n
\]

The variables $x_i$ are constrained to be nonnegative, of course.
We therefore have a linear program in the appropriate form that is feasible at the origin.
It is a simple task to solve the problem using our Simplex solver.

\begin{problem} % Product mix problem.
Solve the product mix problem for the data contained in the file \li{productMix.npz}.
In this problem, there are 4 products and 3 resources.
The archive file, which you can load using the function
\li{np.load}, contains a dictionary of arrays.
The array with key \li{'A'} gives the resource coefficients $a_{i,j}$ (i.e. the $(i,j)$-th entry of the array give $a_{i,j}$).
The array with key \li{'p'} gives the unit prices $p_i$.
The array with key \li{'m'} gives the available resource
units $m_j$.
The array with key \li{'d'} gives the demand constraints $d_i$.

Report the number of units that should be produced for each product. \emph{Hint:} Because this is a maximization problem and your solver works with minimizations, you will need to change the sign of the array c.
\end{problem}

\begin{comment}
\section*{Auxiliary Problems} % ===============================================

When one of the entries of $\b$ is negative, we need to run an auxiliary problem to find a feasible point.
Try adding $x_0$ as the last variable.
That way you just need to add a single row and column to your current dictionary $T$.
You can check that subtracting $x_0$ from each of the constraints is the same as adding $x_0$ to each of the expressions for the slack variables.
Since we also need write $x_0$ in terms of itself ($x_0 = x_0$), this is equivalent to setting the last column equal to 1 for all the rows corresponding to slack variables, plus one new row.
We also need to change the objective function to $-x_0$.
Let's let $N$ be the matrix for the auxiliary problem.
Then we can construct it from $T$ using the code

\begin{lstlisting}
>>> N = zeros((s+1,s+1))
>>> N[0:s,0:s] = T
>>> N[n:s+1,s] = 1
>>> N[0,s] = -1
\end{lstlisting}

Before you run simplex on this auxiliary dictionary, make sure you do a pivot on the last column and the row corresponding to the smallest entry of $b$.
Check that the objective function value is 0 when simplex finishes running.
If not, your initial problem is infeasible.
If the problem is feasible, get the system of equations from $N$ and put them back into $T$, leaving off the last row and column of $N$ (for $x_0$) and the first row (corresponding to the objective function).

\begin{lstlisting}
T[1:s,0:s] = N[1:s,0:s]
\end{lstlisting}

The last thing to do is to insert the previous objective function.
However, we need to re-write it in terms of the current independent variables.
Fortunately, $T$ currently contains all of the variables written in terms of the independent variables.
You can check (mathematically, or however you want to satisfy yourself) that

\begin{lstlisting}
T[0,0:s] = np.dot(T[0,0:s], T)
\end{lstlisting}

will put the objective function into the first row, now written in terms of the new independent variables.
\end{comment}

% TODO: Dual problem and duality theory.

\section*{Beyond Simplex} % ===================================================

The \emph{Computing in Science and Engineering} journal listed Simplex as one of the top ten algorithms of the twentieth century \cite{Nash2000}.
However, like any other algorithm, Simplex has its drawbacks.

In 1972, Victor Klee and George Minty Cube published a paper with several examples of worst-case polytopes for the Simplex algorithm \cite{Klee1972}.
In their paper, they give several examples of polytopes that the Simplex algorithm struggles to solve.

Consider the following linear program from Klee and Minty.
\begin{align*}
\text{max } & 2^{n-1}x_1 & + & 2^{n-2}x_2  & + & \cdots & + & 2x_{n-1} & + & x_n\\
\text{subject to } & x_1 &  &  &  &  &  &  &  &\leq 5\\
& 4x_1 & + & x_2 &  &  &  &  &  &\leq 25\\
& 8x_1 & + & 4x_2 & + & x_3 &  &  &  &\leq 125\\
& \vdots & &      &   &     &  &  &  &\vdots\\
& 2^n x_1 & + & 2^{n-1} x_2 & + & \cdots & + & 4x_{n-1} & + x_n &\leq 5\\
\end{align*}

% When $n = 3$, we have the initial dictionary
% \begin*{equation*}
% \begin{bmatrix}
% 0 & 4 & 2 & 1 & 0 & 0 & 0\\
% 0 & 1 & 0 & 0 & 0 & 0 & 0\\
% 0 & 0 & 1 & 0 & 0 & 0 & 0\\
% 0 & 0 & 0 & 1 & 0 & 0 & 0\\
% 5 & -1 & 0 & 0 & 0 & 0 & 0\\
% 25 & -4 & -1 & 0 & 0 & 0 & 0\\
% 125 & -8 & -4 & -1 & 0 & 0 & 0\\
% \end{bmatrix}
% \end{equation*}
%
% After the first pivot with $x_1$ leaving and $s_1$ entering, we have the dictionary
%
% \begin{equation*}
% \begin{bmatrix}
% 20 & 0 & 2 & 1 & -4 & 0 & 0\\
% 5 & 0 & 0 & 0 & -1 & 0 & 0\\
% 0 & 0 & 1 & 0 & 0 & 0 & 0\\
% 0 & 0 & 0 & 1 & 0 & 0 & 0\\
% 0 & 0 & 0 & 0 & 1 & 0 & 0\\
% 5 & 0 & -1 & 0 & 4 & 0 & 0\\
% 85 & 0 & -4 & -1 & 8 & 0 & 0\\
% \end{bmatrix}
% \end{equation*}
%
% \begin{problem}
% What is the final dictionary for this Klee-Minty example with $n=3$?
% How many iterations does it take to arrive at the final dictionary?
% \end{problem}
%
% \begin{problem}
% Using problem 1 as a guide, guess the optimum value of the Klee-Minty example with $n=20$.
% Then find the maximum value for the Klee-Minty example with $n=20$.
% How many iterations does it take to arrive at the final dictionary?
% How long does the program take to run for only $20$ variables?
% \end{problem}

Klee and Minty show that for this example, the worst case scenario has exponential time complexity.
With only $n$ constraints and $n$ variables, the simplex algorithm goes through $2^n$ iterations.
This is because there are $2^n$ extreme points, and when starting at the point $x=0$, the simplex algorithm goes through all of the extreme points before reaching the optimal point $(0,0,\dots, 0, 5^n)$.
Other algorithms, such as interior point methods, solve this problem much faster because they are not constrained to follow the edges.


%!TEX root = ../OGUSAdoc.tex

The previous chapters derive all the equations necessary to solve for the steady-state and nonsteady-state equilibria of this model. However, because labor productivity is growing at rate $g_y$ as can be seen in the firms' production function \eqref{EqFirmsCESprodfun} and the population is growing at rate $\tilde{g}_{n,t}$ as defined in \eqref{EqPopGrowthTil}, the model is not stationary. Different endogenous variables of the model are growing at different rates. We have already specified three potential budget closure rules \eqref{EqUnbalGBCclosure_Gt}, \eqref{EqUnbalGBCclosure_TRt}, and \eqref{EqUnbalGBCclosure_TRGt} using some combination of government spending $G_t$ and transfers $TR_t$ that stationarize the debt-to-GDP ratio.

Table \ref{TabStnrzStatVars} lists the definitions of stationary versions of these endogenous variables. Variables with a ``$\:\,\hat{}\,\:$'' signify stationary variables. The first column of variables are growing at the productivity growth rate $g_y$. These variables are most closely associated with individual variables. The second column of variables are growing at the population growth rate $\tilde{g}_{n,t}$. These variables are most closely associated with population values. The third column of variables are growing at both the productivity growth rate $g_y$ and the population growth rate $\tilde{g}_{n,t}$. These variables are most closely associated with aggregate variables. The last column shows that the interest rate $r_t$ and household labor supply $n_{j,s,t}$ are already stationary.

\begin{table}[htbp] \centering \captionsetup{width=3.5in}
\caption{\label{TabStnrzStatVars}\textbf{Stationary variable definitions}}
  \begin{threeparttable}
  \begin{tabular}{>{\small}c >{\small}c >{\small}c |>{\small}c}
    \hline\hline
    \multicolumn{3}{c}{Sources of growth} & Not \\
    & & & \\[-4mm]
    $e^{g_y t}$ & $\tilde{N}_t$ & $e^{g_y t}\tilde{N}_t$ & growing\tnote{a} \\
    \hline
    & & \\[-4mm]
    $\hat{c}_{j,s,t}\equiv\frac{c_{j,s,t}}{e^{g_y t}}$ & $\hat{\omega}_{s,t}\equiv\frac{\omega_{s,t}}{\tilde{N}_t}$ & $\hat{Y}_t\equiv\frac{Y_t}{e^{g_y t}\tilde{N}_t}$ & $n_{j,s,t}$ \\[2mm]
    $\hat{b}_{j,s,t}\equiv\frac{b_{j,s,t}}{e^{g_y t}}$ & $\hat{L}_t\equiv\frac{L_t}{\tilde{N}_t}$ & $\hat{K}_t\equiv\frac{K_t}{e^{g_y t}\tilde{N}_t}$ & $r_t$ \\[2mm]
    $\hat{w}_t\equiv\frac{w_t}{e^{g_y t}}$ &  & $\hat{BQ}_{j,t}\equiv\frac{BQ_{j,t}}{e^{g_y t}\tilde{N}_t}$ &  \\[2mm]
    $\hat{y}_{j,s,t}\equiv\frac{y_{j,s,t}}{e^{g_y t}}$ &  & $\hat{C}_t\equiv \frac{C_t}{e^{g_y t}\tilde{N}_t}$  &  \\[2mm]
    $\hat{T}_{s,t}\equiv\frac{T_{j,s,t}}{e^{g_y t}}$ &  & $\hat{TR}_t\equiv\frac{TR_t}{e^{g_y t}\tilde{N}_t}$ &  \\[2mm]
    \hline\hline
  \end{tabular}
  \begin{tablenotes}
    \scriptsize{\item[a]The interest rate $r_t$ in \eqref{EqFirmFOC_K} is already stationary because $Y_t$ and $K_t$ grow at the same rate. Household labor supply $n_{j,s,t}\in[0,\tilde{l}]$ is stationary.}
  \end{tablenotes}
  \end{threeparttable}
\end{table}

The usual definition of equilibrium would be allocations and prices such that households optimize \eqref{EqHHeul_n}, \eqref{EqHHeul_b}, and \eqref{EqHHeul_bS}, firms optimize \eqref{EqFirmFOC_L} and \eqref{EqFirmFOC_K}, and markets clear \eqref{EqMarkClrLab} and \eqref{EqMarkClrCap}, and \eqref{EqMarkClrBQ}. In this chapter, we show how to stationarize each of these characterizing equations so that we can use our fixed point methods described in Sections \ref{SecEqlbSSsoln} and \ref{SecEqlbNSSsoln} to solve for the equilibria in Definitions \ref{DefSSEql} and \ref{DefNSSEql}.

\section{Stationarized Household Equations}\label{SecStnrzHH}

  The stationary version of the household budget constraint \eqref{EqHHBC} is found by dividing both sides of the equation by $e^{g_y t}$. For the savings term $b_{j,s+1,t+1}$, we must multiply and divide by $e^{g_y(t+1)}$, which leaves an $e^{g_y} = \frac{e^{g_y(t+1)}}{e^{g_y t}}$ in front of the stationarized variable.
  \begin{equation}\label{EqStnrzHHBCstat}
    \begin{split}
      \hat{c}_{j,s,t} + e^{g_y}\hat{b}_{j,s+1,t+1} &= (1 + r_{t})\hat{b}_{j,s,t} + \hat{w}_t e_{j,s} n_{j,s,t} + \zeta_{j,s}\frac{\hat{BQ}_t}{\lambda_j\hat{\omega}_{s,t}} + \eta_{j,s,t}\frac{\hat{TR}_{t}}{\lambda_j\hat{\omega}_{s,t}} - \hat{T}_{s,t}  \\
      &\quad\forall j,t\quad\text{and}\quad s\geq E+1 \quad\text{where}\quad b_{j,E+1,t}=0\quad\forall j,t
    \end{split}
  \end{equation}
  Because total bequests $BQ_t$ and total government transfers $TR_t$ grow at both the labor productivity growth rate and the population growth rate, we have to multiply and divide each of those terms by the economically relevant population $\tilde{N}_t$. This stationarizes total bequests $\hat{BQ}_t$, total transfers $\hat{TR}_t$, and the respective population level in the denominator $\hat{\omega}_{s,t}$.

  We stationarize the Euler equations for labor supply \eqref{EqHHeul_n} by dividing both sides by $e^{g_y(1-\sigma)}$. On the left-hand-side, $e^{g_y}$ stationarizes the wage $\hat{w}_t$ and $e^{-\sigma g_y}$ goes inside the parentheses and stationarizes consumption $\hat{c}_{j,s,t}$. On the right-and-side, the $e^{g_y(1-\sigma)}$ terms cancel out.
  \begin{equation}\label{EqStnrzHHeul_n}
    \begin{split}
      &\hat{w}_t e_{j,s}\bigl(1 - \tau^{mtrx}_{s,t}\bigr)(\hat{c}_{j,s,t})^{-\sigma} = \chi^n_{s}\biggl(\frac{b}{\tilde{l}}\biggr)\biggl(\frac{n_{j,s,t}}{\tilde{l}}\biggr)^{\upsilon-1}\Biggl[1 - \biggl(\frac{n_{j,s,t}}{\tilde{l}}\biggr)^\upsilon\Biggr]^{\frac{1-\upsilon}{\upsilon}} \\
      &\qquad\qquad\qquad\qquad\qquad\qquad\qquad\qquad\forall j,t, \quad\text{and}\quad E+1\leq s\leq E+S \\
    \end{split}
  \end{equation}

  We stationarize the Euler equations for savings \eqref{EqHHeul_b} and \eqref{EqHHeul_bS} by dividing both sides of the respective equations by $e^{-\sigma g_y t}$. On the right-hand-side of the equation, we then need to multiply and divide both terms by $e^{-\sigma g_y(t+1)}$, which leaves a multiplicative coefficient $e^{-\sigma g_y}$.
  \begin{equation}\label{EqStnrzHHeul_b}
    \begin{split}
      &(\hat{c}_{j,s,t})^{-\sigma} = e^{-\sigma g_y}\biggl[\chi^b_j\rho_s(\hat{b}_{j,s+1,t+1})^{-\sigma} + \beta\bigl(1 - \rho_s\bigr)\Bigl(1 + r_{t+1}\bigl[1 - \tau^{mtry}_{s+1,t+1}\bigr]\Bigr)(\hat{c}_{j,s+1,t+1})^{-\sigma}\biggr] \\
      &\qquad\qquad\qquad\qquad\qquad\qquad\qquad\qquad\forall j,t, \quad\text{and}\quad E+1\leq s\leq E+S-1 \\
    \end{split}
  \end{equation}

  \begin{equation}\label{EqStnrzHHeul_bS}
    (\hat{c}_{j,E+S,t})^{-\sigma} = e^{-\sigma g_y}\chi^b_j(\hat{b}_{j,E+S+1,t+1})^{-\sigma} \quad\forall j,t \quad\text{and}\quad s = E+S
  \end{equation}

\section{Stationarized Firms Equations}\label{SecStnrzFirms}

  The nonstationary production function \eqref{EqFirmsCESprodfun} can be stationarized by dividing both sides by $e^{g_y t}\tilde{N}$. This stationarizes output $\hat{Y}_t$ on the left-hand-side. Because the general CES production function is homogeneous of degree 1, $F(xK,xL) = xF(K,L)$, which means the right-hand-side of the production function is stationarized by dividing by $e^{g_y t}\tilde{N}_t$.
  \begin{equation}\label{EqStnrzCESprodfun}
    \hat{Y}_t = F(\hat{K}_t, \hat{L}_t) \equiv Z_t\biggl[(\gamma)^\frac{1}{\ve}(\hat{K}_t)^\frac{\ve-1}{\ve} + (1-\gamma)^\frac{1}{\ve}(\hat{L}_t)^\frac{\ve-1}{\ve}\biggr]^\frac{\ve}{\ve-1} \quad\forall t
  \end{equation}
  Notice that the growth term multiplied by the labor input drops out in this stationarized version of the production function. We stationarize the nonstationary profit function \eqref{EqFirmsProfit} in the same way, by dividing both sides by $e^{g_y t}\tilde{N}_t$.
  \begin{equation}\label{EqStnrzProfit}
    \hat{PR}_t = (1 - \tau^{corp})\Bigl[F(\hat{K}_t,\hat{L}_t) - \hat{w}_t \hat{L}_t\Bigr] - \bigl(r_t + \delta\bigr)\hat{K}_t + \tau^{corp}\delta^\tau \hat{K}_t \quad\forall t
  \end{equation}

  The firms' first order equation for labor demand \eqref{EqFirmFOC_L} is stationarized by dividing both sides by $e^{g_y t}$. This stationarizes the wage $\hat{w}_t$ on the left-hand-side and cancels out the $e^{g_y t}$ term in front of the right-hand-side. To complete the stationarization, we multiply and divide the $\frac{Y_t}{e^{g_y t}L_t}$ term on the right-hand-side by $\tilde{N}_t$.
  \begin{equation}\label{EqStnrzFOC_L}
    \hat{w}_t = (Z_t)^\frac{\ve-1}{\ve}\left[(1-\gamma)\frac{\hat{Y}_t}{\hat{L}_t}\right]^\frac{1}{\ve} \quad\forall t
  \end{equation}

  It can be seen from the firms' first order equation for capital demand \eqref{EqFirmFOC_K} that the interest rate is already stationary. If we multiply and divide the $\frac{Y_t}{K_t}$ term on the right-hand-side by $e^{t_y t}\tilde{N}_t$, those two aggregate variables become stationary. In other words, $Y_t$ and $K_t$ grow at the same rate and $\frac{Y_t}{K_t} = \frac{\hat{Y}_t}{\hat{K}_t}$.
  \begin{equation}\tag{\ref{EqFirmFOC_K}}
    \begin{split}
      r_t &= (1 - \tau^{corp})(Z_t)^\frac{\ve-1}{\ve}\left[\gamma\frac{\hat{Y}_t}{\hat{K}_t}\right]^\frac{1}{\ve} - \delta + \tau^{corp}\delta^\tau \quad\forall t \\
      &= (1 - \tau^{corp})(Z_t)^\frac{\ve-1}{\ve}\left[\gamma\frac{Y_t}{K_t}\right]^\frac{1}{\ve} - \delta + \tau^{corp}\delta^\tau \quad\forall t
    \end{split}
  \end{equation}

\section{Stationarized Government Equations}\label{SecStnrzGovt}

  Each of the tax rate functions $\tau^{etr}_{s,t}$, $\tau^{mtrx}_{s,t}$, and $\tau^{mtry}_{s,t}$ is stationary. The total tax liability function $T_{s,t}$ is growing at the rate of labor productivity growth $g_y$ This can be see by looking at the decomposition of the total tax liability function into the effective tax rate times total income \eqref{EqTaxCalcLiabETR}. The effective tax rate function is stationary, and household income is growing at rate $g_y$. So household total tax liability is stationarized by dividing both sides of the equation by $e^{g_y t}$.
  \begin{equation}\label{EqStnrzLiabETR}
    \begin{split}
      \hat{T}_{s,t} &= \tau^{etr}_{s,t}(\hat{x}_{j,s,t}, \hat{y}_{j,s,t})\left(\hat{x}_{j,s,t} + \hat{y}_{j,s,t}\right) \qquad\qquad\qquad\quad\:\:\forall t \quad\text{and}\quad E+1\leq s\leq E+S \\
      &= \tau^{etr}_{s,t}(\hat{w}_t e_{j,s}n_{j,s,t}, r_t\hat{b}_{j,s,t})\left(\hat{w}_t e_{j,s}n_{j,s,t} + r_t\hat{b}_{j,s,t}\right) \quad\forall t \quad\text{and}\quad E+1\leq s\leq E+S
    \end{split}
  \end{equation}

  We can stationarize the simple expressions for total government spending on public goods $G_t$ in \eqref{EqUnbalGBC_Gt} and on household transfers $TR_t$ in \eqref{EqUnbalGBCtfer} by dividing both sides by $e^{g_y t}\tilde{N}_t$,
  \begin{equation}\label{EqStnrz_Gt}
    \hat{G}_t = g_{g,t}\:\alpha_{g}\:\hat{Y}_t \quad\forall t
  \end{equation}
  \begin{equation}\label{EqStnrzTfer}
    \hat{TR}_t = g_{tr,t}\:\alpha_{tr}\:\hat{Y}_t \quad\forall t
  \end{equation}
  where the time varying multipliers $g_{g,t}$ and $g_{tr,t}$, respectively, are defined in \eqref{EqStnrzClosureRule_Gt} and \eqref{EqStnrzClosureRule_TRt} below. These multipliers $g_{g,t}$ and $g_{tr,t}$ do not have a ``$\:\,\hat{}\,\:$'' on them because their specifications \eqref{EqUnbalGBCclosure_Gt} and \eqref{EqUnbalGBCclosure_TRt} that are functions of nonstationary variables are equivalent to \eqref{EqStnrzClosureRule_Gt} and \eqref{EqStnrzClosureRule_TRt} specified in stationary variables.

  We can stationarize the expression for total government revenue $Rev_t$ in \eqref{EqUnbalGBCgovRev} by dividing both sides of the equation by $e^{g_y t}\tilde{N}_t$.
  \begin{equation}\label{EqStnrzGovRev}
    \hat{Rev}_t = \underbrace{\tau^{corp}\bigl[\hat{Y}_t - \hat{w}_t\hat{L}_t\bigr] - \tau^{corp}\delta^\tau \hat{K}_t}_{\text{corporate tax revenue}} + \underbrace{\sum_{s=E+1}^{E+S}\sum_{j=1}^J\lambda_j\hat{\omega}_{s,t}\tau^{etr}_{s,t}\left(\hat{x}_{j,s,t},\hat{y}_{j,s,t}\right)\bigl(\hat{x}_{j,s,t} + \hat{y}_{j,s,t}\bigr)}_{\text{household tax revenue}} \quad\forall t
  \end{equation}
  Every term in the government budget constraint \eqref{EqUnbalGBCbudgConstr} is growing at both the productivity growth rate and the population growth rate, so we stationarize it by dividing both sides by $e^{g_y t}\tilde{N}_t$. We also have to multiply and divide the next period debt term $D_{t+1}$ by $e^{g_y(t+1)}\tilde{N}_{t+1}$, leaving the term $e^{g_y}(1 + \tilde{g}_{n,t+1})$.
  \begin{equation}\label{EqStnrzGovBC}
    e^{g_y}\left(1 + \tilde{g}_{n,t+1}\right)\hat{D}_{t+1} + \hat{Rev}_t = (1 + r_t)\hat{D}_t + \hat{G}_t + \hat{TR}_t \quad\forall t
  \end{equation}

  The three potential budget closure rules \eqref{EqUnbalGBCclosure_Gt}, \eqref{EqUnbalGBCclosure_TRt}, and \eqref{EqUnbalGBCclosure_TRGt} are the last government equations to stationarize. In each of the cases, we simply divide both sides by $e^{g_y t}\tilde{N}_t$.
  \begin{equation}\label{EqStnrzClosureRule_Gt}
      \begin{split}
        &\hat{G}_t = g_{g,t}\:\alpha_{g}\: \hat{Y}_t \\
        &\text{where}\quad g_{g,t} =
          \begin{cases}
            1 \qquad\qquad\qquad\qquad\qquad\qquad\qquad\qquad\qquad\quad\:\:\text{if}\quad t < T_{G1} \\
            \frac{e^{g_y}\left(1 + \tilde{g}_{n,t+1}\right)\left[\rho_{d}\alpha_{D}\hat{Y}_{t} + (1-\rho_{d})\hat{D}_{t}\right] - (1+r_{t})\hat{D}_{t} - \hat{TR}_{t} + \hat{Rev}_{t}}{\alpha_g \hat{Y}_t} \quad\text{if}\quad T_{G1}\leq t<T_{G2} \\
            \frac{e^{g_y}\left(1 + \tilde{g}_{n,t+1}\right)\alpha_{D}\hat{Y}_{t} - (1+r_{t})\hat{D}_{t} - \hat{TR}_{t} + \hat{Rev}_{t}}{\alpha_g \hat{Y}_t} \qquad\qquad\qquad\text{if}\quad t \geq T_{G2}
          \end{cases} \\
        &\quad\text{and}\quad g_{tr,t} = 1 \quad\forall t
      \end{split}
    \end{equation}
  or
  \begin{equation}\label{EqStnrzClosureRule_TRt}
    \begin{split}
        &\hat{TR}_t = g_{tr,t}\:\alpha_{tr}\: \hat{Y}_t \\
        &\text{where}\quad g_{tr,t} =
          \begin{cases}
            1 \qquad\qquad\qquad\qquad\qquad\qquad\qquad\qquad\qquad\quad\text{if}\quad t < T_{G1} \\
            \frac{e^{g_y}\left(1 + \tilde{g}_{n,t+1}\right)\left[\rho_{d}\alpha_{D}\hat{Y}_{t} + (1-\rho_{d})\hat{D}_{t}\right] - (1+r_{t})\hat{D}_{t} - \hat{G}_{t} + \hat{Rev}_{t}}{\alpha_{tr} \hat{Y}_t} \quad\text{if}\quad T_{G1}\leq t<T_{G2} \\
            \frac{e^{g_y}\left(1 + \tilde{g}_{n,t+1}\right)\alpha_{D}\hat{Y}_{t} - (1+r_{t})\hat{D}_{t} - \hat{G}_{t} + \hat{Rev}_{t}}{\alpha_{tr} \hat{Y}_t} \qquad\qquad\qquad\text{if}\quad t \geq T_{G2}
          \end{cases} \\
      &\quad\text{and}\quad g_{g,t} = 1 \quad\forall t
      \end{split}
  \end{equation}
  or
  \begin{equation}\label{EqStnrzClosureRule_TRGt}
      \begin{split}
        &\hat{G}_t + \hat{TR}_t = g_{trg,t}\left(\alpha_g + \alpha_{tr}\right)\hat{Y}_t \quad\Rightarrow\quad \hat{G}_t = g_{trg,t}\:\alpha_g\:\hat{Y}_t \quad\text{and}\quad \hat{TR}_t = g_{trg,t}\:\alpha_{tr}\:\hat{Y}_t \\
        &\text{where}\quad g_{trg,t} =
          \begin{cases}
            1 \qquad\qquad\qquad\qquad\qquad\qquad\qquad\qquad\quad\:\:\,\text{if}\quad t < T_{G1} \\
            \frac{e^{g_y}\left(1 + \tilde{g}_{n,t+1}\right)\left[\rho_{d}\alpha_{D}\hat{Y}_{t} + (1-\rho_{d})\hat{D}_{t}\right] - (1+r_{t})\hat{D}_{t} + \hat{Rev}_{t}}{\left(\alpha_g + \alpha_{tr}\right)\hat{Y}_t} \quad\text{if}\quad T_{G1}\leq t<T_{G2} \\
            \frac{e^{g_y}\left(1 + \tilde{g}_{n,t+1}\right)\alpha_{D}\hat{Y}_{t} - (1+r_{t})\hat{D}_{t} + \hat{Rev}_{t}}{\left(\alpha_g + \alpha_{tr}\right)\hat{Y}_t} \qquad\qquad\quad\:\:\:\:\,\text{if}\quad t \geq T_{G2}
          \end{cases}
      \end{split}
    \end{equation}

\section{Stationarized Market Clearing Equations}\label{SecStnrzMC}

  The labor market clearing equation \eqref{EqMarkClrLab} is stationarized by dividing both sides by $\tilde{N}_t$.
  \begin{equation}\label{EqStnrzMarkClrLab}
    \hat{L}_t = \sum_{s=E+1}^{E+S}\sum_{j=1}^{J} \hat{\omega}_{s,t}\lambda_j e_{j,s}n_{j,s,t} \quad \forall t
  \end{equation}
  The capital market clearing equation \eqref{EqMarkClrCap} is stationarized by dividing both sides by $e^{g_y t}\tilde{N}_t$. Because the right-hand-side has population levels from the previous period $\omega_{s,t-1}$, we have to multiply and divide both terms inside the parentheses by $\tilde{N}_{t-1}$ which leaves us with the term in front of $\frac{1}{1+\tilde{g}_{n,t}}$.
  \begin{equation}\label{EqStnrzMarkClrCap}
    \hat{K}_t + \hat{D}_t = \frac{1}{1 + \tilde{g}_{n,t}}\sum_{s=E+2}^{E+S+1}\sum_{j=1}^{J}\Bigl(\hat{\omega}_{s-1,t-1}\lambda_j \hat{b}_{j,s,t} + i_s\hat{\omega}_{s,t-1}\lambda_j \hat{b}_{j,s,t}\Bigr) \quad \forall t
  \end{equation}

  We stationarize the goods market clearing \eqref{EqMarkClrGoods} condition by dividing both sides by $e^{g_y t}\tilde{N}_t$. On the right-hand-side, we must multiply and divide the $K_{t+1}$ term by $e^{g_y(t+1)}\tilde{N}_{t+1}$ leaving the coefficient $e^{g_y}(1+\tilde{g}_{n,t+1})$. And the term that subtracts the sum of imports of next period's immigrant savings we must multiply and divide by $e^{g_(t+1)}$, which leaves the term $e^{g_y}$.
  \begin{equation}\label{EqStnrzMarkClrGoods}
    \begin{split}
      \hat{Y}_t &= \hat{C}_t + e^{g_y}(1 + \tilde{g}_{n,t+1})\hat{K}_{t+1} - e^{g_y}\biggl(\sum_{s=E+2}^{E+S+1}\sum_{j=1}^{J}i_s\hat{\omega}_{s,t}\lambda_j \hat{b}_{j,s,t+1}\biggr) - (1-\delta)\hat{K}_t + \hat{G}_t \quad\forall t \\
      &\quad\text{where}\quad \hat{C}_t \equiv \sum_{s=E+1}^{E+S}\sum_{j=1}^{J}\hat{\omega}_{s,t}\lambda_j\hat{c}_{j,s,t}
    \end{split}
  \end{equation}

  We stationarize the law of motion for total bequests $BQ_t$ in \eqref{EqMarkClrBQ} by dividing both sides by $e^{g_y t}\tilde{N}_t$. Because the population levels in the summation are from period $t-1$, we must multiply and divide the summed term by $\tilde{N}_{t-1}$ leaving the term in the denominator of $1+\tilde{g}_{n,t}$.
  \begin{equation}\label{EqStnrzMarkClrBQ}
    \hat{BQ}_{t} = \left(\frac{1+r_{t}}{1 + \tilde{g}_{n,t}}\right)\left(\sum_{s=E+2}^{E+S+1}\sum_{j=1}^J\rho_{s-1}\lambda_j\hat{\omega}_{s-1,t-1}\hat{b}_{j,s,t}\right) \quad\forall t
  \end{equation}


\documentclass{article}
\usepackage{fullpage}
\usepackage{nopageno}
\usepackage{amsmath}
\allowdisplaybreaks

\newcommand{\abs}[1]{\left\lvert #1 \right\rvert}
\newcommand{\degree}{\ensuremath{^\circ}}

\begin{document}
Jon Allen

November 20, 2013

\section*{8.3}
In Exercises 1–15, use Laplace transforms to solve the IVPs. Briefly describe how each
equation could be solved using other methods such as undetermined coefficients or variation
of parameters.
\subsection*{\#12}
\[y'''+y'=0,\quad y(0)=y'(0)=0,\quad y''(0)=1\]
this could be solved by integrating to get $y''+y=C$ and then proceeding with the method of undetermined coefficients
\subsubsection*{solution}
\begin{align*}
	y'''+y'&=0\\
	\mathcal{L}\{y(t)\}&=Y(s)\\
	\mathcal{L}\{y'''\}+\mathcal{L}\{y'\}&=\mathcal{L}\{0\}\\
	s^3\mathcal{L}\{y(t)\}-s^2y(0)-sy'(0)-y''(0)+s\mathcal{L}\{y(t)\}-y(0)&=0\\
	Y(s)\left(s^3+s\right)-1&=0\\
	Y(s)\left(s^3+s\right)&=1\\
	Y(s)&=\frac{1}{s(s^2+1)}\\
	\frac{1}{s(s^2+1)}&=\frac{A}{s}+\frac{B}{s^2+1}\\
	1&=A(s^2+1)+Bs\\
	A=1, \quad s^2+Bs=0,\quad B&=-s\\
	Y(s)&=\frac{1}{s}-\frac{s}{s^2+1}\\
	y(t)&=1-\cos t
\end{align*}
\subsection*{\#13}
\[y'''-y'=e^t+e^{-t},\quad y(0)=y'(0)=y''(0)=0\]
This could be solved essentially the same way that I describe for \#10, it's just the right hand side of the equation will be a little more complicated
\subsubsection*{solution}
\begin{align*}
	y'''-y'&=e^t+e^{-t}\\
	\mathcal{L}\{y(t)\}&=Y(s)\\
	\mathcal{L}\{y'''\}-\mathcal{L}\{y'\}&=\mathcal{L}\{e^t+e^{-t}\}\\
	s^3\mathcal{L}\{y(t)\}-s^2y(0)-sy'(0)-y''(0)-s\mathcal{L}\{y(t)\}+y(0)&=\frac{1}{s-1}+\frac{1}{s+1}\\
	Y(s)(s^3-s)&=\frac{1}{s-1}+\frac{1}{s+1}\\
	Y(s)s(s^2-1)&=\frac{s+1+s-1}{s^2-1}\\
	Y(s)&=\frac{2}{(s-1)^2(s+1)^2}\\
	\frac{A}{(s-1)}+\frac{B}{(s-1)^2}+\frac{C}{(s+1)}+\frac{D}{(s+1)^2}&=\frac{1}{(s-1)^2(s+1)^2}\\
	A(s-1)(s+1)^2+B(s+1)^2+C(s+1)(s-1)^2+D(s-1)^2&=1\\
	As^3+As^2-As-A+Bs^2+B2s+B+Cs^3-Cs^2-Cs+C+Ds^2-D2s+D&=1\\
	s^3(A+C)+s^2(A+B-C+D)+s(-A+2B-C-2D)+(-A+B+C+D)&=1,\quad A=-C\\
	s^2(B-2C+D)+s(2B-2D)+(B+2C+D)&=1,\quad B=D\\
	s^2(2D-2C)+(2D+2C)&=1,\quad C=D\\
	4D&=1,\quad D=\frac{1}{4}\\
	\frac{2}{4}\left(-\frac{1}{s-1}+\frac{1}{(s-1)^2}+\frac{1}{s+1}+\frac{1}{(s+1)^2}\right)&=Y(s)\\
	y(t)&=\frac{1}{2}\left(-e^t+te^t+e^{-t}+te^{-t}\right)
\end{align*}
\section*{8.5}

\subsection*{\#10}
find the laplace transform of $h$ where $h(t)=\int_0^t{v\cos(t-v)\,\mathrm{d}v}$
\subsubsection*{solution}
\begin{align*}
	f(t)&=\cos t,\quad g(t)=t\\
	\mathcal{L}\{h(t)\}&=\mathcal{L}\{f*g\}=\mathcal{L}\{f(t)\}\mathcal{L}\{g(t)\}\\
	\mathcal{L}\{h(t)\}&=\frac{s}{s^2+1}\cdot\frac{1}{s^2}=\frac{1}{s^3+s}
\end{align*}

\subsection*{\#18}
find the inverse laplace of $\frac{s}{(s^2+1)^2}$
\subsubsection*{solution}
\begin{align*}
	\frac{s}{(s^2+1)^2}&=\frac{s}{s^2+1}\cdot\frac{1}{s^2+1}\\
	\mathcal{L}\{\sin t\}&=\frac{1}{s^2+1},\quad \mathcal{L}\{\cos t\}=\frac{s}{s^2+1}\\
	\frac{s}{(s^2+1)^2}&=\mathcal{L}\{\cos t\}\mathcal{L}\{\sin t\}=\mathcal{L}\{\cos t*\sin t\}\\
	\mathcal{L}^{-1}\left\{\frac{s}{(s^2+1)^2}\right\}&=\int_0^t{\cos(t-v)\sin v\,\mathrm{d}v}
\end{align*}

\subsection*{\#27 extra credit}
finish this to get +2 points on exam
solve $\frac{\mathrm{d}y}{\mathrm{d}t}-4y+4\int_0^t{y(v)\,\mathrm{d}v}=t^3e^{2t},y(0)=0$
\subsubsection*{solution}
\begin{align*}
    g(t)&=1\\
    sY(s)-4Y(s)+4\frac{1}{s}Y(s)&=\frac{6}{(s-2)^4}\\
    Y(s)\left[s-4+\frac{4}{s}\right]&=\frac{6}{(s-2)^4}\\
    Y(s)\left[\frac{s^2-4s+4}{s}\right]&=\frac{6}{(s-2)^4}\\
	Y(s)\left[(s-2)^2\right]&=\frac{6s}{(s-2)^4}\\
	Y(s)&=\frac{6s}{(s-2)^6}=\frac{6(s-2)+12}{(s-2)^6}=\frac{6}{(s-2)^5}+\frac{12}{(s-2)^6}\\
	    &=\frac{1}{4}\cdot\frac{24}{(s-2)^5}+\frac{1}{10}\cdot\frac{120}{(s-2)^6}=\frac{1}{4}\cdot\frac{4!}{(s-2)^5}+\frac{1}{10}\cdot\frac{5!}{(s-2)^6}\\
	\mathcal{L}\{e^{at}t^n\}&=\frac{n!}{(s-a)^{n+1}}\\
	y(t)&=\frac{1}{4}e^{2t}t^4+\frac{1}{10}e^{2t}t^5
\end{align*}

\end{document}


    \filetitle{eig}{Eigenvalues of a VAR process}{VAR/eig}

	\paragraph{Syntax}\label{syntax}

\begin{verbatim}
E = eig(V)
\end{verbatim}

\paragraph{Input arguments}\label{input-arguments}

\begin{itemize}
\itemsep1pt\parskip0pt\parsep0pt
\item
  \texttt{V} {[} VAR {]} - VAR object whose eigenvalues will be
  returned.
\end{itemize}

\paragraph{Output arguments}\label{output-arguments}

\begin{itemize}
\itemsep1pt\parskip0pt\parsep0pt
\item
  \texttt{E} {[} numeric {]} - VAR eigenvalues.
\end{itemize}

\paragraph{Description}\label{description}

This function is equivalent to calling

\begin{verbatim}
e = get(v,'eig')
\end{verbatim}

\paragraph{Example}\label{example}