\section{The \lang language}

\lang is a minimal ML-like language with
let-polymorphism and abstract types. Its type system manages
linearity and borrowing using kinds and (kind-) constrained types.
For ease of presentation, we consider a simplified internal language.
\begin{itemize}[topsep=0pt]
\item Pattern matching is demonstrated on pairs rather than algebraic
  datatypes.
\item There are separate operators for borrowing and reborrowing (taking
  the borrow of a borrow); the surface language unifies these
  operators using ad-hoc polymorphism / typeclasses.
\item Regions are explicit in the code and must be annotated using the
  algorithms presented in \cref{regionannot}.
\item Regions are identified using nesting levels instead of region
  variables.
\end{itemize}

The rest of this section formalizes  \lang: the syntax (\cref{syntax}),
the statics in terms of a region annotation pass (\cref{regionannot}) and
syntax-directed typing (\cref{sdtyping}),
and a dynamics that is linearity- and resource-aware (\cref{sec:sem}).

\subsection{Syntax}
\label{syntax}

\begin{figure}[!tb]
  \input{grammar}
  \vspace{-7pt}
  \caption{Syntax}
  \label{grammar}
  \vspace{-10pt}
\end{figure}

\Cref{grammar} defines the syntax of \lang. Expressions are as usual
in an ML-like language.  The novel aspects are match
specifications, regions, and borrows.

A borrow $\borrow{x}$ is always taken from a variable $x$. The
\emph{borrow annotation} $\BORROW$ indicates whether the borrow is exclusive/affine
($\MBORROW$) or shared/unrestricted ($\IBORROW$). If $x$ is already borrowed,
then we need to use the reborrow expression $\reborrow{x}$.
%
A region $\region{\Sone x\BORROW}{e}$ is annotated with its nesting $n$, the variable $x$ that may be borrowed in $e$, and the kind of borrow $\BORROW$.
%
A match is indexed with a \emph{match specification} $\etransfm$ that indicates
whether the match operates on borrows ($\etransfm=\&^b$) or not ($\etransfm=id$).
%
We consider four primitive operations to manipulate resources:
$\create$, $\observe$, $\update$ and $\destroy$.
They serve a prototypes to demonstrate the typing and handling of
resources. For a concrete type of resource, there are further
arguments and perhaps different versions of the operations. But the
typing and behavior of the operations is analogous to the prototype
operations. Moreover, $\observe$ and $\update$ serve as eliminators
for borrow types.

Many types are indexed with kinds.
A kind $k$ is either a kind variable $\kvar$ or a constant
(linear $\klin$, affine $\kaff$, or unrestricted $\kun$) indexed
by a nesting level $n \in \Nat \cup \{\infty\}$.

A type $\tau$ is either a type variable, a pair type, a function type indexed by a
kind,
a type application $\tapp{\tcon}{\Multi{\tau}}$ of an abstract type constructor
$\T T$, or a borrowed type  $\borrowty{k}{\tau}$.

Type schemes $\schm$ add quantification over kind
variables $\kappa$, kinded type variables $(\alpha:k)$, and constraints
$C$ to a type, where a constraint is a list of inequalities over
kinds.

Abstract type constructors possess kind schemes $\kschm$ which relate
the kinds of the type constructors' arguments to the kind of the
constructed type.

Generally, we write lists with an overbar and (sometimes) an index as
in $\Multi[i]\tau$.

% \paragraph{Previously}

% Let us first define our conventions and meta-syntactic variables.
% Expressions, types and kinds are denoted respectively as $e$, $\tau$, and $k$.
% Variables, type variables and kind variables are denoted
% respectively as $x$, $\tvar$ and $\kvar$. Types and kind schemes
% are denoted by $\schm$ and $\kschm$.
% In the rest of the text, we will write lists with a bar and an index, for
% instance $\Multi[i]{\tau}$.
% Kind constants are denoted in bold capital letters, such as $\kaff$ for affine.

% The syntax of \lang is presented in \cref{grammar} and follows
% traditional ML languages with let bindings.
% Borrows $\borrow{e}$ are annotated with a specification indicating
% if a borrow is immutable ($\IBORROW$) or mutable ($\MBORROW$).
% We also distinguish reborrows, which are written as $\reborrow{e}$.
% Match are indexed with a specification which can be either $\&^b$
% (which $b$ a borrow specification) or $id$, indicating if the match
% should operate on borrows or not.
% Regions $\region{\Sone x\BORROW}{e}$ are annotated with their nesting ($n$)
% and the variable whose borrow they enclose ($x$).
% %
% $\tapp{\tcon}{\Multi{\tau}}$ denotes a type application where
% $\T t$ is an abstract type constructor.
% Arrow and borrow types are annotated with a kind, written as $\tau \tarr{k} \tau$
% and $\borrowty{k}{\tau}$ respectively.
% %
% Kinds can be either a kind variable $\kvar$, or constants
% (linear $\klin$, affine $\kaff$ or unrestricted $\kun$) indexed
% by a nesting level represented by a member of $N \cup \{\infty\}$.
% Type schemes and kind schemes are guarded by a set of constraints.
% %
% Finally, constraints are composed of a list of kind inequalities.

% Environments are composed of value and type bindings, along with type
% declarations. Type declarations, of the form
% $\tydecl{t}{\kschm}{K}{\tau}$, introduce both a new type constructor $\T{t}$ and
% a data constructor $K$.

\subsection{Automatic region annotation}
\label{regionannot}

In the surface language (\cref{motivation}) region annotations are optional.
In the internal language, regions must be syntactically explicit and
annotated with a nesting index and a scoped variable.
This section defines a transformation $\RannotT{p}{p'}$ which
automatically inserts region annotations in  programs.
The input $p$ is a program with optional region annotations of the form $\region[]{}{e}$.
The output $p'$ is a program with explicit annotations
of the form $\region{\Sone x\BORROW}{e}$ such that no borrow occurs
outside a region.
We give an informal presentation of our code transformation and defer
the complete definition to \cref{appendix:regionannot}. This code transformation
aims to find, for each borrow $\borrow{x}$, the biggest region satisfying
the following rules:
\begin{enumerate}
\item The region should contain at least $\borrow{x}$.
\item The region must be contained in the scope of $x$.
\item An exclusive borrow $\borrow[\kaff]{x}$ should never share a region with any other borrow of $x$.
\item The variable $x$ cannot occur in the region of $\borrow{x}$.
\end{enumerate}
The transformation starts from each borrow $\borrow x$ and grows its associated
region until enlarging it would include the binding for $x$ or lead to a
conflicting use of $x$ or a conflicting borrow for $x$.
As an example, consider the following program:
%
\[
  \setlength{\jot}{-1pt}
  \RannotT{
\begin{aligned}
  \lam{a}{}\ &
  \letin{x}{\app{f}{\borrow[\kaff]{a}}}{}\\
  &g\ (\borrow[\kaff]{x});\\
  &f\ (\borrow[\kun]{x})\ (\borrow[\kun]{x})\\
\end{aligned}
}{
\begin{aligned}
  \lam{a}{}\region[1]{\Sone a\MBORROW}{\ &%
  \letin{x}{\app{f}{\borrow[\kaff]{a}}}{}\\
  &\region[2]{\Sone x\MBORROW}{g\ (\borrow[\kaff]{x})};\\
  &\region[2]{\Sone x\IBORROW}{f\ (\borrow[\kun]{x})\ (\borrow[\kun]{x})}\\
  &\!\!\!}
\end{aligned}
}
\]
%
As variable $a$ only has one borrow, its region covers its whole lexical scope.
Variable $x$ has multiple conflicting borrows and requires more consideration.
We place a first
region around the exclusive borrow and its function application,
and a second region around both shared borrows. This placement of region
is optimal: making any region bigger would cause a borrowing
error.
In particular, it is essential to place the second borrow around \emph{both}
occurrence of $(\borrow[\kun]{x}$: we want the function to receive both
borrows, but its result must not contain any borrow (otherwise it would escape).
Region indices are assigned after placement, so it is trivial to
ensure well-nested regions where the inner regions have
higher indices than the outer ones.

Programmers may also annotate regions explicitly.
The transformation considers an annotation as an
upper bound on the contained regions.
In the following program, a manual annotation has been inserted to ensure
no borrow enters the reference $r$:
%
\[
  \setlength{\jot}{-1pt}
  \RannotT{
\begin{aligned}
  \letin{&r}{\operatorname{ref}\ 0}{}\\
  \lam{a}{}\ &
  set\ r\ \region[]{}{g\ (\borrow[\kun]{a})};\\
  &f\ (\borrow[\kun]{a})
\end{aligned}
}{
\begin{aligned}
  \letin{&r}{\operatorname{ref}\ 0}{}\\
  \lam{a}{}\ &
  set\ r\ \region[1]{\Sone a\IBORROW}{g\ (\borrow[\kun]{a})};\\
  &\region[1]{\Sone a\IBORROW}{f\ (\borrow[\kun]{a})}
\end{aligned}
}
\]
%
The rules allow merging the two regions around the borrows
$\borrow[\kun]{a}$. However
the explicit annotation indicates that the region should stay around the closure
passed as argument of $set$. This feature is useful to control captures
by imperative APIs.

The code transformation is purely syntactic and must be used before
typing. It only produces well-nested annotations: if $\region[n]{b}{\dots}$
is nested inside $\region[n']{b'}{\dots}$, then $n > n'$. Furthermore, there
is at most one region per borrow, and exactly one region per exclusive borrow.
In the rest of this article, we assume
that all terms have been annotated by this code transformation and respect
these properties.

\subsection{Typing}
\label{sdtyping}

To avoid distraction, this section focuses on the essential and novel
parts of the type system. A complete
description is available in \cref{appendix:sdtyping}.
% In this section, we focus on chosen parts of our system
% through a set of selected rules.
%
Here we only discuss the following judgments:
\begin{flushleft}
  \begin{tabular}{l@{ --- }l}
    $\inferS{C}{\E}{e}{\tau}$&
                               Expression $e$ has type $\tau$ in
                               environment $\E$ under constraints
                        $C$. \\
    $\inferSK{C}{\E}{\tau}{k}$&
                                Type $\tau$ has kind $k$ in
                                environment $\E$ under constraints
                                $C$. \\
    $\entail{D}{C}$ & Constraint $D$ entails constraint $C$.\\
    $D \equivC C$ & Constraints $C$ and $D$ are equivalent.
  \end{tabular}
\end{flushleft}

\paragraph{Kinds and constraints}

\affe uses kinds and constrained types to indicate
linear and affine types.
% Before explaining the details of our type system, we
% give a quick presentation of the kinds and constraints.
A kind $k$ is either a kind variable, $\kvar$, or a constant $\mul_n$.
The quality $\mul$ describes the use pattern of the type:
unrestricted $\kun$, affine $\kaff$, or linear $\klin$. The level $n \in \Nat \cup \{\infty\}$
describes the nested regions in which the value can be used.
Level $0$ refers to the top-level scope outside any region; we often elide it
and write $\kaff$ for $\kaff_0$. Level
$\infty$ refers to an empty region that is infinitely nested.
For instance, the constraint $\Cleq{\kvar}{\kun_\infty}$ indicates that
$\kvar$ must be unrestricted, but can be local to a region.
%
Kinds form a lattice described in \cref{sdtyp:lattice}.
Unrestricted values may be used
where affine ones are expected and affine ones are less restricted
than linear ones as reflected in \TirName{Lat-UAL}.
Values usable at level $n$ may be used at any more deeply
nested level $n'$ as defined in the \TirName{Lat-Level} axioms.
%
Constraints are conjunctions of inequality constraints over this kind
lattice, i.e., they specify upper or lower bounds for
kind variables or relate two kind variables.

\begin{figure}[tp]
  \input{infer/lattice}
  \vspace{-10pt}
  \caption{Lattice ordering -- $k \lk_\Lat k'$}
  \label{sdtyp:lattice}
  \vspace{-10pt}
\end{figure}

\paragraph{Environments and bindings}
\label{sdtyping:envs}

\begin{figure}[tp]
  \begin{minipage}{0.36\linewidth}
  \begin{align*}
    \E ::=&\ \Eempty \mid \E;B\tag{Environments}\\
    B ::=&\ \bnone \tag{Empty} \\
    |&\ \bvar{\tvar}{\kschm} \tag{Types}\\
    |&\ \bvar{x}{\schm} \tag{Variables} \\
    |&\ \svar{x}{\schm}^n \tag{Suspended} \\
    |&\ \bbvar x k \schm \tag{Borrows}
    % \bvar{\borrow{x}}{\borrowty{k}{\tau}} \tag{Borrows}\\
    % |&\ \tydecl{t}{\kschm}{K}{\tau}\tag{Type Declaration}\\
  \end{align*}
  \vspace{-15pt}
  \caption{Type environments}
  \label{grammar:env}
  \end{minipage}\hfill
  \begin{minipage}{0.6\linewidth}
    \input{sdtyping/split-binder}
    \vspace{-5pt}
    \caption{Splitting rules for bindings -- $\lsplit{C}{B}{B_l}{B_r}$}
    \label{sdtyp:split}
  \end{minipage}
\end{figure}

\begin{figure*}[tp]
  % \begin{minipage}{0.7\linewidth}
    \begin{mathpar}
      \ruleInstance
      \and
      \ruleSDVar
      \and
      \ruleSDLam
      \and
      \ruleSDApp
      \and
      \ruleSDRegion
      \and
      \ruleSDBorrow
      \and
      \ruleSDReBorrow
      \and
      \inferrule[BorrowBinding]{
        \entail{C}{(\BORROW_n\lk k) \wedge (k \lk \BORROW_\infty)}\\\\
        \BORROW\in\left\{\kun,\kaff\right\}
      }{
        \lregion{C}{x}
        {\svar[\BORROW]{x}{\schm}^n}
        {\bbvar x k \schm}
        % {\bvar{\borrow[\BORROW]{x}}{\borrowty[\BORROW] k{\schm}}}
      }
      % \and
      % \ruleSDPair
      % \and
      % \ruleSDMatchPair
    \end{mathpar}
    \vspace{-10pt}
    \caption{Selected typing rules ($\inferS{C}{\E}{e}{\tau}$)
      and borrowing rules ($\lregion{C}{x}{\E}{\E'}$)}
    \label{selectrules:borrow}
    \label{selectrules:binders}
    \label{sdtyp:app}
    \label{selectrules:region}
    \label{env:rule:borrow}
    \vspace{-5pt}
  % \end{minipage}
\end{figure*}

\lang controls the use of variables by supporting new modes of
binding in type environments $\E$, as defined in \cref{grammar:env}.
Environments contain standard bindings of type variables to kind schemes,
$\bvar{\tvar}{\kschm}$, value bindings $\bvar{x}{\schm}$, but also
suspended and borrow bindings.
A suspended binding, $\svar{x}{\schm}^n$, indicates that $x$ is
earmarked for a borrowing use in a nested region
marked with $x$ % (see \cref{sdtyping:regions}),
but
cannot be used directly.
A borrow binding,
$\bbvar x k \schm$,
%$\bvar{\borrow{x}}{\borrowty{k}{\schm}}$,
replaces
such a suspended binding on entry to the $x$-region. It indicates
that the borrow $\borrow{x}$ can be used directly. Kind $k$
restricts the lifetime of the borrow to the region (see rules
\TirName{Region} and \TirName{BorrowBinding} in
\cref{selectrules:borrow} and the upcoming discussion of these rules).

% , either
% through
% linearity and affinity which restrict how variables are shared and ignored,
% or through borrows which allow to circumvent the linearity rules
% in a controlled way.
% In order to check these properties, we introduce several new bindings
% in our typing environments.
% The grammar of type environment (denoted $\E$) is shown in \cref{grammar:env}.

% Environments are also used to encode several linearity-related properties
% through \emph{environment-wide constraints}.
Constraints on an environment control substructural properties by
restricting the types of variables.  The constraint $\Cleq{\E}{k}$
stands for the conjunction of $\Cleq\schm k$, for all $\bvar{x}{\schm}$
% $\svar{x}\schm$, and $\bvar{\borrow{x}}{\borrowty{k'}{\schm}}$
in $\E$, which in turn means that $k' \lk k$ where $k'$ is the kind of
the variable's type scheme $\schm$.
Borrow bindings follow the same rules, but suspended bindings
are forbidden in an environment $\E$ constrained like that.
This intuitive explanation is sufficient to understand
the \TirName{Var} and \TirName{Abs} rules shown in
\cref{selectrules:binders}.

Rule {\sc Var} looks up the type scheme of the variable $x$ in
the environment $\E$
and instantiates it with $\Instance(\E,\schm)$.
Instantiation follows the \hmx formulation and
takes as input a scheme $\schm$ and an environment $\E$
and returns a constraint $C$ and a type $\tau$.
The rule also
checks that the other bindings in $\E$ can be safely discarded by
imposing the constraint $\Cleq{\E\Sdel{x}}{\kaff_\infty}$.
It enforces that all remaining bindings (except $x$) are affine or
unrestricted and can therefore be discarded.

Rule {\sc Abs} ensures the kind annotation on the arrow type
($\tau_2 \tarr{k} \tau_1$) reflects the restrictions on captured variables
via the constraint $\Cleq\E k$.
If, for instance, any binding in $\E$ is affine, it gives rise to the
constraint $\Cleq{\kaff_n}{k}$ and the arrow kind is at least
affine at nesting level $n$.
Capturing a borrow is perfectly fine: the kind of the borrow is also a
lower bound of the arrow kind $k$ which restricts the closure
to the region of the borrow.
Capturing a suspended binding is forbidden.
% Note that $x$ is \emph{not} included in $\E$: since it's the argument of the
% closure, its use should not induce a capture.

\paragraph{Copying and Splitting}
\label{sdtyping:split}

The {\sc App} typing rule in \cref{sdtyp:app} demonstrates how \lang
deals with duplication and dropping of values.
The splitting $\lsplit{C}{\E}{\E_1}{\E_2}$ in the rule decomposes the
type environment $\E$ in two parts, $\E_1$ and $\E_2$, which are used
to typecheck the components of the application.
% The constraint $C$ characterizes a valid  splitting.

\cref{sdtyp:split} shows the action of splitting rules on single
bindings. If $x$'s type is unrestricted,
rule {\sc Both} indicates that we can duplicate it.
Similarly, unrestricted borrows can be duplicated with rule
{\sc Borrow}.
{\sc Left} and {\sc Right} rules are always applicable and move a binding
either to the left or right environment.
The rules {\sc Susp}, {\sc SuspB} and {\sc SuspS}
split off suspended bindings to
the left while conserving access to the binding on the right.
A suspended binding can later be turned
into a borrow inside a region. Splitting of suspended bindings is
asymmetric. It must follow the order of execution from left to right,
which means that a resource can be used first as a borrow on the left
and then later as a full resource on the right. The {\sc Susp} rule
works with a full resource, rule {\sc SuspB}
with a borrow, and rule {\sc SuspS} with a suspended binding.

Splitting applies whenever an
expression has multiple subexpressions:  function applications,
let bindings and pairs. In the
expression
$\letin{a}{\text{create}\ 8\ x}
{f\ \region[{}]{\Sone a\IBORROW}{\text{length}\ \borrow[\IBORROW]{a}}\ a}$,
the rule {\sc Susp} splits off a borrow from  the resource
$a$ to use it in the left argument.
As usual, a borrow cannot be active in the same scope as its resource.
The \emph{region} around its use ensures that the borrow in the left argument
does not
escape, which brings us to the next topic.

\paragraph{Regions}
\label{sdtyping:regions}

% \begin{figure}[tp]
%   % \begin{minipage}{0.4\linewidth}
%   %   \centering
%   %   \begin{mathpar}
%   %     \ruleSDRegion
%   %   \end{mathpar}
%   %   \caption{The {\sc Region} rule}
%   %   \label{selectrules:region}
%   % \end{minipage}\hfill
%   % \begin{minipage}{\linewidth}
%     \centering
%     % \begin{tabular}
%     %   {@{}>{$}r<{$}@{ $\vdash_e$ }
%     %   >{$}c<{$}@{ $\rightsquigarrow_n^{x}$ }
%     %   >{$}l<{$}
%     %   r}

%     %   (\kun_n\lk k\lk\kun_\infty)
%     %   &{\svar[\IBORROW]{x}{\tau}^n}
%     %   &{\bvar{\borrow[\IBORROW]{x}}{\borrowty[\IBORROW] k{\tau}}}
%     %   &Immut\\

%     %   (\kaff_n\lk k\lk\kaff_\infty)
%     %   &\svar[\MBORROW]{x}{\tau}^n
%     %   &\bvar{\borrow[\MBORROW]{x}}{\borrowty[\MBORROW] k{\tau}}
%     %   &Mut
%     % \end{tabular}
%     \begin{mathpar}
%     \end{mathpar}
%     \vspace{-10pt}
%     \caption{Borrowing rules for bindings -- }
%   \vspace{-10pt}
%   % \end{minipage}
% \end{figure}

Borrowing is crucial to support an imperative programming style.
To guarantee the validity of a borrow, its lifetime must be properly contained in its
ancestor's lifetime. \lang ensures proper nesting of lifetimes by using
regions. The expression $\region{\Sone x\BORROW}{e}$ indicates a
region at nesting level $n$ in which a $\BORROW$-borrow can be taken of $x$.

The typing for a region (rule {\sc Region} in \cref{selectrules:region})
replaces suspended bindings by borrow bindings
(rule {\sc BorrowBinding}), typechecks the body
of the region, and ensures that the borrow does not leak outside.
This last check is done with indices that correspond to the nesting
level of the region. The kind $k$ of the borrow is indexed with the level $n$
corresponding to its region, thanks to the constraint $(\BORROW_n\lk
k)$. The constraint $\Cleq{\tau}{\klin_{n-1}}$ ensures that
the return type of the region must live at some enclosing, lower level.

As an example, consider the expression $\region{\Sone x\IBORROW}{f(\borrow[\IBORROW]{c})}$
where $c$ is a linear channel in an environment $\E$.
The first step is to check that $\svar[\IBORROW]{c}{\text{channel}}$
is in $\E$.
When entering the region, rule \TirName{Region} imposes
$\lregion{C}{x}{\E}{\E'}$, which defines $\E'$
corresponding to $\E$ where the suspended binding is replaced by the
borrow binding  $\bbvar[\IBORROW]{c}{k}{\text{channel}}$.
To constrain the borrow to this region we impose the constraint
$\entail{C}{(\kun_n\lk k) \wedge (k \lk\kun_\infty)}$, which affirms
that the borrow is unrestricted, but can only be used in nesting
levels $n$ and higher.
%
% With that setup we typecheck the body of the region,
% $f(\borrow[\IBORROW]{c})$.
% The constraint $\Cleq{\tau}{\klin_{n-1}}$ ensures
% that the kind of $\tau$ does not contain anything whose kind is
% ``above level $n$'' and thus confines the borrow to the region
% (for instance, $\borrowty[\IBORROW]{\kun_n}{\text{c}}$ has kind
% $\kun_n$ and thus cannot be returned).
%
Rule {\sc Region} also imposes the constraint
$\Cleq{\tau}{\klin_{n-1}}$, which prevents the borrow, having kind $k$ of level
$\geq n$, from escaping the region's body of type $\tau$.

% As it would be cumbersome to markup regions manually, we developed an
% algorithm that starts from each borrow, creates a region around it,
% and extends it as much as possible while respecting other borrows
% and binders. The algorithm (see \cref{regionannot}) also provides the region's level
% and variable annotation.
% Henceforth, we consider terms with fully annotated regions.

% \paragraph{Kind checking}

% \TODO{Present this if we have enough space}

\paragraph{Pattern matching}
\label{sdtyping:matching}

Elimination of pairs is done using a matching construct
$(\matchin{x,x'}{e_1}{e_2})$.
This construct is mostly standard, except it can operate both
on a normal pair and a borrow of a pair.
The intuition is as follows:
A syntactic marker $\etransfm$ indicates if it applies to
a pair ($\etransfm = \operatorname{id}$) or a borrow ($\etransfm = \&^\BORROW$).
If $\etransfm = \operatorname{id}$, the typing simplifies to
the usual elimination of a pair.
Otherwise, $e_1$ is expected to be a borrow of type
$\borrowty{k}{\tyPair{\tau_1}{\tau'_1}}$
and the variables $x$ and $x'$ have type
$\borrowty{k}{\tau_1}$ and $\borrowty{k}{\tau'_1}$,
respectively. Thus, the borrow of a pair is considered as a pair of
borrows of its components.

% Matching is voluntarily simple here and
% could be improved using a richer pattern language
% to access inner components and a typeclass mechanisms
% to avoid the need for explicit markers for borrow matches.
% Both extensions are compatible with our system and have been partially
% implemented in our prototype type-checker.

\paragraph{Resource management}

To demonstrate how \lang{} deals with resources, we introduce an abstract
type $\tapp{\tres}{\tau}$ whose content of type $\tau$ must be
unrestricted ($\kun_0$) and which is equipped with the four
operations introduced in \cref{syntax}:
\begin{itemize}[topsep=0pt]
\item
$\create$:
$\forall{\kvar_\tvar}\bvar{\tvar}{\kvar_\tvar}.\
\qual{\Cleq {\kvar_\tvar} {\kun_0}}
{\tvar \tarr{} \tapp\tres\tvar}$
% Creates a new resource.
\item
$\observe$:
$\forall{\kvar\kvar_\tvar}\bvar{\tvar}{\kvar_\tvar}.\
\qual{\Cleq {\kvar_\tvar} {\kun_0}}
{\borrowty[\IBORROW]{\kvar}{\tapp\tres\tvar} \tarr{} \tvar}$
% Reads from a shared borrow of a resource.
\item
$\update$:
$\forall{\kvar\kvar_\tvar}\bvar{\tvar}{\kvar_\tvar}.\
\qual{\Cleq {\kvar_\tvar} {\kun_0}}
\borrowty[\MBORROW]{\kvar}{\tapp\tres\tvar} \tarr{} \tvar \tarr{\kaff} \tunit$
% Writes to an exclusive borrow of a resource.
\item
$\destroy$:
$\forall{\kvar_\tvar}\bvar{\tvar}{\kvar_\tvar}.\
\qual{\Cleq {\kvar_\tvar} {\kun_0}}
\tapp\tres\tvar \tarr{} \tunit$
% Destroys a resource.
\end{itemize}

% \clearpage
\subsection{Semantics}
\label{sec:sem}
\input{internal-grammar}

% PT: removed style=rule
\lstMakeShortInline[keepspaces,basicstyle=\normalsize\normalfont]@

It is straightforward to give a standard semantics for \lang, but such
a semantics would not be very informative. In this section, we give a
big-step semantics that performs explicit bookkeeping of the number of
times a value is used and of the mode in which a reference to a
resource is used (e.g., borrowed or not). This bookkeeping is based on a set of permissions
that regulate the currently allowed mode of access to resources and
closures. It enables us to state and prove a highly informative type
soundness result (see \cref{sec:metatheory}) with expressive invariants that ensure proper
resource usage.

The dynamics of \lang is given in big-step
functional
style~\cite{siek13:_type_safet_three_easy_lemmas,DBLP:conf/esop/OwensMKT16,
  DBLP:conf/popl/AminR17}.  A function
@eval@
manipulates the semantic objects defined in
\cref{fig:syntax-internal-language}.
% To demonstrate resource handling, the semantics comes with an abstract
% notion of linear resources that can be created, destroyed, observed
% (through unrestricted borrows), and
% updated (through affine borrows).
%
The semantics is defined in terms of \emph{elaborated expressions} $e$
with kind, constraint, and splitting annotations inserted by the typechecker.
A splitting $\Sp$ is evidence of the splitting relation for type environments
used in the typing rules.

Let-polymorphism in the surface language gives rise to elaborated
$\eletfun$ expressions annotated with a type scheme $\schm$ and a kind $k$ indicating their
usage restriction (linear, affine, etc) relative to the variables and
constraints of $\schm$. Their use
gives rise to explicit instantiation of the kind and type variables.
Pairs come with a kind tag $k$ indicating the usage restriction.

Addresses $\Addr$ are composed of a raw location $\Loc$, which is just
a pointer into a store, and a stack of modifiers that indicates the
borrows and reborrows that have been taken from $\Loc$.
Once we have taken an unrestricted borrow (from a raw location or a borrowed
one), then we can take further unrestricted borrows from it, but no more affine
ones.

A permission $\Perm$ is a set of addresses that may be accessed during
evaluation. A well-formed permission contains at most one address for each raw
location.

Non-trivial results are boxed in the  semantics. So, a result
$r$ is either an address or a primitive constant (e.g., a number).

A value environment $\VEnv$  maps variables to results.

A storable $w$ describes the content of a location in the store. There are five
kinds of storables. A \emph{poly closure} represents a polymorphic
function. It consists of an environment and the components of an
elaborated abstraction. A \emph{closure} represents a monomorphic
function in the usual way.
% A \emph{pair}
% consists of a kind and two results.
A \emph{resource} contains
a result and the \emph{hole} $\StFreed$ fills a released location.

A store $\Store$ is a partial map from raw locations to
storables. The function
@salloc: store -> storable -> (loc *store)@ is such that
@salloc delta@ @w@ allocates an unused location in @delta@ and fills it with
@w@. It returns the location and the extended store.

The evaluation function is indexed by a step count @i@ so that each
invocation is guaranteed to terminate either with an error, a timeout,
or a result. Its return type is a monad
@'a sem@ which combines error reporting and timeout:
\begin{lstlisting}
type 'a sem = Error of string | TimeOut | Ok of 'a
val eval: store->perm->venv->int->exp->(store *perm *result) sem
\end{lstlisting}
Function @eval@ evaluates the given expression in the context of an initial store, a
permission to use addresses in the store, a value environment, and a
step count. If successful, it returns the final store, the remaining
permissions, and the actual result.

\input{fig-code}

We give some excerpts of the definition of @eval@ in
\cref{fig:big-step-interpretation} and leave the full
definition for \cref{sec:semant-defin}.
% The appendix also
% contains the semantics in mathematical notation.
The definition uses OCaml syntax with extensive pretty
printing. The pervasive @let*@ operator acts as monadic bind
for the @sem@ monad. The operator
@let*? : bool -> (unit -> 'a sem) -> 'a sem@
 converts a boolean
argument into success or failure in the monad.
\begin{lstlisting}
let (let*?) : bool -> (unit -> 'b sem) -> 'b sem =
  fun b f -> if b then f () else Error ("test failed")
\end{lstlisting}
The function header of @eval@ checks
whether time is up and otherwise proceeds processing the expression.

The @Varinst@ case corresponds to instantiation. It
obtains the variable's value, checks that it is a location, checks the
permission (the @let*?@ clause), obtains the storable $w$ at that
location, and checks that it is a poly closure (STPOLY). Next, it updates the
permission: if the poly closure is unrestricted, then the location
remains in the permission set, otherwise it is removed. Finally, we
allocate a new monomorphic closure, add it to the permissions, and
return the pointer as the result along with the updated store and
permissions.

The @App@ case implements (elaborated) function application.
We first apply the splitting @sp@ to @gamma@ and
evaluate subterm @e_1@ with its part of the environment and the
decremented timer @i'@. The result must be a location that we are
permitted to use. Moreover, there must be a monomorphic STCLOS stored
at that location. The permission to further use this closure  remains
in force only if the closure is unrestricted. Finally, we evaluate the
argument, then the function body, and return its result.

% The @Pair@ case corresponds to the \TirName{Pair} typing rule. It
% requires no new features.

The @Region@ case implements a region. It obtains the address for @x@,
the suspended binding, and extends it with the intended borrow
$\BORROW$. This extension may fail if we try to take an affine borrow
of an unrestricted borrow. Next, we rebind @x@ to the borrow's
address, extend the permission accordingly, and execute the region's
body.  Finally, we withdraw the permission and return the result.

The @Borrow@ case obtains the address for @x@, checks that it is a
borrow of the correct mode $\BORROW$ and whether it is permitted to
use it. It just returns the address.

\lstDeleteShortInline@

%%% Local Variables:
%%% mode: latex
%%% TeX-master: "main"
%%% End:


\chapter{Obesity-associated genetic signatures and pathway signatures}
\label{cha:obesity_associated_genetic_signature_and_pathway_signatures}

In this chapter, the underlying biological mechanism of the obesity-associated signatures from the CR data were investigated.
In doing so, the pathway genetic signatures from the \citet{Gatza2010a} study (GT) were utilised to determine which biological pathways the obesity-associated genetic signatures were most similar to.
First, the direction of GT pathway-associated genetic signatures were resolved, then the pathway-associated metagenes were compared with the obesity-associated metagenes, and lastly linear models were constructed based on the pathway metagenes and patient \gls{bmi} to predict the obesity-associated metagenes.

\vspace{-3mm}

\section{Pathway-associated genetic signatures from the\\\citet{Gatza2010a} study}
\label{sec:pathway_associated_genetic_signatures_from_gatza2010a_study}

\subsection{Ranking and normalisation methods for pathway metagenes}
\label{sub:ranking_and_normalisation_methods}

In the \citet{Gatza2010a} study, their data comprised of samples from different studies which were aggregated into a single data set that was \gls{mas} normalised, and the metagene scores were transformed to a scale between 0 to 1 using a probit function.
However, the analyses so far have used the \gls{rma}-normalisation method and ranked based on the number of samples present in the data (fractional ranking; \cref{sub:ranking_of_the_metagene_scores}).
To decide which normalisation methods or ranking approaches were suitable for the analysis, the different methods were compared in the GT data (\cref{sec:ranking_method_for_the_pathway_associated_genetic_signatures,sec:normalisation_method_for_pathway_associated_genetic_signature_transformation_matrices}).
Results shown in \cref{sec:ranking_method_for_the_pathway_associated_genetic_signatures} clarified that there was no substantive difference in the ranking approaches used.

Scatter plots were generated and the correlations were calculated for each of the GT pathway metagenes derived from either \gls{rma} or \gls{mas} normalised GT data (\cref{sec:normalisation_method_for_pathway_associated_genetic_signature_transformation_matrices}).
The GT pathway metagenes were generated using the transformation matrices that were derived from either the \gls{rma} or \gls{mas} normalised GT data.
From these results, it was clear the normalisation methods used on the data set had the most significant effect on the resulting metagenes, rather than the normalisation methods used to generate the transformation matrices (\cref{sec:normalisation_method_for_pathway_associated_genetic_signature_transformation_matrices}).
This meant that all of the data sets had to be normalised with a single normalisation method, so \gls{rma} was chosen as the normalisation method to be used as this method is regarded as being more reliable than the \gls{mas} method \citep{Irizarry2003}.

Another thing noted from these scatter plots was that there were some pathway signatures that were more variable than the others (\cref{sec:normalisation_method_for_pathway_associated_genetic_signature_transformation_matrices}).
As an example, the \gls{tgfb} metagenes were significantly more dispersed compared to the \gls{pr} metagenes, even though both of these metagenes were generated in the same data set through similar processes (\cref{fig:gt_rma_vs_mas}).
These differences were seen in other data sets as well (\cref{fig:appendix/gt_meta_rma_mas_other_data} in \cref{sec:normalisation_method_for_pathway_associated_genetic_signature_transformation_matrices}).
This result provided evidence that some of the pathway genetic signatures from the \citet{Gatza2010a} study were less variable across different data sets than the others.
Taken together, it was decided that the GT data set should be batch corrected first (\cref{sub:batch_correction}), then normalised with the \gls{rma} method, and the metagene scores were ranked with fractional ranking (\cref{sub:ranking_of_the_metagene_scores}).

\begin{figure}[htpb]
	\centering
	\includegraphics[page=76,width=0.45\linewidth]{results2/allmeta_rma_vs_mas}
	\includegraphics[page=100,width=0.45\linewidth]{results2/allmeta_rma_vs_mas}
	\caption[Comparison of the pathway metagenes generated in the \acrshort{mas} normalised GT data set from the application of TMs, derived from either the \acrshort{rma} or \acrshort{mas} normalised GT data]{Comparison of the pathway metagenes generated in the \acrshort{mas} normalised GT data set from the application of the transformation matrices derived from either the \acrshort{rma} or \acrshort{mas} normalised GT data.
	Only the \gls{pr} (left) and the \gls{tgfb}  (right) pathway metagenes are shown.
	The scatter plots for the other pathway metagenes are shown in \cref{sec:normalisation_method_for_pathway_associated_genetic_signature_transformation_matrices}.
	}
	\label{fig:gt_rma_vs_mas}
\end{figure}

\subsection{Pathway metagene directionality}
\label{sub:pathway_metagene_directionality}

Before GT pathway metagenes were compared with the obesity-associated metagenes, the direction of the GT pathway metagenes had to be checked to make sure that the metagenes were in the ``correct'' direction (\cref{sub:metagene_direction}).
The correlation of all the pathway metagenes with one another were plotted as a heatmap in \cref{fig:gatza_meta_dir}.
The most prominent group had five pathways (E2F1, \gls{pi3k}, Myc, \gls{bcat} and Ras) that clustered at the top left hand corner of the heatmap.
Other groups included \gls{ifna}/\gls{ifny}/\gls{tnfa} pathways, \gls{er}/\gls{pr}/p53 pathways and p63/\gls{her2} pathways.
In addition to these highly correlated groups, \gls{stat3}/\gls{tgfb}/Src/\gls{egfr}/Akt pathways showed little correlation with one another.
Comparing these groups with the results presented by \citet{Gatza2010a} (\cref{sec:result_from_gatza2010a_study}), the identified clusters approximately resembled the pathway groups identified in by Gatza \textit{et al.}, which confirmed that the directions of GT pathway metagenes were consistent with those used by Gatza \textit{et al.}.

\begin{figure}[htb]
	\centering
	\includegraphics[page=15,width=0.7\linewidth]{results2/gatza_meta_trans}
	\caption[Heatmap of the Pearson correlation of all the pathway metagenes with one another in the \acrshort{rma} normalised GT data]{Heatmap showing the Pearson correlation of all the pathway metagenes from the \citet{Gatza2010a} study with one another  in the \gls{rma} normalised GT data set.
		High and low correlation were represented as red and blue, respectively, where the colours were matched with the values on the scale shown in the top left histogram.
		Refer to \cref{tab:metagene_direction} for the detailed descriptions of the abbreviations used.
		}
	\label{fig:gatza_meta_dir}
\end{figure}

To see whether the directionality of the GT pathway metagenes were being transferred across to other data sets properly, pathway metagenes were generated in other data sets with the same transformation matrices and the groupings of the metagenes were examined.
CR, FM and \gls{nzbc} data were \gls{rma} normalised and transformation matrices of the pathway genetic signatures (derived from the GT data set) were applied to the data sets.
The metagenes were plotted in a heatmap (shown in \cref{sec:correlation_of_the_gt_pathway_metagenes_in_other_cancer_data_sets}), which showed similar groupings  as seen in \cref{fig:gatza_meta_dir}.
This result confirmed that the pathway metagenes were acting similarly in all of the data sets in which the transformation matrices have been applied to.

\section{Pathway-associated metagenes and obesity-associated metagenes}
\label{sec:pathway_associated_metagenes_and_obesity_associated_metagenes}

Results from the previous section confirmed that the pathway metagenes from the \citet{Gatza2010a} study were in the correct directions, and that the pathway metagenes were behaving as expected in the different data sets.
Now that the directions of the pathway metagenes were established, these metagenes were ready for comparison with the obesity-associated metagenes.
However, all of the pathway metagenes were derived from the GT data, whereas the majority of the obesity-associated metagenes were derived from the CR data, which presents a problem in terms of deciding which data set the transformation matrices should be generated in.

\subsection{Obesity and pathway metagene transformation matrices}
\label{sub:obesity_and_pathway_metagene_transformation_matrices}

Metagenes generated from the application of \gls{svd} and metagenes generated from the transformation matrix are exactly the same if the transformation matrix is derived from the same data set.
For example, an obesity-associated metagene generated from the CR data with \gls{svd} would have the same values as the metagenes generated in the CR data with the transformation matrix (since the transformation matrix was derived from the CR data).
Furthermore, if the \gls{svd}-derived metagenes and transformation matrix-derived metagenes were the same (or at least similar) in a different data set, this suggests that the metagene-related biology contained in the two data sets is highly similar.
In other words, the transformation matrix can be made in either the original data set or in a different data set if there was no difference in the \gls{svd}-derived or transformation matrix-derived metagenes.

To decide which data set the transformation matrices for obesity and pathway-associated genetic signatures should be generated in, the \gls{svd}- and transformation matrix(TM)-generated metagene scores were compared in all of the data sets.
As in \cref{sec:pathway_associated_genetic_signatures_from_gatza2010a_study}, all data sets were normalised with the \gls{rma} method and metagenes were ranked with fractional ranking.
TMs for the obesity-associated genetic signatures were made in the CR data set and the TMs for pathway-associated genetic signatures were made in the GT data set.
Metagenes for all of the obesity and pathway-associated genetic signatures were generated in all of the data sets with \gls{svd} and TMs.
The Spearman correlation of the \gls{svd}-generated and TM-generated metagene scores were calculated for each genetic signatures (\cref{tab:svd_vs_tm_path,tab:svd_vs_tm_obs}).

\begin{table}[tpb]
	\centering
	\begin{threeparttable}
	\caption[Summary of the Spearman correlations of the \gls{svd}- and TM-derived pathway metagenes in the GT, CR, \gls{nzbc} and FM data sets]{Summary of the Spearman correlations of the \gls{svd}- and transformation matrix\tnote{1}-derived pathway metagenes in the GT, CR, \gls{nzbc} and FM data sets}
	\label{tab:svd_vs_tm_path}
		\begin{tabular}{lcccc}
			& GT & CR & \gls{nzbc} & FM\\
			\hline
			\hline
			\rule{0pt}{2.25ex}Akt & 1.000 & 0.5190 & 0.5900 & 0.5563 \\
			\gls{bcat}            & 1.000 & 0.9897 & 0.9977 & 0.9905 \\
			E2F1                  & 1.000 & 0.9646 & 0.8438 & 0.9193 \\
			\gls{egfr}            & 1.000 & 0.0430 & 0.3358 & 0.4040 \\
			\gls{er}              & 1.000 & 0.9978 & 0.9942 & 0.9966 \\
			\gls{her2}            & 1.000 & 0.9553 & 0.5817 & 0.9794 \\
			\gls{ifna}            & 1.000 & 0.9830 & 0.9991 & 0.9951 \\
			\gls{ifny}            & 1.000 & 0.9086 & 0.9950 & 0.9718 \\
			Myc                   & 1.000 & 0.9878 & 0.9852 & 0.9689 \\
			p53                   & 1.000 & 0.3808 & 0.9981 & 0.7923 \\
			p63                   & 1.000 & 0.8319 & 0.2951 & 0.8368 \\
			\gls{pi3k}            & 1.000 & 0.9543 & 0.5989 & 0.9365 \\
			\gls{pr}              & 1.000 & 0.9511 & 0.9887 & 0.9845 \\
			Ras                   & 1.000 & 0.9078 & 0.9125 & 0.7229 \\
			Src                   & 1.000 & 0.9575 & 0.7173 & 0.9548 \\
			\gls{stat3}           & 1.000 & 0.1902 & 0.9159 & 0.6167 \\
			\gls{tgfb}            & 1.000 & 0.9918 & 0.2543 & 0.9890 \\
			\gls{tnfa}            & 1.000 & 0.6046 & 0.9365 & 0.4315 \\
			\hline
			\hline
		\end{tabular}
		\begin{tablenotes}
			\begin{footnotesize}
				\item [1] Transformation matrices were derived from the \gls{rma} normalised GT data set.
			\end{footnotesize}
		\end{tablenotes}
	\end{threeparttable}
\end{table}

\begin{table}[htpb]
	\centering
	\begin{threeparttable}
	\caption[Summary of the Spearman correlations of the \gls{svd}- and TM-derived obesity metagenes in the GT, CR, \gls{nzbc} and FM data sets]{Summary of the Spearman correlations of the \gls{svd}- and transformation matrix\tnote{1}-derived obesity metagenes in the GT, CR, \gls{nzbc} and FM data sets}
		\label{tab:svd_vs_tm_obs}
		\begin{tabular}{lcccc}
			& CR & GT & FM & \gls{nzbc}\\
			\hline
			\hline
			\rule{0pt}{2.25ex} Cr & 1.000     & 0.9985 & 0.9872 & 0.9161 \\
			Res                   & 1.000     & 0.9987 & 0.9898 & 0.9652 \\
			CrOl                  & 1.000     & 0.9982 & 0.9926 & 0.9715 \\
			ResOl                 & 1.000     & 0.9981 & 0.9927 & 0.9571 \\
			Ca                    & 1.000     & 0.9985 & 0.9893 & 0.9468 \\
			CaRes                 & 1.000     & 0.9988 & 0.9939 & 0.9865 \\
			CaOl                  & 1.000     & 0.9983 & 0.9937 & 0.9677 \\
			CaResOl               & 1.000     & 0.9984 & 0.9952 & 0.9642 \\
			Original              & 1.000     & 0.9928 & 0.9862 & 0.9344 \\
			\hline
			\hline
		\end{tabular}
			\begin{tablenotes}
				\begin{footnotesize}
				\item [1] Transformation matrices were derived from the \gls{rma} normalised CR data set.
				\end{footnotesize}
			\end{tablenotes}
	\end{threeparttable}
\end{table}

In \cref{tab:svd_vs_tm_path,tab:svd_vs_tm_obs}, the obesity and pathway-associated genetic signatures had a correlation of 1 in CR and GT data sets respectively, as the obesity and pathway TMs were generated in the CR and GT data sets, respectively.
The correlations of the obesity and pathway metagenes were variable across different data sets, which was as expected since all the data sets were different from one another.
However, what was unexpected was the fact that there were some pathway genetic signatures that were highly correlated in all of the data sets, and there were others that varied considerably across different data sets.
For example, the \gls{bcat} pathway metagene was highly correlated in all of the data sets (\textgreater{} 0.98), whereas the \gls{stat3} pathway metagene was variable across different data sets, ranging from 0.1902 to 0.9159 (\cref{tab:svd_vs_tm_path}; \cref{sec:comparison_of_the_correlation_of_svd_and_tm_generated_pathway_metagenes}).
The fact that some pathway-associated metagenes were consistent across different data sets suggested that some of these genetic signatures were reliable and did not depend on the data set the transformation matrices were derived from.
Adding to this, there were very little overlap in the genes between the different pathway-associated genetic signatures, suggesting that the consistency across the data sets were not due to an artefact that was affecting the dominant probe set in the signatures (\cref{sec:overlap_of_the_genes_between_the_pathway_associated_signatures}).
On the other hand, the genetic signatures that were not consistent across the data sets were likely to be dependent on the data set in which they were derived from, and therefore the transformation matrices for these signatures must be derived from the GT data set.
This also showed that the tumour biology may be different across the data sets, likely due to the difference in the patient cohorts that were selected for each of the studies.

In contrast to the pathway-associated genetic signatures, all of the obesity-associated genetic signatures showed high correlation for the \gls{svd}- and transformation matrix-generated metagenes across the different data sets.
This suggested that the obesity-associated genetic signatures were relatively consistent across all data sets, and the transformation matrices for these signatures could be made in any of the data sets.
For simplicity, it was decided that the transformation matrices for all the genetic  signatures would be made in the GT data set, since there were some pathway-associated signatures that were specific to the GT data.

\subsection{Comparison of the obesity and pathway-associated signatures}
\label{sub:comparison_of_the_obesity_and_pathway_associated_signatures}

To visually determine which pathway-associated genetic signatures were most similar to the obesity-associated genetic signatures, heatmaps were created with the metagenes for all of the genetic signatures.
The directions of the pathway-associated metagenes have already been determined in \cref{sec:pathway_associated_genetic_signatures_from_gatza2010a_study}, and the directions of the obesity-associated metagenes were checked in GT data set as described in \cref{sub:metagene_direction}.
All of the metagenes were created in the GT data set (normalised with \gls{rma}) using \gls{svd}, and the metagene scores were plotted in a heatmap and clustered into groups (\cref{fig:gatza_allmeta}).

\begin{figure}[tb]
	\centering
	\includegraphics[page=15,width=0.8\linewidth]{results2/all_meta_trans}
	\caption[Heatmap of the Pearson correlation of all the pathway and obesity metagenes with one another in the \acrshort{rma}-normalised GT data]{Heatmap showing the Pearson correlation of all the pathway and obesity metagenes  with one another  in the \gls{rma}-normalised GT data set.
		High and low correlation were represented as red and blue, respectively, where the colours were matched with the values on the scale shown in the top left histogram.
		Refer to \cref{tab:metagene_direction,tab:mg_abbrev} for the detailed descriptions of the abbreviations used.
		}
	\label{fig:gatza_allmeta}
\end{figure}

In \cref{fig:gatza_allmeta}, all of the obesity-associated metagenes from the CR data set cluster together into a group, but none of the pathway-associated metagenes had  a strong positive correlation with the obesity metagenes.
Though the  \gls{her2} and p63 pathway metagenes were grouped next to the cluster of obesity metagenes, the similarity was at most about 0.6  (Pearson correlation; \cref{fig:gatza_allmeta}).
With that said, these obesity-associated metagenes seem to have a strong negative correlation with some of the pathway-associated genetic signatures, such as the Akt, \gls{er}, \gls{egfr}, \gls{pr}, p53, Src and \gls{tgfb} pathways, and this strong negative correlation was observed in the other data sets as well (\cref{sec:correlation_of_the_pathway_and_obesity_metagenes_in_other_cancer_data_sets}).
In fact,  high Or metagene scores related to lower levels of gene expression for the genes in the Or signature (\cref{fig:crmetaheat}; \cref{sec:creighton_obesity_metagene}), and therefore it could be possible that many of the genes in the Or signature (and the other obesity-associated signatures from the CR data) may be positively correlated with the genes in these pathway signatures.
This suggests that the obesity-associated genetic signatures from the CR data may be related to these pathway signatures, rather than the obesity phenotype of the patients.

The FM obesity-associated metagene did not cluster together with the obesity metagenes from the CR data set, nor with any of the other pathway metagenes.
The fact that the FM metagene did not cluster with any of the CR metagenes showed that the signals captured by the FM metagene was different from those metagenes found in the CR data set.
Furthermore, the FM metagene did not cluster with the Akt pathway in the heatmap, even though \citet{Fuentes-Mattei2014} provided clear evidence that their metagene specifically activated the Akt/\gls{mtor} signalling pathway in a mouse model.
This may have been due to the lack of consistency of the Akt pathway signature in the different data sets (\cref{tab:svd_vs_tm_path}).
Another likely reason could be that FM genetic signature was not comprised only of the genes from the Akt pathway, but genes from the other pathways as well, and so the metagene did not cluster together with the Akt pathway signature in the heatmap.

The results in this section suggested that none of the obesity-associated genetic signatures were positively correlated with any of the pathway-associated genetic signatures from the \citet{Gatza2010a} study.
However, some pathway signatures were negatively correlated with the obesity-associated genetic signatures, which meant that the obesity signatures were likely capturing the signals from these signatures  rather than the biological signals from the obesity phenotype of the patient.

\vspace{-3mm}

\section{Prediction of obesity-associated metagenes with pathway-associated metagenes}
\label{sec:prediction_of_obesity_associated_metagene_with_pathway_associate_metagene}

To confirm the biological relationship between the obesity-associated metagenes with the pathway-associated metagenes from the \citet{Gatza2010a} study, linear models were created to predict the obesity metagene scores with the pathway metagene scores.
If any of the pathway metagenes were significant in the linear model, this would provide evidence that the significant pathways in the linear model were related to the obesity metagene.
Since most of the obesity metagenes were found in the CR data set, and only the CR and the \gls{nzbc} data sets had \gls{bmi} information for the patients, \gls{nzbc} data set was used as the training data set to create the linear models for obesity metagene score prediction.

\subsection{Linear model prediction in the \gls{nzbc} and CR data sets}
\label{sub:linear_model_prediction_in_the_nzbc_and_cr_data_sets}

Metagene scores used for the construction of linear models were generated from the application of the transformation matrices derived from the GT data (from \cref{sec:pathway_associated_metagenes_and_obesity_associated_metagenes}) to \gls{rma} normalised \gls{nzbc} data.
From \cref{tab:svd_vs_tm_path}, it was evident that some pathway-associated genetic signatures could be variable across different data sets.
Therefore, only six pathways (\gls{bcat}, \gls{er}, \gls{ifna}, \gls{ifny}, Myc and \gls{pr}) that were ``consistent'' (correlation \textgreater{} 0.9) across all of the data sets were used to construct the linear models.

For each of the obesity metagenes identified, seven linear models were created: \gls{bmi}-only, \gls{bmi} status-only, \gls{bmi} and \gls{bmi} status, pathway metagenes-only, and the combinations of pathway metagenes with \gls{bmi} and/or \gls{bmi} status.
The only variables that showed significance in any of the models that predicted the obesity metagenes taken from the CR data set were the \gls{pr} metagene and whether the patients were obese or not (\cref{tab:lm_sig_var}).
In the model that predicted the FM metagene scores, the obesity status of the patients and Myc metagene score were significant, but the \gls{pr} metagene score was not (\cref{sec:summary_of_the_linear_models_in_nzbc_data}).

\begin{table}[htpb]
	\centering
	\caption{Description of the linear models constructed from the \gls{nzbc} data to predict the Cr obesity metagene}
	\label{tab:lm_sig_var}
	\begin{threeparttable}
		\begin{tabular}{llrr}
			Linear Model & Variables & Estimate & P-value\\
			\hline
			\hline
			\rule{0pt}{2.25ex}\gls{bmi} only                           & \gls{bmi}  & -0.0016 & 0.717\\
			\hline
			\rule{0pt}{2.25ex}\gls{bmi} status only                    & Overweight & -0.0126 & 0.871\\
                                                                       & Obese      & -0.0981 & 0.166\\
			\hline
			\rule{0pt}{2.25ex}\gls{bmi} and \gls{bmi} status           & \gls{bmi}  & 0.0109  & 0.123\\
                                                                       & Overweight & -0.0687 & 0.420\\
                                                                       & Obese      & -0.2481 & \textbf{0.040}\tnote{1}\\
			\hline
			\rule{0pt}{2.25ex}Pathways only                            & \gls{bcat} & 0.0916  & 0.677\\
                                                                       & \gls{er}   & 0.0523  & 0.834\\
                                                                       & \gls{ifna} & -0.4993 & 0.307\\
                                                                       & \gls{ifny} & 0.4224  & 0.398\\
                                                                       & Myc        & -0.0038 & 0.987\\
                                                                       & \gls{pr}   & 0.5836  & \textbf{0.016}\\
			\hline
			\rule{0pt}{2.25ex}\gls{bmi} and Pathways                   & \gls{bmi}  & -0.0024 & 0.527\\
                                                                       & \gls{bcat} & 0.1121  & 0.614\\
                                                                       & \gls{er}   & 0.0540  & 0.829\\
                                                                       & \gls{ifna} & -0.5383 & 0.276\\
                                                                       & \gls{ifny} & 0.4661  & 0.358\\
                                                                       & Myc        & 0.0168  & 0.941\\
                                                                       & \gls{pr}   & 0.5927  & \textbf{0.015}\\
			\hline
			\rule{0pt}{2.25ex}\gls{bmi} status and Pathways            & Overweight & -0.0120 & 0.864\\
                                                                       & Obese      & -0.1035 & 0.113\\
                                                                       & \gls{bcat} & 0.1495  & 0.501\\
                                                                       & \gls{er}   & 0.0326  & 0.896\\
                                                                       & \gls{ifna} & -0.6707 & 0.177\\
                                                                       & \gls{ifny} & 0.5888  & 0.245\\
                                                                       & Myc        & 0.0439  & 0.846\\
                                                                       & \gls{pr}   & 0.5799  & \textbf{0.016}\\
			\hline
			\rule{0pt}{2.25ex}\gls{bmi}, \gls{bmi} status and pathways & \gls{bmi}  & 0.0091  & 0.161\\
                                                                       & Overweight & -0.0576 & 0.455\\
                                                                       & Obese      & -0.2292 & \textbf{0.040}\\
                                                                       & \gls{bcat} & 0.1460  & 0.509\\
                                                                       & \gls{er}   & 0.0091  & 0.971\\
                                                                       & \gls{ifna} & -0.6937 & 0.161\\
                                                                       & \gls{ifny} & 0.5890  & 0.243\\
                                                                       & Myc        & 0.0263  & 0.907\\
                                                                       & \gls{pr}   & 0.5449  & \textbf{0.024}\\
			\hline
			\hline
		\end{tabular}
		\begin{tablenotes}
			\begin{footnotesize}
				\item [1] All values in bold are statistically significant (p \textless{} 0.05).
			\end{footnotesize}
		\end{tablenotes}
	\end{threeparttable}
\end{table}

The models constructed from the patient \gls{bmi}, \gls{bmi} status and/or GT pathway metagene scores confirmed that none of the pathways were significant, except for the \gls{pr} and Myc pathway metagene scores in the models for the CR metagenes and the FM metagene, respectively.
It was not surprising that the \gls{pr} pathway metagene showed significance in the models generated in \gls{nzbc} data set, as majority of the patients in the \gls{nzbc} data set were \gls{pr}$^+$ (\cref{tab:clin_summary}).
The significance of the Myc metagene in the model for FM metagene was difficult to interpret, as there was no reported association of the FM metagene with the Myc pathway by \citet{Fuentes-Mattei2014}.
\textit{MYC} is an oncogene that encodes the Myc transcription factor that, when overexpressed, disrupts various pathways that directly promote tumour growth and proliferation, and has a central role in many of the cancer hallmarks \citep{Coller2000,Hanahan2000}.
``Sustained cell proliferation'' was one of the cancer hallmarks that \citet{Fuentes-Mattei2014} had shown to be related to their obesity-associated genetic signature, which could be the reason that the Myc pathway metagene showed up as a significant variable in the linear model.
Since the \gls{pr} pathway metagene showed significant association in many of the linear models, linear models were made with each of the combinations of \gls{bmi}, \gls{bmi} status and \gls{pr} pathway metagene for all of the obesity-associated metagenes (\cref{tab:lm_pr_only}; \cref{sec:summary_of_the_linear_models_in_nzbc_data}).
As expected, all of the linear models showed significant contribution of the \gls{pr} metagene scores to the model for all obesity metagenes (except FM metagene; \cref{sec:summary_of_the_linear_models_in_nzbc_data}).

\begin{table}[tpb]
	\centering
	\caption[Description of the linear models constructed from the \gls{nzbc} data to predict the Cr obesity, using only the patient \gls{bmi}, \gls{bmi} status and the \acrshort{pr} pathway metagene score]{Description of the linear models constructed from the \gls{nzbc} data to predict the Cr obesity, using only the patient \gls{bmi}, \gls{bmi} status and the \gls{pr} pathway metagene score}
	\label{tab:lm_pr_only}
	\begin{threeparttable}
			\begin{tabular}{llrS}
				Linear Model & Variables & Estimate & {P-value}\\
				\hline
				\hline
				\rule{0pt}{2.25ex}\gls{pr} only                            & \gls{pr}   & 0.477  & {\bfseries \num{6.06d-7}}\tnote{1}\\
				\hline
				\rule{0pt}{2.25ex}\gls{bmi} and \gls{pr}                   & \gls{bmi}  & -0.002 & 0.586\\
                                                                           & \gls{pr}   & 0.478  & {\bfseries \num{6.35d-7}}\\
				\hline
				\rule{0pt}{2.25ex}\gls{bmi} status and \gls{pr}            & Obese      & -0.085 & 0.176\\
                                                                           & Overweight & -0.011 & 0.875\\
                                                                           & \gls{pr}   & 0.471  & {\bfseries \num{8.25d-7}}\\
				\hline
				\rule{0pt}{2.25ex}\gls{bmi}, \gls{bmi} status and \gls{pr} & \gls{bmi}  & 0.007  & 0.237\\
                                                                           & Obese      & -0.188 & 0.081\\
                                                                           & Overweight & -0.049 & 0.516\\
                                                                           & \gls{pr}   & 0.459  & {\bfseries \num{1.54d-6}}\\
				\hline
				\hline
			\end{tabular}
			\begin{tablenotes}
				\begin{footnotesize}
					\item [1] All values in bold are statistically significant (p \textless{} 0.05).
				\end{footnotesize}
			\end{tablenotes}
	\end{threeparttable}
\end{table}

To determine whether any of the linear models were able to predict the corresponding obesity metagene scores, the predicted metagene scores were generated from the models and then compared with the original scores.
The original obesity metagene scores from the \gls{nzbc} were generated from the application of TM that were derived from the \gls{rma}-normalised GT data set.
These \gls{nzbc} obesity metagene scores were then compared with the metagene scores that were predicted by the linear models (\cref{fig:predict_cris_cris}).

The predicted metagenes from all of the patient \gls{bmi}-related linear models were not significantly related to the original metagene scores in many of the obesity metagenes (\cref{fig:predict_cris_cris}; \cref{sec:summary_of_the_linear_models_in_nzbc_data}).
On the other hand, all of the predicted metagenes generated from the models that used the pathway metagene scores showed significant association with the original metagene scores (\cref{fig:predict_cris_cris}; \cref{sec:summary_of_the_linear_models_in_nzbc_data}).
However, the $R^2$ values for all of the predicted metagenes against the original metagenes were very low ($R^2$ \textless{} 0.4).
All of the plots in \cref{fig:predict_cris_cris,sec:summary_of_the_linear_models_in_nzbc_data} showed clearly that the data points in the scatter plots were highly variable, suggesting that even though the association between the predicted and the true metagene scores were statistically significant, the variables in the linear models may not be strongly associated to the obesity metagene.
Furthermore, the fact that all of the predictions made with the models that contained the \gls{pr} metagene showed greater correlation with the true metagene values suggested that most of the variations in the Cr (and other) obesity metagenes were being explained by the \gls{pr} metagene alone, and the patient \gls{bmi} contributed very little to the prediction.

\begin{figure}[htpb]
	\centering
	\includegraphics[page=1,width=0.32\linewidth]{results2/prediction_cris_with_cris(cris_model)}
	\includegraphics[page=2,width=0.32\linewidth]{results2/prediction_cris_with_cris(cris_model)}
	\includegraphics[page=3,width=0.32\linewidth]{results2/prediction_cris_with_cris(cris_model)}
	\includegraphics[page=4,width=0.32\linewidth]{results2/prediction_cris_with_cris(cris_model)}
	\includegraphics[page=5,width=0.32\linewidth]{results2/prediction_cris_with_cris(cris_model)}
	\includegraphics[page=6,width=0.32\linewidth]{results2/prediction_cris_with_cris(cris_model)}
	\includegraphics[page=7,width=0.32\linewidth]{results2/prediction_cris_with_cris(cris_model)}
	\includegraphics[page=74,width=0.32\linewidth]{results2/prediction_cris_with_cris(cris_model)}
	\includegraphics[page=71,width=0.32\linewidth]{results2/prediction_cris_with_cris(cris_model)}
	\includegraphics[page=72,width=0.32\linewidth]{results2/prediction_cris_with_cris(cris_model)}
	\includegraphics[page=73,width=0.32\linewidth]{results2/prediction_cris_with_cris(cris_model)}
	\caption[Comparison of the predicted Cr metagene scores with the Cr metagene score from the \gls{nzbc} data]{ Box plot and scatter plots comparing the Cr metagene score predicted by the different linear models constructed from the \gls{nzbc} data, with the Cr metagene score from the \gls{nzbc} data.
	Only the results from the models used to predict the Cr metagene scores are shown.
	The summary of the statistics for the other obesity metagene predictions from the \gls{nzbc} data are shown in \cref{sec:summary_statistics_of_the_predicted_obesity_metagenes_with_sample_bmi_bmi_status_in_nzbc_and_cr_data}.
	P-values and $R^2$-value are as described in previous figures.
	}
	\label{fig:predict_cris_cris}
\end{figure}

To confirm the results shown in the \gls{nzbc} data set (the training set), the linear models were applied to CR data (the test set).
As shown in \cref{fig:predict_cr_cris}, all of the predicted Cr metagene generated from the linear models were statistically significantly associated with the true Cr metagenes in CR data, but there were some exceptions in the models for the other obesity metagenes (\cref{sec:summary_statistics_of_the_predicted_obesity_metagenes_with_sample_bmi_bmi_status_in_nzbc_and_cr_data}).
Similar to the results from the \gls{nzbc} data set, all of the $R^2$ values were low ($R^2$ \textless{} 0.43) in the CR data set and the data points were widely spread out in the plots.
Again, these results suggested that the predicted metagene scores from the linear models may be statistically significant, but may not be relevant to the obesity metagenes which the models predict, as the predicted values were only weakly associated with the true values.

Another thing to note from \cref{fig:predict_cr_cris} was the apparent negative association of the predicted metagenes with the original metagenes in the \gls{bmi}-only, the \gls{bmi} status-only and the \gls{bmi} and \gls{bmi} status models.
One possible explanation for this was that these \gls{bmi}-based models were overfitted in the \gls{nzbc} data set, and was not generalisable in the CR data set, and thus produced negative correlations.
In fact, it was evident from the metagene analyses in \cref{cha:obesity_genetic_signatures_and_cancer} that these obesity-associated genetic signatures were not generalisable with the patient \gls{bmi} in different data sets, and overfitting of the model in the \gls{nzbc} data was the likely cause of this negative correlation.

\begin{figure}[htpb]
	\centering
	\includegraphics[page=1,width=0.32\linewidth]{results2/prediction_cr_with_cris}
	\includegraphics[page=2,width=0.32\linewidth]{results2/prediction_cr_with_cris}
	\includegraphics[page=3,width=0.32\linewidth]{results2/prediction_cr_with_cris}
	\includegraphics[page=4,width=0.32\linewidth]{results2/prediction_cr_with_cris}
	\includegraphics[page=5,width=0.32\linewidth]{results2/prediction_cr_with_cris}
	\includegraphics[page=6,width=0.32\linewidth]{results2/prediction_cr_with_cris}
	\includegraphics[page=7,width=0.32\linewidth]{results2/prediction_cr_with_cris}
	\includegraphics[page=74,width=0.32\linewidth]{results2/prediction_cr_with_cris}
	\includegraphics[page=71,width=0.32\linewidth]{results2/prediction_cr_with_cris}
	\includegraphics[page=72,width=0.32\linewidth]{results2/prediction_cr_with_cris}
	\includegraphics[page=73,width=0.32\linewidth]{results2/prediction_cr_with_cris}
	\caption[Comparison of the predicted Cr metagene scores with the Cr metagene score from the CR data]{ Box plot and scatter plots comparing the Cr metagene score predicted by the different linear models constructed from the \gls{nzbc} data, with the Cr metagene score from the CR data.
	Only the results from the models used to predict the Cr metagene scores are shown.
	The summary of the statistics for the other obesity metagene predictions from the CR data are shown in \cref{sec:summary_statistics_of_the_predicted_obesity_metagenes_with_sample_bmi_bmi_status_in_nzbc_and_cr_data}.
	P-values and $R^2$-value are as described in previous figures.
	}
	\label{fig:predict_cr_cris}
\end{figure}

\subsection{Stepwise linear model prediction in \gls{nzbc} and CR data sets}
\label{sub:stepwise_linear_model_prediction_in_nzbc_and_cr_data_sets}

Lastly, since only the six most ``consistent'' pathway metagenes were picked from a total of eighteen pathway metagene scores, linear models were constructed with all eighteen pathway metagenes in a stepwise fashion.
Step wise construction of a linear model is where the variables for a model are selected computationally depending on the contribution of the variable to the resulting linear model, and thus contain only the variables that ``matter'' to the final linear model \cref{sec:obesity_metagene_prediction_with_pathway_metagenes}.
Patient \gls{bmi}, \gls{bmi} status and all of the pathway metagenes (Akt, \gls{bcat}, E2F1, \gls{egfr}, \gls{er}, \gls{her2}, \gls{ifna}, \gls{ifny}, Myc, p53, p63, \gls{pi3k}, \gls{pr}, Ras, \gls{stat3}, Src, \gls{tgfb} and \gls{tnfa}) were used to generate the stepwise linear model for each of the obesity metagenes.
The linear models that resulted from the stepwise selection of the variables were summarised in \cref{tab:stepwise_model}.

These models were used to predict the obesity metagenes in the \gls{nzbc} data to test the performance of the models.
All of the models were able to make statistically significant prediction of the original obesity metagenes in the \gls{nzbc} data set (\cref{fig:stepwise_cris}).
Unlike the previous models, the stepwise models showed very high $R^2$ values, where most predictions had $R^2$ \textgreater{} 0.80.
The statistical significance and the strong association of the predicted metagenes were observed in the CR data set as well (\cref{fig:stepwise_cr}).
Though the $R^2$ values were slightly lower than those from the \gls{nzbc} data set, the $R^2$ values from the CR data predictions were more promising than the predictions made by the non-stepwise linear models.

\begin{ThreePartTable}
	\begin{TableNotes}
		\begin{footnotesize}
		\item [1] All values in bold are statistically significant (p \textless{} 0.05).
		\end{footnotesize}
	\end{TableNotes}
	\begin{longtable}{llr{\bfseries}S}
		\centering
		\caption[Description of the stepwise linear models constructed from the \gls{nzbc} data to predict all of the obesity metagenes]{Description of the stepwise linear models constructed from the \gls{nzbc} data to predict all of the obesity metagenes}
		\label{tab:stepwise_model}\\
			Obesity metagene & Variables retained in the model & Estimate & {P-value}\\
			\hline
		\endfirsthead
		\multicolumn{4}{c}{\tablename\ \thetable{}\ (continued)}\\
			\hline
			\hline
		\endhead
			\hline
			\hline
			Cr      & Src         & -0.1900  & \bfseries 0.005150\tnote{1}       \\
					& \gls{egfr}  & 0.1451   & \bfseries 0.002780                \\
					& \gls{tgfb}  & 0.5105   & \bfseries \num{1.17d-15}          \\
					& Akt         & -0.2821  & \bfseries \num{7.08d-06}          \\
					& \gls{ifna}  & -0.06968 & \bfseries 0.02986                 \\
			\hline
			CrOl    & Akt         & -0.3134  & \bfseries \num{1.76d-06}          \\
					& Src         & -0.5386  & \bfseries \textless{} \num{2d-16} \\
					& p53         & 0.3372   & \bfseries \num{9.18d-07}          \\
					& \gls{pr}    & -0.1115  & \bfseries 0.02760                 \\
			\hline
			Res     & \gls{tgfb}  & -0.5895  & \bfseries \num{1.53d-15}          \\
					& \gls{egfr}  & -0.3597  & \bfseries 0.0005390               \\
					& \gls{tnfa}  & 0.1604   & \bfseries 0.0006970               \\
					& \gls{bcat}  & -0.2141  & \bfseries 0.01157                 \\
					& Akt         & 0.1527   & \bfseries 0.02206                 \\
			\hline
			ResOl   & Akt         & -0.2802  & \bfseries 0.0001420               \\
					& Src         & -0.5214  & \bfseries \num{2.65d-15}          \\
					& p53         & 0.2861   & \bfseries \num{5.31d-07}          \\
			\hline
			Ca      & \gls{tgfb}  & 0.7470   & \bfseries \textless{} \num{2d-16} \\
					& Akt         & -0.2985  & \bfseries \num{2.83d-10}          \\
			\hline
			CaOl    & Src         & -0.5595  & \bfseries \num{3.88d-16}          \\
					& Akt         & -0.4331  & \bfseries \num{2.06d-11}          \\
			\hline
			CaRes   & \gls{tgfb}  & 0.7843   & \bfseries \textless{} \num{2d-16} \\
					& \gls{egfr}  & 0.2418   & \bfseries \num{2.19d-06}          \\
			\hline
			CaResOl & Src         & -0.4553  & \bfseries \num{1.57d-07}          \\
					& \gls{egfr}  & 0.2776   & \bfseries 0.0009570               \\
					& Akt         & -0.3001  & \bfseries 0.0001640               \\
					& E2F1        & 0.2484   & \bfseries 0.001300                \\
					& Myc         & 0.1584   & \bfseries 0.025220                \\
			\hline
			Or      & Src         & -0.5165  & \bfseries \textless{} \num{2d-16} \\
					& p53         & 0.3072   & \bfseries \num{2.60d-12}          \\
					& Akt         & -0.3006  & \bfseries 1.440e-07               \\
					& E2F1        & 0.09684  & \bfseries 0.01070                 \\
					& Obese       & -0.02190 & 0.2166                            \\
					& Overweight  & 0.03099  & 0.1223                            \\
			\hline
			FM      & p63         & 0.3507   & \bfseries 0.0006760               \\
					& \gls{stat3} & 0.2969   & \bfseries 0.004191                \\
					& p53         & 0.5368   & \bfseries 0.0008240               \\
					& \gls{pr}    & -0.3462  & \bfseries 0.034070                \\
			\hline
			\hline
			\insertTableNotes
	\end{longtable}
\end{ThreePartTable}

Clearly, the stepwise linear models were able to predict the obesity-associated metagenes better than the models created in \cref{sub:linear_model_prediction_in_the_nzbc_and_cr_data_sets}.
This could be due to the fact that many of the stepwise linear models included many pathways that had a strong negative correlation with the obesity metagenes (Akt, \gls{er}, \gls{egfr}, \gls{pr}, p53, Src and \gls{tgfb} pathways; \cref{fig:gatza_allmeta}).
These pathway metagenes may have been better predictors of the obesity metagenes than the six pathways that were ``consistent'' across the data sets, and therefore generated better predictions than those linear models.
With that said, some of the predicted obesity metagenes from the stepwise linear models were negatively correlated with the original metagene values in the CR data (\cref{fig:stepwise_cr}).
Again, this could have been due to the model being overfit in the \gls{nzbc} data, and thus making an incorrect prediction about the obesity metagenes in the CR data.

\begin{figure}[htpb]
	\centering
	\includegraphics[page=1,width=0.32\linewidth]{results2/stepwise_cris_both_bic}
	\includegraphics[page=2,width=0.32\linewidth]{results2/stepwise_cris_both_bic}
	\includegraphics[page=3,width=0.32\linewidth]{results2/stepwise_cris_both_bic}
	\includegraphics[page=4,width=0.32\linewidth]{results2/stepwise_cris_both_bic}
	\includegraphics[page=5,width=0.32\linewidth]{results2/stepwise_cris_both_bic}
	\includegraphics[page=6,width=0.32\linewidth]{results2/stepwise_cris_both_bic}
	\includegraphics[page=7,width=0.32\linewidth]{results2/stepwise_cris_both_bic}
	\includegraphics[page=8,width=0.32\linewidth]{results2/stepwise_cris_both_bic}
	\includegraphics[page=9,width=0.32\linewidth]{results2/stepwise_cris_both_bic}
	\includegraphics[page=10,width=0.32\linewidth]{results2/stepwise_cris_both_bic}
	\caption[Comparison of all the obesity metagene scores predicted from the stepwise linear models with the original obesity metagene scores from the \gls{nzbc} data]{Scatter plots comparing all of the obesity metagene scores predicted by the stepwise linear models constructed from the \gls{nzbc} data, with the corresponding obesity metagene scores from the \gls{nzbc} data.
	P-values and $R^2$-value are as described in previous figures.}
	\label{fig:stepwise_cris}
\end{figure}

\begin{figure}[htpb]
	\centering
	\includegraphics[page=1,width=0.32\linewidth]{results2/stepwise_cr_both_bic}
	\includegraphics[page=2,width=0.32\linewidth]{results2/stepwise_cr_both_bic}
	\includegraphics[page=3,width=0.32\linewidth]{results2/stepwise_cr_both_bic}
	\includegraphics[page=4,width=0.32\linewidth]{results2/stepwise_cr_both_bic}
	\includegraphics[page=5,width=0.32\linewidth]{results2/stepwise_cr_both_bic}
	\includegraphics[page=6,width=0.32\linewidth]{results2/stepwise_cr_both_bic}
	\includegraphics[page=7,width=0.32\linewidth]{results2/stepwise_cr_both_bic}
	\includegraphics[page=8,width=0.32\linewidth]{results2/stepwise_cr_both_bic}
	\includegraphics[page=9,width=0.32\linewidth]{results2/stepwise_cr_both_bic}
	\includegraphics[page=10,width=0.32\linewidth]{results2/stepwise_cr_both_bic}
	\caption[Comparison of all the obesity metagene scores predicted from the stepwise linear models with the original obesity metagene scores from the CR data]{Scatter plots comparing all of the obesity metagene scores predicted by the stepwise linear models constructed from the \gls{nzbc} data, with the corresponding obesity metagene scores from the CR data.
	P-values and $R^2$-value are as described in previous figures.}
	\label{fig:stepwise_cr}
\end{figure}

Taken together, these results suggest that the variables included in these stepwise models were relevant to the biology of the obesity metagenes identified in the CR and FM data sets.
However, there were no common pathways that were present in all of the models; although Akt, \gls{egfr}, \gls{tgfb} and Src pathway metagenes were frequently included in many of the stepwise models.
The role of the pathways included in the models and the possible biological links of these pathways to the obesity metagenes remain unclear, and should be the focus for future investigations.


\newpage
\section{Implementation}\paragraph{}
Our cloud is represented by a 3D texture and a collection of billboards. To create our clouds we consider 3 major steps. The first is spherical voxelization of the billboards, the second is voxel cone tracing through the volume, and the third is noise generation.

\input{voxelization}
\input{conetracing}
\input{noise}


\subsection{Age stratification}
All compartments of this base compartmental structure were stratified by age into five-year bands from 0-4 years of age through to 70-74 years of age, with the final age group being those aged 75 years and older. Heterogeneous baseline contact patterns by age were incorporated using age-specific contact rates estimated from survey data from the POLYMOD study, which reported rates of age-specific contacts in various locations between persons of different age groupings (as described below \ref{matrix_construction}). These are then modified by non-pharmaceutical interventions. Our modelled age groups were chosen to match these mixing matrices. The automatic demographic features of the platform that can be used to simulate births, ageing and deaths were not implemented, because the issues considered pertain to the short- to medium-term and the immediate implementation of control strategies, for which population demographics are less relevant.


\section{Basal Boundary Condition}
The Section describes the formulation of the basal boundary condition.
An interface for the upper boundary condition (atmospheric BC) is easily defined by the surface temperature and mass balance. Similarly, the basal boundary consists of mechanical and thermal boundary conditions. The complications arise because the thermal and mechanical boundary conditions depend on each other. The interface of the basal boundary can be described with the following fields (see also Fig.\ref{num.fig.basal_bc}):
\begin{enumerate}
\item \textbf{basal traction:} this field specifies a parameter which is used to allow basal sliding.
\item \textbf{basal heat flux:} heat flux entering the ice sheet from below.
\item \textbf{basal water depth:} the presence of basal melt water affects the basal ice temperature
\end{enumerate}
Additionally, the ice sheet model calculates a melt/freeze rate based on the temperature gradient and basal water depth. This is handled by GLIDE.

\begin{figure}[htbp]
  \centering
  \includegraphics[width=0.9\textwidth]{\dir/figs/basal_bc.eps}
  \caption{Basal boundary condition.}
  \label{num.fig.basal_bc}
\end{figure}

\subsection{Mechanical Boundary Conditions}
If the ice is not frozen to the bed, basal d\'{e}collement may occur. This can be parameterised by a traction factor, $t_b$. Within the ice sheet model $t_b$ is used to either calculate basal sliding velocities, $\vec{u}_b$, in the case of zeroth order physics, i.e.
\begin{equation}
  \vec{u}_b=t_b\vec{\tau}_b
\end{equation}
where $\tau_b$ is the basal shear stress. Alternatively, $t_b$ can be used as part of the stress--balance calculations when the model is used with higher order physics. In simple models $t_b$ may be uniform or prescribed as a spatial variable. More complex models may wish to make $t_b$ dependant on other variables, e.g. basal melt rate. Typically $t_b$ will depend on the presence of basal water.

The second mechanical boundary condition, basal melting/freeze--on $\dot{B}$, is handled within the ice sheet model. The details are described in Section \ref{num.sec.bc_melt}.

\subsection{Thermal Boundary Conditions}
The thermal boundary condition at the ice base is more complicated than the mechanical BC. The ice is heated from below by the geothermal heat flux. Heat is generated by friction with the bed. Furthermore, the ice temperature is constrained to be smaller or equal to the pressure melting point of ice. The thermal boundary is set to the basal heat flux if there is no water present. If there is water, the thermal boundary condition is set to the pressure melting temperature\footnote{if it was lower there would be no water, if it was higher than there would be no ice}.

\subsubsection{Basal Melting and Freezing}\label{num.sec.bc_melt}
At the ice base, $z=h$, we can define outgoing and incoming heat fluxes, $H_o$ and $H_i$:
\begin{subequations}
  \begin{align}
    H_o&=-k_{\text{ice}}\left.\frac{\pd T}{\pd z}\right|_{z=h^+}\\
    \intertext{and}
    H_i&=-k_{\text{rock}}\left.\frac{\pd T}{\pd z}\right|_{z=h^-}+\vec{u}_b\cdot\vec{\tau}_b+
    \begin{cases}
      {\rho_{\text{ice}}\dot{B}}/{L} & \text{when $\dot{B}<0$} \\
      0 & \text{otherwise}
    \end{cases}
  \end{align}
\end{subequations}
where $k_{\text{ice}}$ and $k_{\text{rock}}$ are the thermal conductivities of ice and rock, $\vec{u}_b\cdot\vec{\tau}_b$ is the heat generated by friction with the bed and $L$ is the latent heat of fusion of pure water. The basal melt/freeze--on rate, $\dot{B}$ can then be calculated from the difference between the incoming and outgoing heat fluxes:
\begin{equation}
  \label{bc.eq.meltrate}
  \dot{B}=\frac{H_o-H_i}{\rho_{\text{ice}}L}
\end{equation}
Freeze--on occurs if $\dot{B}$ is negative, basal melting occurs if $\dot{B}$ is positive.

\input{\dir/gthf.tex}

\subsection{Basal Hydrology}
It is clear from the discussion above that the presence of basal water plays a crucial role in specifying both the mechanical and thermal boundary conditions. However, the treatment of basal water can vary greatly. Basal water is, therefore, left as an unspecified interface. GLIDE does provide a simple local water balance model which can be run in the absence of more complex models.

\subsection{Putting It All Together}
The basal boundary consists of the individual components described in the previous sections. All components are tightly linked with each other. Figure \ref{num.fig.bc_flow} illustrates how the modules are linked and in what order they are resolved.
\begin{figure}[htbp]
  \centering
  \includegraphics[width=\textwidth]{\dir/figs/basal_alg.eps}
  \caption{Flow diagram illustrating how the various modules communicate with each other by exchanging data fields.}
  \label{num.fig.bc_flow}
\end{figure}
The order of executions is then:
\begin{enumerate}
\item Find the basal heat flux by either solving the equation describing the thermal evolution of the lithosphere, Eq. \eqref{num.eq.diffu_rock}, or by using the geothermal heat flux directly. The upper boundary condition of \eqref{num.eq.diffu_rock} is the same as the lower boundary condition of the thermal evolution of the ice sheet.
\item The lower boundary condition for the thermal evolution of the ice sheet is either given by the basal heat flux from \emph{Step 1}; or if melt water is present the basal temperature is set to the pressure melting point of ice.
\item Calculate the temperature distribution within the ice sheet given the boundary condition found during \emph{Step 2} and the atmospheric BC.
\item Calculate a melt/freeze--on rate using Equation \eqref{bc.eq.meltrate} given the outgoing heat flux calculated during \emph{Step 3}, friction with the bed (calculated during the previous \emph{Step 7}) and the incoming heat flux from \emph{Step 1}. Freezing only occurs when there is basal water.
\item Track basal water. This is a user supplied module which can take any complexity. Inputs will typically be the melt/freeze--on rate determined during \emph{Step 4}.
\item Calculate the basal traction parameter. Again, this is a user supplied module which typically will involve the presence of basal melt water (calculated during \emph{Step 5}).
\item Solve the mechanical ice equations given basal traction parameter from \emph{Step 6}.
\end{enumerate}
Clearly, this scheme has the problem that heat is lost if the basal heat flux is such that more water could be frozen than is available. This might be avoided by iterating the process. On the other hand if time steps are fairly small this might no matter to much.


\hypertarget{structIir_1_1ChebyshevII_1_1BandPass}{}\doxysubsection{Iir\+::Chebyshev\+II\+::Band\+Pass$<$ Filter\+Order, State\+Type $>$ Struct Template Reference}
\label{structIir_1_1ChebyshevII_1_1BandPass}\index{Iir::ChebyshevII::BandPass$<$ FilterOrder, StateType $>$@{Iir::ChebyshevII::BandPass$<$ FilterOrder, StateType $>$}}

{\ttfamily \#include $<$Chebyshev\+I\+I.\+h$>$}

Inheritance diagram for Iir\+::Chebyshev\+II\+::Band\+Pass$<$ Filter\+Order, State\+Type $>$\+:\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[height=2.434783cm]{structIir_1_1ChebyshevII_1_1BandPass}
\end{center}
\end{figure}
\doxysubsubsection*{Public Member Functions}
\begin{DoxyCompactItemize}
\item
void \mbox{\hyperlink{structIir_1_1ChebyshevII_1_1BandPass_a7fcada7f9376bd6cf0d99a18aa62ee32}{setup}} (double sample\+Rate, double center\+Frequency, double width\+Frequency, double stop\+Band\+Db)
\item
void \mbox{\hyperlink{structIir_1_1ChebyshevII_1_1BandPass_a1157ea7f70718df1e2983fb0f576931f}{setup}} (int req\+Order, double sample\+Rate, double center\+Frequency, double width\+Frequency, double stop\+Band\+Db)
\item
void \mbox{\hyperlink{structIir_1_1ChebyshevII_1_1BandPass_a6044cfbd6da7f2f6f78e9a2d969038d3}{setupN}} (double center\+Frequency, double width\+Frequency, double stop\+Band\+Db)
\item
void \mbox{\hyperlink{structIir_1_1ChebyshevII_1_1BandPass_ad17b6f448cb0395d0a4fe4843ac0c44b}{setupN}} (int req\+Order, double center\+Frequency, double width\+Frequency, double stop\+Band\+Db)
\end{DoxyCompactItemize}

\doxysubsubsection{Detailed Description}
\subsubsection*{template$<$int Filter\+Order = 4, class State\+Type = Direct\+Form\+II$>$\newline
struct Iir\+::\+Chebyshev\+I\+I\+::\+Band\+Pass$<$ Filter\+Order, State\+Type $>$}

\mbox{\hyperlink{namespaceIir_1_1ChebyshevII}{Chebyshev\+II}} bandpass filter
\begin{DoxyParams}{Parameters}
{\em Filter\+Order} & Reserves memory for a filter of the order Filter\+Order \\
\hline
{\em State\+Type} & The filter topology\+: \mbox{\hyperlink{classIir_1_1DirectFormI}{Direct\+FormI}}, \mbox{\hyperlink{classIir_1_1DirectFormII}{Direct\+Form\+II}}, ... \\
\hline
\end{DoxyParams}

\doxysubsubsection{Member Function Documentation}
\mbox{\Hypertarget{structIir_1_1ChebyshevII_1_1BandPass_a7fcada7f9376bd6cf0d99a18aa62ee32}\label{structIir_1_1ChebyshevII_1_1BandPass_a7fcada7f9376bd6cf0d99a18aa62ee32}}
\index{Iir::ChebyshevII::BandPass$<$ FilterOrder, StateType $>$@{Iir::ChebyshevII::BandPass$<$ FilterOrder, StateType $>$}!setup@{setup}}
\index{setup@{setup}!Iir::ChebyshevII::BandPass$<$ FilterOrder, StateType $>$@{Iir::ChebyshevII::BandPass$<$ FilterOrder, StateType $>$}}
\doxyparagraph{\texorpdfstring{setup()}{setup()}\hspace{0.1cm}{\footnotesize\ttfamily [1/2]}}
{\footnotesize\ttfamily template$<$int Filter\+Order = 4, class State\+Type  = Direct\+Form\+II$>$ \\
void \mbox{\hyperlink{structIir_1_1ChebyshevII_1_1BandPass}{Iir\+::\+Chebyshev\+I\+I\+::\+Band\+Pass}}$<$ Filter\+Order, State\+Type $>$\+::setup (\begin{DoxyParamCaption}\item[{double}]{sample\+Rate,  }\item[{double}]{center\+Frequency,  }\item[{double}]{width\+Frequency,  }\item[{double}]{stop\+Band\+Db }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [inline]}}

Calculates the coefficients of the filter
\begin{DoxyParams}{Parameters}
{\em sample\+Rate} & Sampling rate \\
\hline
{\em center\+Frequency} & Center frequency of the bandpass \\
\hline
{\em width\+Frequency} & Width of the bandpass \\
\hline
{\em stop\+Band\+Db} & Permitted ripples in dB in the stopband \\
\hline
\end{DoxyParams}
\mbox{\Hypertarget{structIir_1_1ChebyshevII_1_1BandPass_a1157ea7f70718df1e2983fb0f576931f}\label{structIir_1_1ChebyshevII_1_1BandPass_a1157ea7f70718df1e2983fb0f576931f}}
\index{Iir::ChebyshevII::BandPass$<$ FilterOrder, StateType $>$@{Iir::ChebyshevII::BandPass$<$ FilterOrder, StateType $>$}!setup@{setup}}
\index{setup@{setup}!Iir::ChebyshevII::BandPass$<$ FilterOrder, StateType $>$@{Iir::ChebyshevII::BandPass$<$ FilterOrder, StateType $>$}}
\doxyparagraph{\texorpdfstring{setup()}{setup()}\hspace{0.1cm}{\footnotesize\ttfamily [2/2]}}
{\footnotesize\ttfamily template$<$int Filter\+Order = 4, class State\+Type  = Direct\+Form\+II$>$ \\
void \mbox{\hyperlink{structIir_1_1ChebyshevII_1_1BandPass}{Iir\+::\+Chebyshev\+I\+I\+::\+Band\+Pass}}$<$ Filter\+Order, State\+Type $>$\+::setup (\begin{DoxyParamCaption}\item[{int}]{req\+Order,  }\item[{double}]{sample\+Rate,  }\item[{double}]{center\+Frequency,  }\item[{double}]{width\+Frequency,  }\item[{double}]{stop\+Band\+Db }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [inline]}}

Calculates the coefficients of the filter
\begin{DoxyParams}{Parameters}
{\em req\+Order} & Requested order which can be less than the instantiated one \\
\hline
{\em sample\+Rate} & Sampling rate \\
\hline
{\em center\+Frequency} & Center frequency of the bandpass \\
\hline
{\em width\+Frequency} & Width of the bandpass \\
\hline
{\em stop\+Band\+Db} & Permitted ripples in dB in the stopband \\
\hline
\end{DoxyParams}
\mbox{\Hypertarget{structIir_1_1ChebyshevII_1_1BandPass_a6044cfbd6da7f2f6f78e9a2d969038d3}\label{structIir_1_1ChebyshevII_1_1BandPass_a6044cfbd6da7f2f6f78e9a2d969038d3}}
\index{Iir::ChebyshevII::BandPass$<$ FilterOrder, StateType $>$@{Iir::ChebyshevII::BandPass$<$ FilterOrder, StateType $>$}!setupN@{setupN}}
\index{setupN@{setupN}!Iir::ChebyshevII::BandPass$<$ FilterOrder, StateType $>$@{Iir::ChebyshevII::BandPass$<$ FilterOrder, StateType $>$}}
\doxyparagraph{\texorpdfstring{setupN()}{setupN()}\hspace{0.1cm}{\footnotesize\ttfamily [1/2]}}
{\footnotesize\ttfamily template$<$int Filter\+Order = 4, class State\+Type  = Direct\+Form\+II$>$ \\
void \mbox{\hyperlink{structIir_1_1ChebyshevII_1_1BandPass}{Iir\+::\+Chebyshev\+I\+I\+::\+Band\+Pass}}$<$ Filter\+Order, State\+Type $>$\+::setupN (\begin{DoxyParamCaption}\item[{double}]{center\+Frequency,  }\item[{double}]{width\+Frequency,  }\item[{double}]{stop\+Band\+Db }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [inline]}}

Calculates the coefficients of the filter
\begin{DoxyParams}{Parameters}
{\em center\+Frequency} & Normalised centre frequency (0..1/2) of the bandpass \\
\hline
{\em width\+Frequency} & Width of the bandpass \\
\hline
{\em stop\+Band\+Db} & Permitted ripples in dB in the stopband \\
\hline
\end{DoxyParams}
\mbox{\Hypertarget{structIir_1_1ChebyshevII_1_1BandPass_ad17b6f448cb0395d0a4fe4843ac0c44b}\label{structIir_1_1ChebyshevII_1_1BandPass_ad17b6f448cb0395d0a4fe4843ac0c44b}}
\index{Iir::ChebyshevII::BandPass$<$ FilterOrder, StateType $>$@{Iir::ChebyshevII::BandPass$<$ FilterOrder, StateType $>$}!setupN@{setupN}}
\index{setupN@{setupN}!Iir::ChebyshevII::BandPass$<$ FilterOrder, StateType $>$@{Iir::ChebyshevII::BandPass$<$ FilterOrder, StateType $>$}}
\doxyparagraph{\texorpdfstring{setupN()}{setupN()}\hspace{0.1cm}{\footnotesize\ttfamily [2/2]}}
{\footnotesize\ttfamily template$<$int Filter\+Order = 4, class State\+Type  = Direct\+Form\+II$>$ \\
void \mbox{\hyperlink{structIir_1_1ChebyshevII_1_1BandPass}{Iir\+::\+Chebyshev\+I\+I\+::\+Band\+Pass}}$<$ Filter\+Order, State\+Type $>$\+::setupN (\begin{DoxyParamCaption}\item[{int}]{req\+Order,  }\item[{double}]{center\+Frequency,  }\item[{double}]{width\+Frequency,  }\item[{double}]{stop\+Band\+Db }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [inline]}}

Calculates the coefficients of the filter
\begin{DoxyParams}{Parameters}
{\em req\+Order} & Requested order which can be less than the instantiated one \\
\hline
{\em center\+Frequency} & Normalised centre frequency (0..1/2) of the bandpass \\
\hline
{\em width\+Frequency} & Width of the bandpass \\
\hline
{\em stop\+Band\+Db} & Permitted ripples in dB in the stopband \\
\hline
\end{DoxyParams}

The documentation for this struct was generated from the following file\+:\begin{DoxyCompactItemize}
\item
iir/Chebyshev\+I\+I.\+h\end{DoxyCompactItemize}