\documentclass{beamer}
\usefonttheme[onlymath]{serif}
\usetheme[numbering=fraction, progressbar=frametitle]{metropolis}
\usepackage{appendixnumberbeamer}
\useoutertheme[footline=empty,subsection=false]{miniframes}
\useinnertheme{circles}
% \setbeamertemplate{headline}{%
%     \begin{beamercolorbox}[colsep=1.5pt]{upper separation line head}
%     \end{beamercolorbox}
%     \begin{beamercolorbox}{section in head/foot}
%     \vskip2pt\insertsectionnavigationhorizontal{\paperwidth}{}{}\vskip2pt
%         \end{beamercolorbox}%
%         \begin{beamercolorbox}[colsep=1.5pt]{lower separation line head}
%     \end{beamercolorbox}
% }

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{textcomp}
\usepackage{amsmath, amssymb, amsthm}

\usepackage[style=authoryear,maxbibnames=9,maxcitenames=2,uniquelist=false,backend=biber,doi=false,url=false]{biblatex}
\renewcommand*{\nameyeardelim}{\addcomma\space} % have comma in parencite
\addbibresource{$BIB} % bibtex location
%%% Small bibliography slide
\setbeamertemplate{bibliography item}[triangle]
\makeatletter
\newcommand{\srcsize}{\@setfontsize{\srcsize}{6.5pt}{6.5pt}}
\makeatother
\renewcommand*{\bibfont}{\srcsize}

\usepackage{import}
\usepackage{pdfpages}
\usepackage{transparent}
\usepackage{xcolor}

\newcommand{\blue}[1]{\textcolor{blue}{#1}}
\newcommand{\red}[1]{\textcolor{red}{#1}}

\graphicspath{ {./figures} }
\newcommand{\inkfig}[2][1]{%
    \def\svgwidth{#1\columnwidth}
    \import{./figures/}{#2.pdf_tex}
}

%%%%%% Template
\usepackage{hyperref}
\definecolor{links}{HTML}{2A1B81}

%% beaver (red) style:
% \usecolortheme{beaver}
% \setbeamercolor{block body}{bg=gray!30!white}
% \setbeamercolor{block title}{bg=darkred!70, fg=black!2}
% \hypersetup{colorlinks=true,allcolors=red}

%% seahorse style:
\usecolortheme{seahorse}
\setbeamercolor{block body}{bg=mDarkTeal!30}
\setbeamercolor{block title}{bg=mDarkTeal,fg=black!2}
\hypersetup{colorlinks=true,allcolors=links}
%%%%%% Template

\pdfsuppresswarningpagegroup=1

\title{Review of Mathematics}
\author{\textit{Hui-Jun Chen}}
\date{\today}

\begin{document}

\maketitle

\section{Area Formula}%
\label{sec:area_formula}

\begin{frame}[t]{Area Formula: Triangle}
    \centering
    \includegraphics[width=0.5\textwidth]{./figures/triArea2.jpg}
    \begin{itemize}
        \item Area formula: $\frac{1}{2}  \times a  \times h$
    \end{itemize}
\end{frame}

\begin{frame}[t]{Area Formula: Rectangle}
    \centering
    \includegraphics[width=0.7\textwidth]{./figures/qwe.jpg}
    \begin{itemize}
        \item Area formula: $length \times  width$
    \end{itemize}

\end{frame}

\begin{frame}[t]{Area Formula: Trapezoid}
    \centering
    \includegraphics[width=0.4\textwidth]{./figures/trapezoid.png}
    \begin{itemize}
	\item Area formula: $\frac{\left( b_{1} + b_{2}  \right) }{2}  \times h$
	\item Or separate into two triangles and one rectangle
    \end{itemize}
\end{frame}

\section{Basic Algebra Review}%
\label{sec:basic_algebra_review}

\begin{frame}[t]{Basic Algebra Review: properties}
    \begin{itemize}
        \item Associative properties:
	    \begin{itemize}
		\item additive: $a + \left( b+c \right) = \left( a+b \right) +c$
		\item multiplicative: $a\left( bc \right) = \left( ab \right) c$
	    \end{itemize}
	\item Commutative properties:
	    \begin{itemize}
		\item additive: $a+b = b+a$
		\item multiplicative: $ab = ba$
	    \end{itemize}
	\item Distributive properties: $a\left( b+c \right) = ab + ac$
	\item Properties for exponents:
	    \begin{itemize}
	        \item $a^{x} a^{y} = a^{x+y} $; $\frac{a^{x} }{a^{y} } = a^{x-y} $
		\item $\left( ab \right)^{x} = a^{x} b^{x} $; $\left( \frac{a}{b}  \right)^{x} = \frac{a^{x} }{b^{x} } $
		\item $\left( a^{x}  \right)^{y} = a^{xy} $
	    \end{itemize}
    \end{itemize}
\end{frame}

\begin{frame}[t]{Basic Algebra Review: properties (Cont.)}
    \begin{itemize}
        \item Properties for fractions:
	    \begin{itemize}
		\item $a\left( \frac{b}{c}  \right) = \frac{ab}{c} $
		    \vspace{0.5em}
		\item $\frac{\frac{a}{c} }{b} = \red{\frac{a}{bc}} $
		    \vspace{0.5em}
		\item $\frac{\frac{a}{c} }{\frac{b}{d} } = \frac{ad}{bc} $
		    \vspace{0.5em}
		\item $\frac{a}{b} + \frac{c}{d} = \frac{ad + bc}{bd} $
		\item $\frac{a}{b} - \frac{c}{d} = \frac{ad - bc}{bd} $
	    \end{itemize}
    \end{itemize}
\end{frame}

\begin{frame}[t]{Axioms of Equality}
    \begin{itemize}
        \item $a+b = c  \implies a = c - b$
	\item $a - b = c  \implies a = c + b$
	\item $ab = c  \implies a = \frac{c}{b} $
	\item $\frac{a}{b} = c  \implies a = bc$
    \end{itemize}
\end{frame}

\section{Calculus}%
\label{sec:calculus}

\begin{frame}[t]{Introductory Example}
    \begin{itemize}
	\item Function: how $y$ is gotten from $x$, written as $y = f\left( x \right) $.
	    \begin{itemize}
	        \item E.g.,  $y = 3x+2$: if $x=3$, then $3$ times  $3$ and plus $2$ will get $y=11$.
	    \end{itemize}
	\item Differentiation: how the value of $y$ changes when the value of $x$ changes.
	    \begin{itemize}
	        \item E.g., $y = 3x+2$,
		    \begin{table}[htpb]
		        \centering
		        \caption{Table for how the value of $x$ affects the value of $y$}
		        \label{tab:Table-for-how-the-value-of-x-affects-the-value-of-y-}
		        \begin{tabular}{cccccc}
			    $x$ & $1$ &  $2$ &  $3$ & $4$ & $5$ \\
			    \hline
			    $y$ & $5$ & $8$ & $11$ & $14$ & $17$ \\
		        \end{tabular}
		    \end{table}
		    \textbf{Notice $ \Delta x = 1 \implies  \Delta y = 3  \implies  \frac{ \Delta y}{ \Delta x} = 3 $}, change to differentiation notation, $\frac{dy}{dx}  = 3$
	    \end{itemize}
	\item  \textbf{Tips}: $y = 3x^{2} + 9x  + 2 $, look at terms with $x$,  $dy = 3 \times 2 x\left( dx \right) + 9 \left( dx \right)   \implies \frac{dy}{dx} = 6x+9  $
    \end{itemize}
\end{frame}

\begin{frame}[t]{Notation and Convention}
    \begin{itemize}
	\item Function is a mapping from argument to outcome:
	    \begin{itemize}
	        \item $y = f\left( x \right) $: $f$ describes a mapping from argument $x$ to outcome $y$
	    \end{itemize}
	\item Differentiation: given mapping $f$, how much $y$ would change ($dy$) if x change a fixed amoung  ($dx$)
	\item First derivative: $y = f\left( x \right)  \implies  \frac{dy}{dx} $ or $f'\left( x \right) $
	    \begin{itemize}
		\item the ``change'' itself
	        \item  \textbf{Example:} $y = x^{  \alpha  }  \implies \frac{dy}{dx} =  \alpha x^{ \alpha - 1}  $
	    \end{itemize}
	\item Partial derivative: $y = f\left( x, z \right)  \implies \frac{\partial y}{\partial x} $
	    \begin{itemize}
	    \item  \textbf{Example: } $y = x^{ \alpha } z^{1- \alpha }  \implies \frac{\partial y}{\partial x} =  \alpha x^{ \alpha - 1} z^{1- \alpha }; \frac{\partial y}{\partial z} = \left( 1- \alpha  \right) x^{ \alpha } z^{- \alpha }  $
	    \end{itemize}
	\item Second derivative: $y = f\left( x \right)  \implies \frac{d^{2} f}{dx^{2} } $ or $f''\left( x \right) $
	     \begin{itemize}
		 \item the speed of ``change''
		 \item  \textbf{Example: } $y = x^{ \alpha }  \implies \frac{d^{2} f}{dx^{2} } =  \alpha \left(  \alpha -1 \right) x^{ \alpha -2} $
	     \end{itemize}
    \end{itemize}
\end{frame}

\begin{frame}[t]{Production}
    Average Production of Labor (APL): $y = f\left( x \right)  \implies APL = \frac{y}{x} = \frac{f\left( x \right) }{x} $
    \centering
    \includegraphics[width=0.8\textwidth]{./figures/production-1.png}
\end{frame}

\begin{frame}[t]{Production (Cont.)}
    Marginal Production of Labor (MPL): $y = f\left( x \right)  \implies MPL = \frac{dy}{dx} = \frac{df\left( x \right) }{dx} $
    \centering
    \includegraphics[width=0.8\textwidth]{./figures/production-2.png}

\end{frame}

\begin{frame}[t]{Concave / Convex and Diminishing MPL}
    \begin{columns}
	\begin{column}{0.37\textwidth}
	    \centering
	    \includegraphics[width=\textwidth]{./figures/production-3.png}
        \end{column}
	\begin{column}{0.63\textwidth}
	    \begin{itemize}
	        \item Concave v.s. Convex: Is production function looks like a ``cave''?
		\item Concave function: whenever study hour increases by 1 unit, the speed of increase in grade point is decreasing.
		\begin{itemize}
		    \item  $\implies $ decreasing MPL
		\end{itemize}
	    \end{itemize}
	\end{column}
    \end{columns}
\end{frame}

\begin{frame}[t]{Application of Differentiation: Elasticity}
    \begin{definition}[The ``A'' Elasticity of ``B'']
	percentage change in ``B'' when ``A'' changes by $1\%$, i.e., $-\frac{\%  \Delta B}{\%  \Delta A} $
    \end{definition}
    \begin{definition}[The price elasticity of quantity demanded]
	percentage change in quantity demanded when price changes by $1\%$, i.e., $-\frac{\%  \Delta Q}{\%  \Delta P} $
    \end{definition}
    \begin{itemize}
	\item Calculate percentage: $\frac{\text{value}}{\text{total amount}}  \times 100 \% $
        \item Expand the $\%  \Delta $ part: $\% \Delta Q = \frac{ \Delta Q}{Q} $
	\item Use differentiation notation: $\% \Delta Q = \frac{ \Delta Q}{Q} = \frac{d Q}{Q}  $
	\item Rewrite Def of elasticity: $-\frac{\%  \Delta Q}{\%  \Delta P} = \left. - \frac{dQ}{Q} \middle/ \frac{dP}{P} \right.  = -\frac{P}{Q} \frac{dQ}{dP} $
    \end{itemize}
\end{frame}

\begin{frame}[standout]{Technological Progress Example: Numerically calculating $ \pi  $}
\label{slide:Example_of_Technological_Progress__Numerically_calculating____pi___}

    --\href{https://www.youtube.com/watch?v=gMlf1ELvRzc}{The Discovery That Transformed Pi} by \href{https://www.youtube.com/channel/UCHnyfMqiRRG1u-2MsSQLbXA}{Veritasium }

\end{frame}

\end{document}


%%!TEX TS-program = xelatexmk
\documentclass[ignorenonframetext,aspectratio=169]{beamer}
\title{\S49 Connection}
\author{MATH-UA 120.005 Discrete Mathematics \\ Prof. Leingang}
\date{December 5, 2019}
\usepackage{siunitx}
\usepackage{textcomp}
\usetheme{Gotham}

\let\defined\textbf

%% Contents of discrete.sty
\RequirePackage{amsmath}
\RequirePackage{amsfonts}
\RequirePackage{amssymb}
\RequirePackage{mathtools}
\providecommand{\Z}{\mathbb{Z}}
\providecommand{\Q}{\mathbb{Q}}
\providecommand{\R}{\mathbb{R}}
\providecommand{\N}{\mathbb{N}}
\newcommand{\divides}{\mathrel{|}}
\newcommand{\ndivides}{\mathrel{\nmid}}

  % \subsection{Boolean algebra}
\newcommand{\ltrue}{\textsc{true}}
\newcommand{\lfalse}{\textsc{false}}
\newcommand{\limplies}{\rightarrow}
\newcommand{\lseilpmi}{\leftarrow}
\newcommand{\liff}{\leftrightarrow}
\newcommand{\lnand}{\barwedge}
\newcommand{\lxor}{\veebar}
\providecommand{\set}[1]{\left\{#1\right\}}
\let\setst\outer
\renewcommand{\setst}[2]{\left\{#1 : #2 \right\}}
\providecommand{\union}{\cup}
\providecommand{\intersect}{\cap}
\newcommand{\setdiff}{-}
\let\origsetminus\setminus
\renewcommand{\setminus}{\setdiff}
\newcommand{\symdiff}{\mathbin{\triangle}}
\newcommand{\PowerSet}[1]{2^{#1}}
\newcommand{\Card}[1]{\left|#1\right|}
\newcommand{\raa}{$\Rightarrow\Leftarrow$}
\newcommand{\dom}[1]{\operatorname{dom}#1}
\newcommand{\im}[1]{\operatorname{im}#1}
\providecommand{\comp}{\mathrel{\raisebox{0.175ex}{$\scriptstyle\circ$}}}
\providecommand{\from}{\colon}
\newcommand{\IdentityFunction}[1][\relax]{%
    \mathord{\mathrm{id}}\ifx#1\relax\else_{#1}\fi
}
\providecommand{\sgn}{\operatorname{sgn}}
\providecommand{\idiv}{\mathbin{\text{div}}}
%% end of discrete.sty

\usepackage{tikz}
\usetikzlibrary{patterns}
\colorlet{primary}{cyan}
\tikzset{onslide/.code args={<#1>#2}{%
  \only<#1>{\pgfkeysalso{#2}}
}}

\tikzset{simple graph/.style={
    every edge/.append style={thick},
    dot/.style={draw,circle,inner sep=0pt,minimum width=1ex},
    vertex/.style={dot},
}}
\newcommand{\tikzmark}[1]{\tikz[overlay,remember picture] \node (#1) {};}
\usetikzlibrary{decorations}

\begingroup
\usebeamercolor{block title example}
\xglobal\colorlet{example}{bg}
\endgroup

\usepackage{hyperref}
\begin{document}

\begin{frame}%
    \maketitle
    \begin{tikzpicture}[remember picture,overlay]
        \node[
anchor=south west, at={([xshift=1mm,yshift=1mm]current page.south west)}
        ]
        {\includegraphics[width=2.5in]{NYUCourant}};
    \end{tikzpicture}
\end{frame}

\section*{Announcements}
\timecheck{\LARGE\clock{11}{00}}

\begin{frame}{It's the final countdown}%
\begin{itemize}
\item Dec 3: Quiz on \S36 and \S47; Cover \S48 Subgraphs
\item Dec 5: \S49 Connection
\item Dec 6: HW on \S36 and \S47 due
\item Dec 10: Quiz on \S\S48–49; Cover \S50 Trees
\item Dec 12: \S51 Eulerian Graphs
\item Dec 13: HW on \S\S48--49 not due;
\item Dec 17, 8:00 AM in CIWW 101: Review for final
\item Dec 19, 8:00 AM: Final Exam
\end{itemize}
\end{frame}

\begin{frame}{Motivation}
\begin{itemize}
\item We like road systems that allow us to get from point $A$ to point $B$ for all $A$ and $B$.
\item The importance of the internet is that any computer can send a message to any other computer
\item Kevin Bacon numbers for actors, Erd\H os numbers for mathematicians
\item An electrical company may need to identify its most critical lines
\end{itemize}
\end{frame}

\mode<article>{%
\section*{Objectives}
}% end mode<article>

\begin{frame}{Objectives}
\begin{columns}
\begin{column}{0.65\textwidth}
\begin{itemize}
    \item Define and use the is-connected-to relation on the set of vertices of a graph
    \item Define and identify the connected components of a graph
    \item Define and identify the cut edges of a graph.
\end{itemize}
\end{column}
\begin{column}{0.25\textwidth}
\mode<presentation>{\includegraphics[width=\textwidth]{Anonymous_target_with_arrow}}
\end{column}
\end{columns}
\end{frame}

\subsection*{Notes}

See also:
\begin{itemize}%%%
\item Fall 2019: tweaking colors
\item Spring 2019: slidified.  Still pretty thin; needs worksheet and pictures.
\item Spring 2018: \href{https://www.evernote.com/shard/s2/nl/210343/c9a0520f-8e6d-42fa-b0e2-8056a0964ece/}{Notes in Evernote}
\end{itemize}

\section*{Materials}

\begin{itemize}
\item Colored chalk/markers
\end{itemize}

\mode<article>{
\section*{Do Now}}

\begin{frame}[label=do-now]
\begin{columns}
\begin{column}{0.45\textwidth}
\begin{exampleblock}<+->{Do Now}%%
Let $G$ be the graph below.
\begin{center}
     \begin{tikzpicture}[scale=0.4,simple graph]
     \begin{scope}[x={(0cm,1bp)},y={(-1bp,0cm)}]
     \begin{scope}[every node/.append style={vertex}]
         \draw (173.0,306.0) node[label=$1$] (n0) {};
         \draw (27.0,234.0)  node[label=180:$2$] (n1) {};
         \draw (99.0,234.0)  node[label=$3$] (n2) {};
         \draw (82.0,90.0)   node[label=$4$] (n3) {};
         \draw (137.0,162.0) node[label=-25:$5$] (n4) {};
         \draw (154.0,90.0)  node[label=$6$] (n5) {};
         \draw (118.0,18.0)  node[label=45:$7$] (n6) {};
         \path (n0) edge (n1) edge (n4) edge (n5) edge[out=15,in=105] (n6)
               (n1) edge (n4) edge[out=-15,in=255] (n6)
               (n2) edge (n3) edge (n4)
               (n3) edge (n6)
               (n4) edge (n5) edge (n6)
               (n5) edge (n6)
          ;
     \end{scope}
     \end{scope}
     \end{tikzpicture}
\end{center}
Find $\omega(G)$ and $\alpha(G)$.
\end{exampleblock}
\end{column}
\begin{column}{0.45\textwidth}
\begin{solution}<+->
\begin{itemize}
\item<.->     There is a clique of size $4$: $\set{1,5,2,7}$.
    But there are no cliques of size $5$.  That would require five vertices of degree at least $4$,
    and there are only two ($1$ and $7$).
    So $\omega(G) = 4$.
\item<+->
    There are two independent sets of size $3$:
        $\set{2,3,6}$ and $\set{2,4,6}$.
    So $\alpha(G) = 3$.
\end{itemize}
\end{solution}
\end{column}
\end{columns}
\end{frame}

\mode<article>{%
\section*{Anticipatory Set}}
\timecheck{\LARGE\clock{09}{15}}

\tableofcontents

\mode<article>{%
\section*{Procedure}}
\timecheck{\LARGE\clock{09}{00}}

\section{Walks}

\begin{frame}[label=walk-def]
\begin{definition}
    Let $G=(V,E)$ be a graph.
    A \defined{walk} in $G$ is a list (or finite sequence) of vertices
    with each adjacent to the next.  We write it as
    \[
        W = (v_0,v_1,\dots,v_\ell)
    \]
    where $v_i \in V$ for all $i$, and $v_{i-1} \sim v_i$ for each $i$ from $1$ to $\ell$.
\end{definition}
\begin{itemize}
\item We sometimes write a walk with the vertices separated by $\sim$:
\[
    W = v_0 \sim v_1 \sim \dots \sim v_\ell
\]
\item The \defined{length} of a walk is the number of edges traversed in the sequence
($\ell$)
\end{itemize}
\end{frame}

\begin{frame}[label=walk-ex]%
\begin{example}<+->
{\usebeamercolor{block title example}\xglobal\colorlet{efg}{bg}}
Using the same graph as in the Do Now, here are some walks:
\begin{columns}
\begin{column}{0.45\textwidth}
    \centering%
     \begin{tikzpicture}[scale=0.4,simple graph,
         walk/.style={preaction={draw,ultra thick,efg}}
     ]
     \begin{scope}[x={(0cm,1bp)},y={(-1bp,0cm)}]
     \begin{scope}[every node/.append style={vertex}]
         \draw (173.0,306.0)
               node[onslide={<2,3,4,5>{walk}},label=$1$] (n0) {};
         \draw (27.0,234.0)
               node[onslide={<4,5>{walk}},label=180:$2$] (n1) {};
         \draw (99.0,234.0)
               node[label=$3$] (n2) {};
         \draw (82.0,90.0)   node[label=$4$] (n3) {};
         \draw (137.0,162.0)
               node[onslide={<3,4,5>{walk}},label=-25:$5$] (n4) {};
         \draw (154.0,90.0)
               node[onslide={<3,5>{walk}},label=$6$] (n5) {};
         \draw (118.0,18.0)
               node[onslide={<3,5>{walk}},label=45:$7$] (n6) {};
         \path (n0) edge[onslide={<4>{walk}}] (n1)
                    edge[onslide={<3,4,5>{walk}}] (n4) edge (n5)
                    edge[out=15,in=105,onslide={<0>{walk}}] (n6)
               (n1) edge[onslide={<4,5>{walk}}] (n4) edge[out=-15,in=255] (n6)
               (n2) edge (n3) edge (n4)
               (n3) edge (n6)
               (n4) edge[onslide={<3,5>{walk}}] (n5)
                    edge[onslide={<5>{walk}}] (n6)
               (n5) edge[onslide={<3,5>{walk}}] (n6)
          ;
     \end{scope}
     \end{scope}
     \end{tikzpicture}
\end{column}
\begin{column}{0.45\textwidth}
\begin{itemize}
\item<+-> $1$
\item<+-> $1 \sim 5 \sim 6 \sim 7$
\item<+-> $1 \sim 5 \sim 2 \sim 1$
\item<+-> $1 \sim 5 \sim 6 \sim 7 \sim 5 \sim 2$
\end{itemize}
\end{column}
\end{columns}

\end{example}
\end{frame}

\Do{Remarks:
\begin{itemize}
\item Walks can go nowhere.
\item Walks can visit a vertex more than once.
\item Walks can be reversed.
\item Walks can come back to where they started.
\item Walks must traverse edges.
\end{itemize}
}

\begin{frame}[label=concat-def]
\begin{definition}
Suppose that $W_1 = v_0 \sim v_1 \sim \dots \sim v_\ell$ and
$W_2 = w_0 \sim w_1 \sim \dots \sim w_k$
are walks with $v_\ell = w_0$.  The \defined{concatenation} of $W_1$ and $W_2$
is the walk
\[
   W_1 + W_2 = v_0 \sim v_1 \sim \dots \sim (v_\ell = w_0) \sim w_1 \sim \dots \sim w_k
\]
\end{definition}
\begin{itemize}
\item This walk has length $\ell+k$.
\item Not every pair of walks can be concatenated
\item Even if you can concatenate in the opposite order, walk concatenation is not usually commutative
\end{itemize}
\end{frame}

\section{Paths}

\begin{frame}[label=path-def]
\begin{definition}
    If $u$ and $v$ are vertices, a \defined{walk from $u$ to $v$} or \defined{$(u,v)$-walk} is a walk that starts at $u$ and ends at $v$:
    \[
        W = u \sim \dots \sim v
    \]
\end{definition}
\begin{definition}
    A \defined{path} in $G$ is a walk in which no vertex is repeated.
    A \defined{path from $u$ to $v$} or \defined{$(u,v)$-path} is a path that starts at $u$ and ends at $v$.
\end{definition}
\end{frame}

\begin{frame}[label=path-prop]
\begin{block}<+->{Proposition 49.4}
    Let $P$ a path in a graph $G$.  then $P$ does not traverse any edge of $G$ more than once.
\end{block}
\begin{proof}<+->
Suppose $P$ traverses an edge $uv$ twice.  The possibilities are (without loss of generality):
\begin{gather*}
 \dots \sim u \sim v \sim \dots \sim u \sim v \sim \dots \\
\dots \sim u \sim v \sim \dots \sim v \sim u \sim \dots \\
\dots \sim u \sim v \sim u \sim \dots
\end{gather*}
Each of these repeats a vertex ($u$ or $v$), so is not a path.
\end{proof}
\end{frame}

\begin{frame}[label=path-graph-def]
We defined a path to be a sequence of vertices, but the edges joining the vertices
can also be included to form a graph.  So when convenient, we'll consider paths as graphs too.
\begin{definition}
    Let $n$ be a positive integer.
    The \defined{path graph} on $n$ vertices is the graph $P_n$ whose vertices
    are $\set{v_1,v_2,\dots,v_n}$, and whose edges are
    $\set{\set{v_1,v_2},\set{v_2,v_3},\dots,\set{v_{n-1},v_n}}$.
\end{definition}
\end{frame}

\begin{frame}[label=ctdto-def]
\begin{definition}[Connected to]
    Let $G=(V,E)$ be a graph.
    We say that $u$ is \defined{connected to} $v$ if there exists a $(u,v)$-path in $G$.
\end{definition}
\end{frame}

\begin{frame}[label=ctdto-ex]
    \begin{columns}
    \begin{column}{0.45\textwidth}
        \begin{example}<+->
        Find the pairs of connected vertices in the graph below.
        \begin{center}
            \begin{tikzpicture}[simple graph]
                \begin{scope}[every node/.append style={vertex}]
                    \path (0,0) node[label=180:$1$] (v1) {}
                        ++(1,0) node[label=0:$2$] (v2) {}
                        ++(0,1) node[label=0:$3$] (v3) {}
                        ++(-1,0) node[label=180:$4$] (v4) {};
                    \path (v1) edge (v2) edge (v4)
                          (v3) edge (v2) edge (v4);
                    \begin{scope}[xshift=2cm]
                    \path (0,0) node[label=$9$] (v9) {}
                        ++(1,1) node[label=$0$] (v0) {};
                    \path (v9) edge (v0);
                    \end{scope}
                    \begin{scope}[yshift=2cm]
                    \path (0,0) node[label=$5$] (v5) {};
                    \end{scope}
                    \begin{scope}[xshift=2cm,yshift=2cm]
                    \path (0,0) node[label=$6$] (v6) {}
                          (1,0) node[label=$7$] (v7) {}
                          (60:1) node[label=$8$] (v8) {};
                    \draw (v6) -- (v7) -- (v8);
                    \end{scope}
                \end{scope}
            \end{tikzpicture}
        \end{center}
        \end{example}
    \end{column}
    \begin{column}{0.45\textwidth}
        \begin{solution}<+->
            \centering
            \begin{tabular}{r|l}
                vertex & connected to \\\hline
                0 & 0, 9 \\
                1 & 1, 2, 3, 4 \\
                2 & 2, 3, 4, 1 \\
                3 & 3, 4, 1, 2 \\
                4 & 4, 1, 2, 3 \\
                5 & 5 \\
                6 & 6, 7, 8 \\
                7 & 7, 8, 6 \\
                8 & 8, 7, 6 \\
                9 & 9, 0
            \end{tabular}
        \end{solution}
    \end{column}
    \end{columns}
\end{frame}

\begin{frame}[label=ctd-adj]%%
    \begin{alertblock}{Note}
       It's tempting to use “connected” as a synonym for \emph{adjacent} when describing graphs.
       But they are different terms.
       \begin{itemize}
           \item If $v$ is adjacent to $w$, then $v$ is connected to $w$.
           \item But not vice versa!
       \end{itemize}
    \end{alertblock}
\end{frame}

\begin{frame}[label=ctd-thm]
\begin{block}{Theorem 49.8}
    Let $G$ be a graph.  The is-connected-to relation is an equivalence relation on the set of vertices of $G$.
\end{block}
\end{frame}

\begin{frame}[label=ctd-thm-proof-1]
To prove this, we need to show the relation is: reflexive, symmetric, and transitive.
\begin{itemize}
\item<+-> \structure{Reflexive}
\uncover<+->{Let $v \in V$.  The walk $(v)$ is a path, because it does not repeat any vertices.
    This path starts and ends at $v$, so $v$ is connected to $v$.}
\item<+-> \structure{Symmetric}
\uncover<+->{Let $u$ and $v$ be connected vertices, and $P$ a path from $u$ to $v$.
    Denote by $P^{-1}$ the walk that lists the same vertices in the opposite order.
    This is a path, in fact a $(v,u)$-path.  So $v$ is connected to $u$.}
\item<+-> \structure{Transitive}
\uncover<+->{Suppose that $u$ is connected to $v$, and $v$ is connected to $w$.
    Let $W_1$ be a $(u,v)$-path, and $W_2$ a $(v,w)$-path.}
\uncover<+->{Then $W_1+W_2$ is a $(u,w)$-\alert{walk}. It could repeat vertices!}
\end{itemize}
\end{frame}

\begin{frame}[label=lemma]
\begin{block}<+->{Lemma 49.7}
Let $G$ be a graph and $x$ and $y$ vertices.
If there is an $(x,y)$-walk in $G$, then there is an $(x,y)$-path in $G$.
\end{block}
\begin{proof}<+->
\begin{itemize}
\item<.-> Consider the set of all $(x,y)$-walks in $G$.
\item<+-> It's nonempty, so there exists one with minimal length (WOP).  Call it $P$; we claim it's a path.
\item<+-> If $P$ does repeat a vertex, we can eliminate the portion between the two instances, creating a shorter path. \raa \qedhere
\end{itemize}
\end{proof}
\end{frame}

\begin{frame}[label=lemma-2]
More about shortening that path:  Suppose $P$ is a walk from $x$ to $y$ that repeats $u$.  Then
\[
    P = \underbrace{x \sim \dots \sim u}_{W_1}%
    \underbrace{\sim \dots \sim u}_{W_2}%
    \underbrace{\sim \dots \sim y}_{W_3}
\]
We are assuming that $W_2$ has positive length.
Let $P' = W_1 + W_3$.  Then $P'$ is also an $(x,y)$-walk, but has a shorter length than $P$.
\end{frame}

\begin{frame}[label=ctd-thm-proof-2]
Now to show is-connected-to is transitive.
\begin{itemize}
\item Suppose that $u$ is connected to $v$, and $v$ is connected to $w$.
    Let $W_1$ be a $(u,v)$-path, and $W_2$ a $(v,w)$-path.
    Then $W_1+W_2$ is a $(u,w)$-walk.
    By the lemma, there is a $(u,w)$-path in $G$.
    So $u$ is connected to $v$.
\item Therefore is-connected-to is an equivalence relation.
\end{itemize}
\end{frame}

\begin{frame}[label=cpt-def]
\begin{definition}
    A \defined{component} of $G$ is a subgraph of $G$ induced by an equivalence class of
    the is-connected-to relation on $V(G)$.
\end{definition}
In other words, a component is:
\begin{itemize}
\item A maximal set of vertices, each of which is connected to the rest;
\item plus all the edges that join them.
\end{itemize}
\end{frame}

\begin{frame}[label=cpt-ex]
    \begin{columns}
    \begin{column}{0.45\textwidth}
        \begin{example}<+->
        Find the components in the graph below.
        \begin{center}
            \begin{tikzpicture}[simple graph,
                     cpt/.style={preaction={draw,ultra thick,example}}
            ]
                \begin{scope}[
                    vertex/.append style={onslide={<4,9>{cpt}}},
                    every edge/.append style={onslide=<9>{cpt}}
                ]
                    \path (0,0) node[vertex,label=180:$1$] (v1) {}
                        ++(1,0) node[vertex,label=0:$2$] (v2) {}
                        ++(0,1) node[vertex,label=0:$3$] (v3) {}
                        ++(-1,0) node[vertex,label=180:$4$] (v4) {};
                    \path (v1) edge (v2) edge (v4)
                          (v3) edge (v2) edge (v4);
                \end{scope}
                \begin{scope}[xshift=2cm,
                    vertex/.append style={onslide={<7,12>{cpt}}},
                    every edge/.append style={onslide={<12>{cpt}}}
                ]
                \path (0,0) node[vertex,label=$9$] (v9) {}
                    ++(1,1) node[vertex,label=$0$] (v0) {};
                \path (v9) edge (v0);
                \end{scope}
                \begin{scope}[yshift=2cm,
                    vertex/.append style={onslide={<5,10>{cpt}}}
                ]
                \path (0,0) node[vertex,label=$5$] (v5) {};
                \end{scope}
                \begin{scope}[xshift=2cm,yshift=2cm,
                    vertex/.append style={onslide={<6,11>{cpt}}},
                    every edge/.append style={onslide=<11>{cpt}}
                ]
                \path (0,0) node[vertex,label=$6$] (v6) {}
                      (1,0) node[vertex,label=$7$] (v7) {}
                      (60:1) node[vertex,label=$8$] (v8) {};
                \draw (v6) edge (v7) edge (v8) (v7) edge (v8);
                \end{scope}
            \end{tikzpicture}
        \end{center}
        \end{example}
    \end{column}
    \begin{column}{0.45\textwidth}
        \begin{solution}<+->
            \begin{itemize}
            \item<+-> Equivalence classes:
                  \uncover<+->{\textcolor<.>{example}{$\set{1,2,3,4}$},}
                  \uncover<+->{\textcolor<.>{example}{$\set{5}$},}
                  \uncover<+->{\textcolor<.>{example}{$\set{6,7,8}$},}
                  \uncover<+->{\textcolor<.>{example}{$\set{9,0}$}.}
            \item<+-> Each of these induces a component (subgraph)
            \end{itemize}
        \end{solution}
    \end{column}
    \end{columns}
\end{frame}

\begin{frame}[label=ctd-def]
\begin{definition}[Connected]
    A graph is called \defined{connected} if it has exactly one component.
\end{definition}
\begin{itemize}
    \item In other words, $G$ is connected iff for all vertices $x,y\in V$,
    there exists an $(x,y)$-path in $G$.
    \item $G$ is \emph{not} connected iff there exist $x,y\in V$ such that
    there \emph{does not} exist an $(x,y)$-path in $G$.
\end{itemize}
\end{frame}

\section{Disconnection}

\begin{frame}[label=cut-def]
    \begin{definition}[Cut vertex, cut edge]
        Let $G$ be a graph.
        \begin{itemize}
            \item A vertex $v$ is called a \defined{cut vertex} of $G$ if $G-v$ has more components than $G$.
            \item An edge $e$ is called a \defined{cut edge} of $G$ if $G-e$ has more components then $G$.
        \end{itemize}
    \end{definition}
    \begin{itemize}
        \item If $e=xy$, then $e$ is a cut edge of $G$ iff
              there is no $(x,y)$-path in $G$ other than $x \sim y$.
        \item $v$ is a cut vertex iff there exist $x$ and $y$ adjacent to $v$
              such that all $(x,y)$-paths contain $v$.
    \end{itemize}
\end{frame}

\begin{frame}[label=cut-ex]
    \begin{columns}
    \begin{column}{0.45\textwidth}
        \begin{example}<+->
            Find all the cut vertices and edges of the graph
            below.
            \begin{center}
                \begin{tikzpicture}[simple graph]
                % two triangles joined by an edge
                    \path node[vertex,label=$c$] (c) {}
                    (60:1) node[vertex,label=$a$] (a) {}
                    (120:1) node[vertex,label=$b$] (b) {}
                    (0,-1) node[vertex,label=-90:$d$] (d) {}
                    ++(-60:1) node[vertex,label=0:$f$] (f) {}
                    ++(-1,0) node[vertex,label=180:$e$] (e) {}
                    (a) edge (b) edge (c)
                    (b) edge (c)
                    (c) edge (d)
                    (d) edge (e)
                    (e) edge (f)
                    (f) edge (d);
                \end{tikzpicture}
            \end{center}
        \end{example}
    \end{column}
    \begin{column}{0.45\textwidth}
        \begin{solution}<+->
            \begin{itemize}
                \item<.-> $c$ and $d$ are cut vertices.
                \item<+-> $cd$ is the only cut edge.
            \end{itemize}
        \end{solution}
    \end{column}
    \end{columns}
\end{frame}

\begin{frame}[label=cut-prac]
\begin{exampleblock}<+->{Practice}
Find the cut vertices and edges of the graphs below.
\begin{columns}
\begin{column}{0.45\textwidth}
    \begin{center}
        \begin{tikzpicture}[simple graph]
            \path node[vertex,label=$a$] (a) {}
            ++( 1,-1) node[vertex,label=$c$] (c) {} edge (a)
            ++( 1,-1) node[vertex,label=$f$] (f) {} edge (c)
            ++( 1, 1) node[vertex,label=$e$] (e) {} edge (f)
            ++(-1, 1) node[vertex,label=$d$] (d) {} edge (e) edge (c)
            ++(-2,-2) node[vertex,label=135:$b$] (b) {} edge (c) edge (a);
            \node[at=(current bounding box.south east),anchor=south east] {$G$};
        \end{tikzpicture}
    \end{center}
\end{column}
\begin{column}{0.45\textwidth}
    \begin{center}
        \begin{tikzpicture}[simple graph]
            \path node[vertex,label=$a$] (a) {}
            ++( 1, 0) node[vertex,label=$b$] (b) {} edge (a)
            ++( 0,-1) node[vertex,label=left:$c$] (c) {} edge (b)
             +( 0,-1) node[vertex,label=left:$d$] (d) {} edge (c)
            ++( 1, 0) node[vertex,label=135:$e$] (e) {} edge (c)
             +( 0, 1) node[vertex,label=$f$] (f) {} edge (e)
             +( 1, 0) node[vertex,label=0:$g$] (g) {} edge (e) edge (f)
            ++( 0,-1) node[vertex,label=-90:$i$] (i) {} edge (e)
            ++( 1, 0) node[vertex,label=-90:$h$] (h) {} edge (i)
            ;
            \node[at=(current bounding box.south west),anchor=south west] {$H$};
        \end{tikzpicture}
    \end{center}
\end{column}
\end{columns}
\end{exampleblock}
\begin{solution}<+->
\begin{tabular}{c|c|c}
graph & cut vertices & cut edges \\\hline
$G$   & $c$          & $\emptyset$ \\
$H$   & $c$, $e$, $i$ & $ab$, $bc$, $cd$, $ce$, $ei$, $hi$
\end{tabular}
\end{solution}
\end{frame}

\begin{example}
Find the cut edges and vertices on the graphs below:
See \href{https://math.stackexchange.com/q/457159/2785}{MSE}
\begin{center}
\includegraphics[width=\textwidth]{dRD1r}
\end{center}
\end{example}

\begin{frame}[label=cut-thm]
    \begin{block}{Theorem 49.12}
   Let $G$ be a connected graph and suppose $e$ is a cut edge of $G$.
   Then $G-e$ has \emph{exactly} two components.
   \end{block}
   Note $G-e$ has \emph{at least} two components by definition of cut edge.
   We need to show it can't have more.
\end{frame}

\begin{frame}[label=cut-proof]
\begin{proof}
\begin{overlayarea}{\textwidth}{0.8\textheight}
\begin{itemize}
\item<only@1-4|uncover@+-> Suppose FTSOC that $G-e$ has at least three components.  Then there exist vertices $a$, $b$, and $c$ in $G$,
no pair of which are connected in $G-e$.
\item<only@1-4|uncover@+-> There is a path $P$ from $a$ to $b$ in $G$, though.  Such a path \textbf{must traverse the edge $e$}.
\item<only@1-4|uncover@+-> There is a path $Q$ from $c$ to $a$ in $G$, too.  It must also traverse $e$.
\item<uncover@+-> Let $e$ join vertices $x$ and $y$ in the direction of $P$.  Does $Q$ visit $x$ or $y$ first?
\begin{itemize}
\item<uncover@+-> If $Q$ visits $x$ first, we can walk along $Q$ from $c$ to $x$, then along $P^{-1}$ from $x$ to $a$.
    This is a walk from $c$ to $a$ skipping $e$, hence a $(c,a)$-walk in $G-e$.  Therefore $c$ is connected to $a$ in $G-e$.
    \raa
\item<uncover@+-> If $Q$ visits $y$ first, we can walk along $Q$ from $c$ to $y$, then along $P$ from $c$ to $b$.
    This is a walk from $c$ to $b$ skipping $e$, hence a $(c,b)$-walk in $G-e$.  Therefore $c$ is connected to $b$ in $G-e$.
    \raa
\end{itemize}
\item<uncover@+-> Either way, we have a contradiction, so $G-e$ cannot have three components.\qedhere
\end{itemize}

\end{overlayarea}\end{proof}
\end{frame}

\mode<article>{%
\section*{Guided Practice}}

See practice elements above.

\mode<article>{%
\section*{Closure}}
\timecheck{\LARGE\clock{10}{40}}

\begin{frame}[label=summary]{Summary of \S49}
\begin{itemize}
\item walk and path.  A path is a walk that doesn't repeat vertices.
\item connected (equivalence relation on vertices of a graph), components (subgraphs induced by equivalence classes).  Each of these is easier to “see” than to describe.
\item Cut vertices and cut edges separate the graph when removed.  Cut vertices can separate the graph into many components, but cut edges only two.
\end{itemize}
\end{frame}

\mode<article>{%
\section*{Independent Practice}

\subsection*{Practice Problems}

All problems from Scheinerman.

\begin{itemize}
    \item \S49:
\end{itemize}

\subsection*{Homework problems}

}% end mode<article>

\bibliographystyle{amsalpha}
\bibliography{undergrad-textbooks}

\end{document}
\endinput
%%
%% End of file `Lesson23_-_Connections.slides.tex'.


\documentclass{beamer}

% choose theme (warning, to use the UniBern theme you need to copy the files beamerthemeUniBern.sty and ublogo.pdf in the same directory)
\usetheme{UniBern}

% packages

\usepackage{graphicx}
\usepackage{hyperref} % allows clickable urls
\usepackage{tikz}
\usepackage{listings} % show code
\usepackage{dsfont} % show code
\usepackage{fontawesome}
\usepackage{tikz}

% slide numbering
\setbeamertemplate{sidebar right}{}
\setbeamertemplate{footline}{%
	\hfill\usebeamertemplate***{navigation symbols}
	\hspace{1cm}\insertframenumber{}/\inserttotalframenumber}

% outline
\AtBeginSection[]
{
	\begin{frame}<beamer>
		\frametitle{Outline}
		\tableofcontents[currentsection]
	\end{frame}
}

% define title page
\title{Bayesian workflow for disease transmission modelling in Stan}
\subtitle{{\small Swiss Epidemiology Winter School 2021} }
\author{Julien Riou, MD PhD}
\date{Institute of Social and Preventive Medicine, University of Bern, Switzerland}
\institute{institute}

% begin document
\begin{document}

	\frame{\titlepage}

	\frame{
		\frametitle{Preface}
		\begin{itemize}
			\item Objective: fit transmission models in Stan
			\item Based on Grinsztajn et al., 2020 (\underline{\href{https://arxiv.org/abs/2006.02985}{link}} -- v2 upcoming)
			\item Prerequisites:
			\begin{itemize}
				\item introduction to infectious disease modelling
				\item general understanding of Bayesian inference
				\item basic programming with \texttt{R} and \texttt{Stan 2.21}
			\end{itemize}
			\item All material is available on \url{https://github.com/jriou/bayesian_workflow}
		\end{itemize}
	}

\section{Introduction}

\frame{
	\frametitle{Introduction}
	Models of disease transmission:
	\begin{itemize}
		\item Interpretability: \alert{mechanistic}, phenomenological
		\item Granularity: agent-based, \alert{population-based}
		\item Framework: \alert{deterministic}, stochastic
		\item Data-generating mechanisms: incubation, contagion, immunity...
	\end{itemize}
	\pause

	\vspace{2em}
	Mechanistic + population-based + deterministic

	\vspace{1em} $\rightarrow$ \alert{ordinary differential equations (ODE)-based compartmental model}
}

\frame{
	\frametitle{Introduction}
	ODE-based compartmental model:
	\begin{itemize}
		\item Divide the population into homogeneous groups (\alert{compartments})
		\item Define the \alert{flows} between compartments with ODEs
		\item Define initial conditions (at $t_0$)
		\item Solve for the time-dependent volume in each compartment
	\end{itemize}
	\vspace{1em}
	\pause

	The \alert{susceptible-infectious-recovered} (SIR) model:
	\begin{figure}
		\centering
		\scalebox{.8}{
		\begin{tikzpicture}
			\node[circle, draw, inner sep=0pt, minimum size=1cm] (S) at (0,0) {$S$};
			\node[circle, draw, inner sep=0pt, minimum size=1cm] (I) at (4,0) {$I$};
			\node[circle, draw, inner sep=0pt, minimum size=1cm] (R) at (8,0) {$R$};

			\draw[->,>=latex] (S) edge node[above] { $\beta S \frac{I}{N}$} (I);
			\draw[->,>=latex] (I) edge node[above] { $\gamma I$} (R);

			\node[anchor=west] at (10,.8) {$	\frac{dS}{dt} = - \beta S \frac{I}{N}$};
			\node[anchor=west] at (10,0) {$	\frac{dI}{dt} = \beta S \frac{I}{N} - \gamma I $};
			\node[anchor=west] at (10,-.8) {$\frac{dR}{dt} = \gamma I $};
		\end{tikzpicture}
	}
	\end{figure}
}

\frame{
	\frametitle{Introduction}

		\begin{figure}
		\centering
		\scalebox{.8}{
			\begin{tikzpicture}
				\node[circle, draw, inner sep=0pt, minimum size=1cm] (S) at (0,0) {$S$};
				\node[circle, draw, inner sep=0pt, minimum size=1cm] (I) at (4,0) {$I$};
				\node[circle, draw, inner sep=0pt, minimum size=1cm] (R) at (8,0) {$R$};

				\draw[->,>=latex] (S) edge node[above] { $\beta S \frac{I}{N}$} (I);
				\draw[->,>=latex] (I) edge node[above] { $\gamma I$} (R);

				\node[anchor=west] at (10,.8) {$	\frac{dS}{dt} = - \beta S \frac{I}{N}$};
				\node[anchor=west] at (10,0) {$	\frac{dI}{dt} = \beta S \frac{I}{N} - \gamma I $};
				\node[anchor=west] at (10,-.8) {$\frac{dR}{dt} = \gamma I $};
			\end{tikzpicture}
		}
	\end{figure}
	Where:
	\begin{itemize}
		\item $S(t)$ is the number of people \alert{susceptible} to infection
		\item $I(t)$ is the number of people \alert{infected} (i.e. the prevalence)
		\item $R(t)$ is the number of people \alert{recovered} (lifelong immunity)
		\item $N$ is the population size ($S(t)+I(t)+R(t)=N$ for any $t$)
		\item $\beta$ is the \alert{infectious contact rate} (per day per person)
		\item $\gamma$ is the \alert{recovery rate} (1/infectious period)
	\end{itemize}
}

\frame{
	\frametitle{Introduction}

	\begin{figure}
		\centering
		\scalebox{.8}{
			\begin{tikzpicture}
				\node[circle, draw, inner sep=0pt, minimum size=1cm] (S) at (0,0) {$S$};
				\node[circle, draw, inner sep=0pt, minimum size=1cm] (I) at (4,0) {$I$};
				\node[circle, draw, inner sep=0pt, minimum size=1cm] (R) at (8,0) {$R$};

				\draw[->,>=latex] (S) edge node[above] { $\beta S \frac{I}{N}$} (I);
				\draw[->,>=latex] (I) edge node[above] { $\gamma I$} (R);

				\node[anchor=west] at (10,.8) {$	\frac{dS}{dt} = - \beta S \frac{I}{N}$};
				\node[anchor=west] at (10,0) {$	\frac{dI}{dt} = \beta S \frac{I}{N} - \gamma I $};
				\node[anchor=west] at (10,-.8) {$\frac{dR}{dt} = \gamma I $};
			\end{tikzpicture}
		}
	\end{figure}
	\alert{Intuition} behind the SIR model:
	\begin{itemize}
		\item $I(t)/N$ is the proportion of infected (and infectious)
		\item $\beta I(t)/N$ is the daily number of contacts with infectious people
		\item hence each day, $\beta S I(t)/N$ people become infected (the \alert{force of infection})
	\end{itemize}
}

\frame{
	\frametitle{Introduction}

	\begin{figure}
		\centering
		\scalebox{.8}{
			\begin{tikzpicture}
				\node[circle, draw, inner sep=0pt, minimum size=1cm] (S) at (0,0) {$S$};
				\node[circle, draw, inner sep=0pt, minimum size=1cm] (I) at (4,0) {$I$};
				\node[circle, draw, inner sep=0pt, minimum size=1cm] (R) at (8,0) {$R$};

				\draw[->,>=latex] (S) edge node[above] { $\beta S \frac{I}{N}$} (I);
				\draw[->,>=latex] (I) edge node[above] { $\gamma I$} (R);

				\node[anchor=west] at (10,.8) {$	\frac{dS}{dt} = - \beta S \frac{I}{N}$};
				\node[anchor=west] at (10,0) {$	\frac{dI}{dt} = \beta S \frac{I}{N} - \gamma I $};
				\node[anchor=west] at (10,-.8) {$\frac{dR}{dt} = \gamma I $};
			\end{tikzpicture}
		}
	\end{figure}
	\alert{Assumptions} behind the SIR model:
	\begin{itemize}
		\item homogeneous mixing
		\item $\beta$ and $\gamma$ constant over time
		\item all infections are observed
		\item no incubation, exponentially-distributed recovery
		\item lifelong immunity
		\item stable population
	\end{itemize}
}

\frame{
	\frametitle{Introduction}

	Simulate in \texttt{R} with package \texttt{deSolve}:

	\begin{itemize}
		\item set compartments and differential equations
	\end{itemize}
	\begin{figure}
		\centering
		\includegraphics[width=0.55\linewidth]{simple_sir/simsir3.png}
	\end{figure}
	\pause
	\begin{itemize}
		\item set (fixed) values for
		$\beta=0.8$; $\rho=1/7$; $S_0=100,000-50$; $I_0=50$ and $R_0=0$
	\end{itemize}
	\begin{figure}
		\centering
		\includegraphics[width=0.45\linewidth]{simple_sir/simsir1.png}
		\includegraphics[width=0.45\linewidth]{simple_sir/simsir2.png}
	\end{figure}
}

\frame{
	\frametitle{Introduction}
	\begin{itemize}
		\item solve the ODE system numerically (Runge-Kutta 4th order) to obtain unique solutions for $S(t)$, $I(t)$ and $R(t)$
	\end{itemize}
	$$
f(\beta,\gamma,S_0,I_0,R_0) = \{S(t),I(t),R(t)\}
$$
	\begin{figure}
		\centering
		\includegraphics[width=0.65\linewidth]{simple_sir/simsir4.png}
	\end{figure}

}

\frame{
	\frametitle{Introduction}

	\begin{figure}
		\centering
		\only<1>{
			with $\beta=0.8$; $\rho=1/7$; $S_0=100000-50$; $I_0=50$ and $R_0=0$ \\ \bigskip
			\includegraphics[width=0.7\linewidth]{simple_sir/example_sir1.pdf}
		}
		\only<2>{
			with $\beta = 1.1$ instead of $0.8$, we get \\ \bigskip
			\includegraphics[width=0.7\linewidth]{simple_sir/example_sir2.pdf}
		}
		\only<3>{
			with $\beta = 0.6$ instead of $0.8$, we get \\ \bigskip
			\includegraphics[width=0.7\linewidth]{simple_sir/example_sir3.pdf}
		}
		\only<4>{
		with $\gamma = 1/14$ instead of $1/7$, we get \\ \bigskip
		\includegraphics[width=0.7\linewidth]{simple_sir/example_sir4.pdf}
		}
		\only<5>{
		with $\gamma = 1/4$ instead of $1/7$, we get \\ \bigskip
		\includegraphics[width=0.7\linewidth]{simple_sir/example_sir5.pdf}
		}
		\only<6>{
		with $I(0) = 500$ instead of $50$, we get \\ \bigskip
		\includegraphics[width=0.7\linewidth]{simple_sir/example_sir6.pdf}
		}
		\only<7>{
		with $I(0) = 5$ instead of $50$, we get \\ \bigskip
		\includegraphics[width=0.7\linewidth]{simple_sir/example_sir7.pdf}
		}
		\only<8>{
		with $R(0) = 20,000$ instead of $0$, we get \\ \bigskip
		\includegraphics[width=0.7\linewidth]{simple_sir/example_sir8.pdf}
		}
	\end{figure}
}

\frame{
	\frametitle{Introduction}
	Compartmental models have many uses:
	\begin{itemize}
		\item formalize and put numerical values on \alert{general concepts} (herd immunity, vaccination threshold...)
		\item get \alert{mechanistic insight} about an epidemic (transmissibility levels, drivers of transmission)
		$$
		\mathcal{R}_0 = \frac{\beta}{\gamma}
		$$

		\item produce precise \alert{forecasts} (based on mechanisms)
	\end{itemize}

	\pause\vspace{2em}
	$\rightarrow$ all these uses are based on \alert{numerical values} for $\beta$, $\rho$ and the initial conditions and their \alert{uncertainty}
}

\frame{
	\frametitle{Introduction}
	Enters \alert{Bayesian inference}:
	\begin{itemize}
		\item infer parameter values by \alert{integrating information from data and from domain knowledge}
		\item more efficient for complex models (high dimensionality)
		\item rigorously quantify and propagate uncertainty in parameter estimates and forecast
	\end{itemize}

	\pause\vspace{2em}
	$\rightarrow$ Markov Chain Monte Carlo (MCMC) methods and \alert{Stan}
}

\section{Basics of Bayesian inference}

\frame{
	\frametitle{Bayesian inference}
	General principle of Bayesian inference\footnote{Gelman et al. \textit{Bayesian Data Analysis}}$^,$\footnote{Michael Betancourt, \textit{Introduction to Stan}}:
	\medskip
	\begin{itemize}
		\item[(1)] specify a complete Bayesian model
		\begin{itemize}
			\item[-] consider data $y = \{y_1,...,y_n\}$ that are noisy measurement of an unknown quantity (parameter) $\theta$
			\medskip

			\item[-] encode the data-generating processes in an \alert{observation model} (likelihood) $$p(y|\theta) = \prod_n^N \text{normal}(y_n | \theta,1)$$
			\medskip

			\item[-] encode domain knowledge in a \alert{prior distribution}  $$p(\theta) = \text{normal}(0,1)$$
		\end{itemize}

%		\item the model corresponds to a \alert{joint probability density function}
%		$$
%		p(y, \theta) = p(y|\theta)p(\theta)
%		$$
	\end{itemize}
}

\frame{
	\frametitle{Bayesian inference}
%	General principle of Bayesian inference:
	\begin{itemize}
		\item[(2)] reverse the question:
		\medskip

		``\textit{given a model and data, \alert{what are plausible parameter values?}}"
		\medskip

		\begin{itemize}
		\item[-] the answer comes from Bayes' rule:
	\end{itemize}

		$$
		p(\theta \mid y) \propto p(\theta) p( y \mid \theta)
		$$
		\medskip
		\begin{itemize}
		\item[-] where $p(\theta \mid y)$ is the \alert{posterior distribution}, i.e. the set of plausible parameter values given data and model

	\end{itemize}
	\end{itemize}
}

\frame{
	\frametitle{Bayesian inference}
	\bigskip
	In practice, we rarely have an analytic expression for $p(\theta \mid y)$ and rely on inference algorithms to learn about the posterior distribution
	\medskip
	\begin{itemize}
		\item \alert{Monte Carlo} methods
	\end{itemize}
	\begin{figure}
		\centering
		\includegraphics[width=0.6\linewidth]{fig/Montecarlo.svg.png}
		\caption{Monte Carlo approach to determine the area of a lake using random artillery fire.}
	\end{figure}
}

\frame{
	\frametitle{Bayesian inference}
	\bigskip
	\begin{itemize}
		\item \alert{Markov chain Monte Carlo} (MCMC) samplers apply this principle to probability distributions
	\end{itemize}
	\begin{figure}
	\centering
	\fbox{\includegraphics[width=0.55\linewidth]{fig/mh_sampler.png}}
	\caption{An MCMC sampler exploring a bivariate normal distribution (\url{https://chi-feng.github.io/mcmc-demo/app.html}).}
\end{figure}
	\centering
}
%
%\frame{
%	\frametitle{Bayesian modelling workflow}
%	The \alert{joint probability density function} of the model is given by
%		$$
%		\Pr(y, \theta)
%		=
%		\prod_{n = 1}^{N} \text{normal\_pdf} \, (y_{n} \mid \theta, 1)
%		\cdot \text{normal\_pdf} \, (\theta \mid 0, 1)
%		$$
%	or on the log scale
%	$$
%	\log \Pr(y, \theta)
%	=
%	\sum_{n = 1}^{N} \text{normal\_lpdf} \, (y_{n} \mid \theta, 1)
%	+ \text{normal\_lpdf} \, (\theta \mid 0, 1)
%	$$
%}

\section{Bayesian modelling with Stan}

\frame{
	\frametitle{Bayesian modelling with Stan}
	Stan is a probabilistic programming framework for Bayesian inference
	\begin{itemize}
		\item it is designed to let the user \alert{focus on modelling} while inference happens under the hood
		\item object-oriented language (based on \texttt{C++}) that supports many  operations, probability densities and ODE solvers
		\item extremely \alert{efficient} MCMC algorithm (Hamiltonian Monte Carlo)
		\item \alert{diagnostic tools} to evaluate the inference
		\item interfaces in \texttt{R} (package \texttt{rstan}), \texttt{python}, \texttt{julia}...
	\end{itemize}
}

\frame{
	\frametitle{Bayesian modelling with Stan}
	Programming in Stan is structured in \alert{blocks}:
	\begin{itemize}
		\item the \alert{\texttt{data}} block defines known variables and constants
		\begin{figure}
			\centering
			\includegraphics[width=0.6\linewidth]{example_linear/example_linear1.png}
		\end{figure}

		\item the \alert{\texttt{parameters}} block defines unknown variables (parameters)
		\begin{figure}
			\centering
			\includegraphics[width=0.6\linewidth]{example_linear/example_linear2.png}
		\end{figure}

		\item the \alert{\texttt{model}} block defines the {prior distribution(s) and the observation model(s)}
		\begin{figure}
			\centering
			\includegraphics[width=0.6\linewidth]{example_linear/example_linear3.png}
		\end{figure}
		\item save in \texttt{model\_linear.stan}

	\end{itemize}
}

\frame{
	\frametitle{Bayesian modelling with Stan}
	We then explore the target with Stan's MCMC \alert{sampler}:
	\begin{itemize}
		\item load \texttt{rstan} package
		\begin{figure}
			\centering
			\includegraphics[width=0.7\linewidth]{example_linear/run_stan1.png}
		\end{figure}

		\item simulate $N=50$ data points with $\theta=0.7$
		\begin{figure}
			\centering
			\includegraphics[width=0.7\linewidth]{example_linear/run_stan2.png}
		\end{figure}

		\item run MCMC sampling
		\begin{figure}
			\centering
			\includegraphics[width=0.7\linewidth]{example_linear/run_stan3.png}
		\end{figure}
	\end{itemize}
}

\frame{
	\frametitle{Bayesian modelling with Stan}
	We use \alert{multiple chains} that should converge after warm-up
	\begin{figure}
		\centering
		\only<1>{\includegraphics[width=.6\linewidth]{example_linear/trace_theta.pdf}}
		\only<2>{\includegraphics[width=.6\linewidth]{example_linear/trace_theta_init.pdf}}
	\end{figure}
}

\frame{
	\frametitle{Bayesian modelling with Stan}
	The post-warm-up samples of $\theta$ approximate its \alert{posterior distribution}
	\begin{figure}
		\centering
		\includegraphics[width=.6\linewidth]{example_linear/post_theta.pdf}
	\end{figure}
}

\frame{
	\frametitle{Bayesian modelling with Stan}

	We run \alert{basic diagnosis tools}: divergences, tree depth, energy
		\begin{figure}
			\centering
			\vspace{1em}
			\includegraphics[width=.8\linewidth]{example_linear/run_stan5.png}
		\end{figure}

}

\frame{
	\frametitle{Bayesian modelling with Stan}

	Printing the object gives:
	\begin{itemize}
		\item \alert{diagnostics}: effective sample size, Gelman-Rubin $\hat{R}$
		\item \alert{inference}: full posterior distribution of $\theta$
	\begin{figure}
		\centering
		\vspace{1em}
		\includegraphics[width=1\linewidth]{example_linear/run_stan4.png}
	\end{figure}
	\end{itemize}
}

\section{Fitting a simple SIR model}

\frame{
	\frametitle{Fitting a simple SIR}
	Example data: outbreak of influenza A (H1N1) at a \alert{British boarding school} in 1978 (available in \texttt{R} package \texttt{outbreaks})
	\begin{itemize}
		\item 763 students, 512 had symptoms
		\item daily number of students in bed over 14 days (\alert{prevalence} data)
		\begin{figure}
			\centering
			\vspace{.5em}
			\includegraphics[width=.55\linewidth]{boarding_school/inbed.pdf}
		\end{figure}
	\end{itemize}
}

\frame{
	\frametitle{Fitting a simple SIR}
	Specifying the model:
	\begin{itemize}
		\item prevalence data: $\mathds{I}_{t}$ with $t \in \{1,\ldots,14\}$
		\item parameters to estimate: $\theta = \{\beta,\gamma,\phi\}$
		\item parameters that will remain fixed: $\{S_0=762,I_0=1,R_0=0\}$
		\item map data $\mathds{I}_{t}$ to SIR model output $I(t)$ using an observation model  with an appropriate \alert{probability distribution}:
		$$
		\Pr(\mathds{I}|\theta) = \prod_{t=1}^{14} \text{neg-bin}(\mathds{I}_{t} | I(t), \phi)
		$$
		\item \alert{prior distributions}
		\vspace{-1em}

		$$\Pr(\beta) = \text{exponential}(1)$$
		$$\Pr(1/\gamma) = \text{normal}(2,0.5)$$
		$$\Pr(1/\phi) = \text{exponential}(5)$$
	\end{itemize}
}

\frame{
	\frametitle{Fitting a simple SIR}
	We define the ODE system in the \texttt{function} block
		\begin{figure}
			\centering
			\includegraphics[width=1\linewidth]{boarding_school/stan_code1.png}
		\end{figure}
	\faWarning\ Be careful of the signature and formats!
}

\frame{
	\frametitle{Fitting a simple SIR}
	We declare the data variables in the \texttt{data} block
		\begin{figure}
			\centering
			\includegraphics[width=1\linewidth]{boarding_school/stan_code2.png}
		\end{figure}

	\pause
	and define additional data variables in \texttt{transformed data}
	\begin{figure}
		\centering
		\includegraphics[width=1\linewidth]{boarding_school/stan_code3.png}
	\end{figure}
}

\frame{
	\frametitle{Fitting a simple SIR}
	Similarly, parameters are declared in the \texttt{parameters} block
		\begin{figure}
			\centering
			\includegraphics[width=1\linewidth]{boarding_school/stan_code4.png}
		\end{figure}
	\faWarning\ It sometimes makes more sense to transform some parameters (e.g., recovery rate $\gamma$ and overdispersion $\phi$) to improve interpretability
	}

\frame{
	\frametitle{Fitting a simple SIR}
	In \texttt{transformed parameters}, we define additional parameters and solve the ODE system
		\begin{figure}
			\centering
			\includegraphics[width=1\linewidth]{boarding_school/stan_code5.png}
		\end{figure}
}

\frame{
	\frametitle{Fitting a simple SIR}
	\begin{figure}
		\centering
		\includegraphics[width=.8\linewidth]{boarding_school/stan_code5bis.png}
	\end{figure}
	Two crucial points:
	\begin{itemize}
	\item be careful about the \alert{formats and signatures}
	\begin{itemize}
			\item[-] the ODE output \texttt{y} is an array of size \texttt{T}$\times$3 (number of time steps and number of compartments)
			\item[-] \texttt{sir} is the name of the function defined in the \texttt{function} block
			\item[-] \texttt{y0} is an array of size 3 defined in the \texttt{data} block
			\item[-] \texttt{ts} is an array of size \texttt{T} defined in the \texttt{data} block
			\item[-] \texttt{theta} is an array of size 2 storing the parameters
			\item[-] \texttt{x\_r} is defined as empty in \texttt{transformed data}, but can be used to store fixed real values
			\item[-] \texttt{x\_i} is an array of size 1 storing the population size \texttt{N} (can also be used to store fixed integer values)
	\end{itemize}
	\end{itemize}
}
\frame{
	\frametitle{Fitting a simple SIR}
	\begin{figure}
		\centering
		\includegraphics[width=.8\linewidth]{boarding_school/stan_code5bis.png}
	\end{figure}
	Two crucial points:
	\begin{itemize}
		\item two ODE solvers are available:
	\begin{itemize}
		\item[-] \texttt{integrate\_ode\_rk45} uses the Runge-Kutta method (quicker but non-adapted to stiff systems)
		\item[-] \texttt{integrate\_ode\_bdf} uses the backward differentiation method (slower but adapted to stiff systems)
	\end{itemize}
	\end{itemize}
}

\frame{
	\frametitle{Fitting a simple SIR}
	In the \texttt{model} block, we write the priors and the observation model
	\begin{figure}
		\centering
		\includegraphics[width=1\linewidth]{boarding_school/stan_code6.png}
	\end{figure}
	\faWarning\ It's important that the chosen distributions correspond with the boundaries set in the \texttt{parameters} block (\texttt{<lower=0>})

\bigskip
	\faWarning\ \texttt{col(to\_to\_matrix(y))} extracts the 2nd column of \texttt{y}
}

\frame{
	\frametitle{Fitting a simple SIR}
	Last, we add a \texttt{generated quantities} block that does not influence sampling and can be used for ``post-processing'':
	\begin{itemize}
		\item reproduction number $\mathcal{R}_0 = \beta/\gamma$
		\item model predictions of prevalence from the negative binomial
	\end{itemize}

	\begin{figure}
		\centering
		\includegraphics[width=1\linewidth]{boarding_school/stan_code7.png}
	\end{figure}
}

\frame{
	\frametitle{Fitting a simple SIR}
	In summary:
	\begin{itemize}
		\item \texttt{functions}: define the ODE system (\faWarning\ signature and formats)
		\item \texttt{data}: declare data variables that will be provided
		\item \texttt{tranformed data}: additional quantities that can be computed internally or from \texttt{data} variables
		\item \texttt{parameters}: declare parameters (\faWarning\ boundaries)
		\item \texttt{transformed parameters}: quantities that can be computed internally or from \texttt{data} or \texttt{parameters} variables,
		including the ODE output (\faWarning \ signature and format)
		\item \texttt{model}: priors and observation model
		\item \texttt{generated quantities}: additional quantities that can be computed without influencing the sampling
	\end{itemize}

}

\frame{
	\frametitle{Fitting a simple SIR}
	As before, we conduct the inference from \texttt{R} with the package \texttt{rstan}:
	\begin{figure}
		\centering
		\includegraphics[width=1\linewidth]{boarding_school/r_code1.png}
	\end{figure}

	\faWarning\ data is put in a list with names matching the \texttt{data} block in Stan
}

\frame{
	\frametitle{Fitting a simple SIR}
	Hit the inference button!
	\begin{figure}
		\centering
		\includegraphics[width=1\linewidth]{boarding_school/r_code2.png}
	\end{figure}
}

\frame{
	\frametitle{Fitting a simple SIR}
	Run basic diagnosis tools:
	\begin{figure}
		\centering
		\includegraphics[width=1\linewidth]{boarding_school/r_code3.png}
	\end{figure}
}

\frame{
	\frametitle{Fitting a simple SIR}
	Examine trace plots:
	\begin{figure}
		\centering
		\includegraphics[width=1\linewidth]{boarding_school/trace_theta.pdf}
	\end{figure}
}

\frame{
	\frametitle{Fitting a simple SIR}
	Examine chain mixing:
	\begin{figure}
		\centering
		\includegraphics[width=.8\linewidth]{boarding_school/post_theta.pdf}
	\end{figure}
}

\frame{
	\frametitle{Fitting a simple SIR}
	Posterior predictive checking (always show!):
	\begin{figure}
		\centering
		\includegraphics[width=.6\linewidth]{boarding_school/inbed_fit.pdf}
	\end{figure}
}

\frame{
	\frametitle{Fitting a simple SIR}
	Print the results:
	\begin{figure}
		\centering
		\includegraphics[width=1\linewidth]{boarding_school/r_code4.png}
	\end{figure}
}

\frame{
	\frametitle{Fitting a simple SIR}
	Conclusions:
	\begin{itemize}
		\item we estimate $\mathcal{R}_0$ to 3.3 (95\% credible interval: 2.8 to 4.0)
		\item this corresponds to the direct estimation from the final size of the epidemic $q = 512/763 = 0.67$
		\vspace{-.5em}
		$$
		\mathcal{R}_0 = 1 / (1-q) = 3.03
		$$
		\item based on \alert{many assumptions}:
		\begin{itemize}
			\item[-] common to all SIRs (homogeneous mixing, no incubation...)
			\item[-] prior distributions (especially on the recovery period)
			\item[-] complete ascertainment, no asymptomatics
			\item[-] no initial immunity
		\end{itemize}
	\end{itemize}

}

\section{Simulation-based model assessment}

\frame{
	\frametitle{Simulation-based model assessment}
	In practice, the situation is often less clear than in the boarding school example:
	\begin{itemize}
		\item[-] incomplete data, insufficient domain knowledge
		\item[-] uncertainty on \alert{necessary model features}
	\end{itemize}
\bigskip
	\alert{Fake data} can be used to probe the model and better understand its behaviour:
	\begin{itemize}
		\item[-] prior predictive checking\footnote{Gabry et al. \textit{Visualization in Bayesian workflow}}
		\item[-] simulation study
	\end{itemize}
}

\frame{
	\frametitle{Simulation-based model assessment}
	\alert{Prior predictive checking} consists in simulating data from the priors:
	\begin{itemize}
		\item visualize priors (especially after transformation)
		\item this shows the range of data compatible with the model
		\item it helps understand the \alert{adequacy of the chosen priors}, as it is often easier to elicit expert knowledge on measureable quantities of interest rather than abstract parameter values
		\bigskip\pause
		\item remove (or switch off) the likelihood from the \texttt{model} block
	\end{itemize}
	\begin{figure}
		\centering
		\includegraphics[width=1\linewidth]{boarding_school/stan_code6bis.png}
	\end{figure}
}

\frame{
	\frametitle{Simulation-based model assessment}
	Simulating priors in the boarding school example:
	\begin{figure}
		\centering
		\includegraphics[width=.8\linewidth]{boarding_school/prior_theta.pdf}
	\end{figure}
}

\frame{
	\frametitle{Simulation-based model assessment}
	Prior predictive checking: simulating \alert{epidemic trajectories}
	\begin{figure}
		\centering
		\only<1>{\includegraphics[width=.6\linewidth]{boarding_school/inbed_fit_prior.pdf}}
		\only<2>{\includegraphics[width=.6\linewidth]{boarding_school/inbed_fit_prior_traj.pdf}}
	\end{figure}
}

\frame{
	\frametitle{Simulation-based model assessment}
	Prior predictive checking brings insight about \alert{non-obvious features}:
	\begin{itemize}
		\item even if the priors seem weakly informative, there is actually not a lot of leeway
		\item \alert{highly constrained} model:
		\begin{itemize}
		\item[-] if $\beta$ is high, the epidemic will stop rapidly by lack of susceptibles
		\item[-] if $\beta$ is small, the epidemic will be small
	\end{itemize}
	\item the negative binomial might lead to problems in extreme situations, e.g. more cases (>1000) than the overall number of students
	\end{itemize}
}

\frame{
	\frametitle{Simulation-based model assessment}
	A \alert{simulation study} consists in two steps:
	\begin{itemize}
		\item simulate data with specified parameter values
		\item measure the capacity of the model to recover the chosen parameter values
\end{itemize}
	\bigskip\pause
	Many advantages:
	\begin{itemize}
	\item check for bugs and coding mistakes
	\item check for \alert{identifiability} issues
	\item compare different versions of a model
	\item understand in what \alert{situations} a model works or not
\end{itemize}
}

\frame{
	\frametitle{Simulation-based model assessment}
	Let's go back to the \alert{simple SIR example} from the beginning:
	\begin{itemize}
		\item set $\beta=2$ and $\gamma=0.5$ (so that $\mathcal{R}_0=4$)
		\item simulate in a susceptible population of size $N=763$ with $I_0=1$
	\end{itemize}
	\begin{figure}
	\centering
	\includegraphics[width=.6\linewidth]{boarding_school/example_sir1.pdf}
\end{figure}
}

\frame{
	\frametitle{Simulation-based model assessment}
	Add noise with a \alert{negative binomial} distribution with $\phi=15$
	\begin{figure}
		\centering
		\includegraphics[width=.6\linewidth]{boarding_school/example_sir2.pdf}
	\end{figure}
}

\frame{
	\frametitle{Simulation-based model assessment}
	Fit the \alert{same model} as for the boarding school example
	\begin{figure}
		\centering
		\includegraphics[width=1\linewidth]{boarding_school/trace_theta_sim.pdf}
	\end{figure}
}

\frame{
	\frametitle{Simulation-based model assessment}
	Posterior predictive checking
	\begin{figure}
		\centering
		\includegraphics[width=.6\linewidth]{boarding_school/inbed_fit_sim.pdf}
	\end{figure}
}

\frame{
	\frametitle{Simulation-based model assessment}
	\bigskip
	Compare the posterior distributions of the parameters with the \alert{``truth''}
	\begin{figure}
		\centering
		\includegraphics[width=.9\linewidth]{boarding_school/post_theta_sim.pdf}
	\end{figure}
	\begin{itemize}
		\vspace{-1em}
	\item no identifiability issue
	\item $\beta$ and $\gamma$ are well estimated, but $\phi$ is not
	\item try with other values to understand \alert{when does the model break}\footnote{Talts et al. \textit{Simulation-based calibration}}
	\end{itemize}
}

\section{The Bayesian workflow}

\frame{
	\frametitle{The Bayesian workflow}

	Bayesian \alert{workflow}: model development as an iterative process\footnote{Gelman et al. \textit{Bayesian workflow}}
	\begin{figure}[htbp]
		\begin{center}
			\scalebox{.5}{ \begin{tikzpicture}
					[
					Box/.style={rectangle, draw=black!, minimum size=10mm, text width=22mm,text centered},
					Box2/.style={rectangle, draw=black!, fill=gray!20, minimum size=10mm, text width=20mm,text centered,rounded corners},
					Round/.style={circle, draw=black!, fill=green!0, minimum size=1mm},
					]
					% Nodes
					\node[Round] (Data) at(3, -4) {Data};
					\node[Box] (Model) at(-4, 0) {Build model};
					\node[Box2] (Crit1) at (0, 0) {Criticize model};
					\node[Box] (Infer) at (0, -2) {Fit model};
					\node[Box2] (Crit2) at (4, -2) {Criticize inference};
					\node[Box2] (Crit3) at (8, -2) {Criticize fitted model};
					\node[Box] (App) at (8,-4) {Apply fitted model};

					% Lines
					\path [->, draw] (Model) -- (Crit1);
					\path [->, draw] (Crit1) -- (Infer);
					\path [->, draw] (Infer) -- (Crit2);
					\path [->, draw] (Crit2) -- (Crit3);
					\path [->, draw] (Crit3) -- (App);
					\path [->, draw] (Crit1) edge[bend right=20] (Model);
					\path [->, draw] (Crit2) edge[bend right=40] (Infer);
					\path [->, draw] (Crit2) edge[bend right=40] (Model);
					\path [->, draw] (Crit3) edge[bend right=42] (Model);
					\path [->, draw, dotted] (Data) -- (Infer);
					\path [->, draw, dotted] (Data) -- (Crit2);
					\path [->, draw, dotted] (Data) -- (Crit3);
			\end{tikzpicture}}
		\end{center}
	\end{figure}
}

\frame{
	\frametitle{The Bayesian workflow}
	\begin{itemize}
		\item[(1)] Build a complete model:
		\begin{itemize}
			\item encode the data-generating processes with observation models
			\item encode domain knowledge with prior distributions
		\end{itemize}

		\item[(2)] \textit{Criticize the model} with fake data
		\begin{itemize}
			\item \alert{prior predictive checking}: is the model adequate?
			\item \alert{simulation-based calibration}: does the model work as intended?
		\end{itemize}

		\item[(3)] Fit the model to real data
		\item[(4)] \textit{Criticize the inference}
		\begin{itemize}
			\item \alert{chain mixing} (trace plots, posteriors by chain, \texttt{Rhat})
			\item \alert{basic diagnosis tools} (divergences, energy, \texttt{n\_eff})
		\end{itemize}
		\item[(5)] \textit{Ciriticize fitted model}
		\begin{itemize}
		\item \alert{posterior predictive checking}
		\end{itemize}
		\item[(6)] Application (inference, forecast...)
	\end{itemize}
}

\section{Scaling-up ODE-based models}

\frame{
	\frametitle{Scaling up ODE-based models}
	Inference with ODE-based models is \alert{computationally intensive}
	\bigskip

	Be attentive to the model structure:
		\begin{itemize}
		\item HMC requires to compute the \alert{gradient} of the log joint density
		multiple times for each iteration
		$$
		\triangledown_{\theta}\log \Pr(y,\theta)
		$$
		 \item each block is treated differently
		 	\begin{itemize}
		 	\item[-] \texttt{transformed data} and \texttt{generated quantities} are evaluated once per iteration
		 	\item[-] \texttt{parameters}, \texttt{transformed parameters} and \texttt{model} are evaluated multiple times for each iteration
		 	\item[$\rightarrow$] put everything that \alert{does not influence the inference} (e.g. $\mathcal{R}_0$ or predicted values)  in \texttt{generated quantities}
	 			 \end{itemize}
	\end{itemize}

}

\frame{
	\frametitle{Scaling up ODE-based models}
	\alert{Limiting the load} of the ODE solver:
	\begin{figure}
		\centering
		\includegraphics[width=.8\linewidth]{boarding_school/stan_code5bis.png}
	\end{figure}
	\begin{itemize}
		\item the computational cost of solving the ODEs scales with $N + NK$
		\begin{itemize}
			\item[-] $N$: the number of compartments
			\item[-] $K$: the number of parameters in \texttt{y0} and \texttt{theta}
		\end{itemize}
		\item[$\rightarrow$] remove unnecessary compartments (e.g. $R(t)$)
		\item[$\rightarrow$] reparametrize initial conditions
	\end{itemize}

}

\frame{
	\frametitle{Scaling up ODE-based models}
	Picking \alert{the right ODE solver}:
	\begin{itemize}
		\item two are available:
	\begin{itemize}
		\item[-] \texttt{integrate\_ode\_rk45} uses the Runge-Kutta method (quicker but non-adapted to stiff systems)
		\item[-] \texttt{integrate\_ode\_bdf} uses the backward differentiation method (slower but adapted to stiff systems)
	\end{itemize}
	\item there is no formal definition of \alert{stiffness}
	\item intuitively, it occurs when the time step of the integrator needs to be very small to keep the solution stable (e.g. large variations in magnitude in time)
	\item[$\rightarrow$] start with \texttt{rk45}, move to \texttt{bdf} if there are problems (\textit{folk theorem of statistical computing})
\end{itemize}
}

\frame{
	\frametitle{Scaling up ODE-based models}
	\alert{Tuning} the ODE solver:
		\begin{itemize}
		\item additional options in the solver function
		\begin{figure}
		\centering
		\includegraphics[width=.8\linewidth]{boarding_school/tolerances.png}
	\end{figure}
		\begin{itemize}
			\item[-] \texttt{rel\_tol} is the relative tolerance
			\item[-] \texttt{abs\_tol} is the absolute tolerance
			\item[-] \texttt{max\_steps} is the maximum number of steps
		\end{itemize}
	\item can be adjusted depending on the level of \alert{precision} needed
	\end{itemize}

	\bigskip
	\faWarning\ be cause of the tolerance, the ODE solver may sometimes give negative values when too close to zero, causing issues

	\vspace{.2em}$\rightarrow$ this can be solved by \alert{adding 5-10 times the absolute tolerance} to the ODE output
}

\section{Extensions}

\frame{
	\frametitle{Extensions}
	In practice, the boarding school example quickly reaches its \alert{limits}:
	\begin{itemize}
		\item epidemics are not often observed in such a controlled environment (\alert{under-ascertainment})
		\item epidemics are not always left uncontrolled
		\item data generally consist of daily counts of new cases (\alert{incidence}) rather than counts of currently sick people (\alert{prevalence})
		\item most infectious diseases have an \alert{incubation period} (SEIR instead of SIR)
		\item transmission is generally not homogeneous in the full population (\alert{stratification} by age, sex...)
		\item ...
	\end{itemize}
}

\frame{
	\frametitle{Extensions}
	Example with SARS-CoV-2 from \alert{Hauser et al.~(2020)}:
	\vspace{1em}

	\begin{figure}
		\centering
		\includegraphics[width=.9\linewidth]{example_hauser/paper_ref.png}
	\end{figure}
}

\frame{
	\frametitle{Background}
	The \alert{case fatality ratio} (CFR) is computed as the number of deaths divided by the number of reported cases at time $t$.
	\bigskip

	Estimated in real time, the CFR is a misleading indicator of mortality due to SARS-CoV-2 because of two opposing biases:
	\begin{itemize}
		\item \alert{preferential ascertainment of severe cases}: severe cases are both more likely to die and more likely to be diagnosed and reported
		\item[$\rightarrow$] overestimates mortality
		\vspace{.4em}
		\item \alert{right-censoring} of deaths: there is a long delay between infection and deaths, so that part of the cases at time $t$ will die in the future
		\item[$\rightarrow$] underestimates mortality
	\end{itemize}
}

\frame{
	\frametitle{Background}
	This \alert{limits the interpretability} of the CFR:

	\begin{itemize}
		\item varies in time (ascending or descending phase)
		\item varies across countries (depending on surveillance system)

		\item[$\rightarrow$] April 2020: from 2.4\% in Wuhan to 17.8\% in Lombardy)

		\bigskip
		\item the real indicator of interest is the \alert{infection fatality ratio}, i.e. the total number of deaths that occur among people infected with SARS-CoV-2
	\end{itemize}
}

\frame{
	\frametitle{Objectives}
	\begin{itemize}
		\item[(1)] Simulate the dynamics of transmission and mortality of SARS-CoV-2 using publicly available surveillance data

		\item[(2)] Provide \alert{overall and age-stratified estimates of IFR} for SARS-CoV-2 infection adjusted for right-censoring and preferential ascertainment

		\bigskip
		 in \alert{seven different geographic locations} with available data on:
		 \item reported cases by date of disease onset
		 \item deaths linked to SARS-CoV-2 infection by date of death
		 \item age distribution of cases
		 \item age distribution of deaths
	\end{itemize}
}

\frame{
	\frametitle{Data}
	In Hubei province (China):
	\begin{figure}
		\centering
				\includegraphics[width=.9\linewidth]{example_hauser/data_china.pdf}
	\end{figure}
}

\frame{
	\frametitle{Model development}
	Specific features and natural history of SARS-CoV-2 infection:
	\begin{itemize}
		\item Incubation period of 5 days (S\alert{E}IR)
		\item Pre-symptomatic transmission accounting for 44-48\% (SE\alert{P}IR)
		\item Symptoms in 81\% (95\%CrI 71\%–89\%) of cases (SEPI\alert{A}R)
		\item Respiratory virus transmitted through contacts (\alert{age stratification})
		\item Effect of control measures (\alert{time-dependent force of infection})
		\item Mortality is delayed by $20.2 \pm 11.6$ days (\alert{fit to mortality data})
	\end{itemize}
}

\frame{
	\frametitle{Model development}
	 Final model:
	 \begin{figure}
	 \scalebox{.8}{\begin{tikzpicture}
	 		% cascade of care
	 		\node[circle, draw, inner sep=0pt, minimum size=1cm] (S) at (0,0) {$S_k$};
	 		\node[circle, draw, inner sep=0pt, minimum size=1cm] (E) at (3,0) {$E_k$};
	 		\node[circle, draw, inner sep=0pt, minimum size=1cm] (P) at (6,0) {$P_k$};
%	 		\node[circle, draw, inner sep=0pt, minimum size=1cm,gray,dashed] (C) at (8.5,-2.5) {$C_k$};
%	 		\node[circle, draw, inner sep=0pt, minimum size=1cm,gray,dashed] (rho_C) at (12,-2.5) {$\rho_k C_k$};
	 		\node[circle, draw, inner sep=0pt, minimum size=1cm,fill=white] (I) at (9,-1.5) {$I_k$};
	 		\node[circle, draw, inner sep=0pt, minimum size=1cm] (A) at (9,1.5) {$A_k$};
	 		\node[circle, draw, inner sep=0pt, minimum size=1cm] (R) at (12,0) {$R_k$};

	 		\draw[->,>=latex] (S) edge node[above] { $\lambda_k(t)$} (E);
	 		\draw[->,>=latex] (E) edge node[above] { $\tau_1$ } (P);
	 		\draw[->,>=latex] (P) edge node[yshift=10,xshift=-5] { $\tau_2(1-\psi)$ } (A);
	 		\draw[->,>=latex] (P) edge node[above] { $\tau_2\psi$ } (I);
%	 		\draw[->,>=latex,gray,dashed] (P) edge[bend left=12] node[below] { $\tau_2\psi$ } (C);
	 		\draw[->,>=latex] (A) edge node[above] { $\mu$ } (R);
	 		\draw[->,>=latex] (I) edge node[above] { $\mu$ } (R);
%	 		\draw[double,gray] (C) -- node[above] { $\rho_k$ }  (rho_C);
%
%	 		% legend
	 		\node (leg) at (6,-4) {
	 			\begin{tabular}{r|lp{0cm}r|l}
	 				$S_k$ & Susceptible (\alert{for age group $k$})& & $\lambda_k(t)$ & Force of infection (\alert{time-dependent})\\
	 				$E_k$ & Exposed & & $1/\tau_1+1/\tau_2$ & Incubation period (\alert{split in two})\\
	 				$P_k$ & Presymptomatic & &$\psi$ & Proportion of symptomatic \\
	 				$A_k$ & Infected asymptomatic & & 	$1/\tau_2$ & Presymptomatic infectious period \\
	 				$I_k$ & Infected symptomatic& &	 $1/\mu$ & Symptomatic infectious period \\
	 				$R_k$ & Removed & & &\\% $\rho_k$ & Ascertainment proportion \\
	 			%	$C_k$ & Cumulative cases  & & $\rho_k C_k$ & Cumulative confirmed cases \\
	 		\end{tabular}};
	 	\end{tikzpicture}
 	}
 \end{figure}
}

\frame{
	\frametitle{Model development}
	\alert{Incubation}:
	\begin{itemize}
		\item \alert{SEIR}: adding a compartment \alert{$E$ for exposed}, i.e. infected but not yet symptomatic

	\bigskip
	\begin{figure}
		\scalebox{.8}{\begin{tikzpicture}
				% cascade of care
				\node[circle, draw, inner sep=0pt, minimum size=1cm] (S) at (0,0) {$S$};
				\node[circle, draw, inner sep=0pt, minimum size=1cm] (E) at (3,0) {$E$};
				\node[circle, draw, inner sep=0pt, minimum size=1cm] (I) at (6,0) {$I$};
				\node[circle, draw, inner sep=0pt, minimum size=1cm] (R) at (9,0) {$R$};

				\draw[->,>=latex] (S) edge node[above] { $\lambda$} (E);
				\draw[->,>=latex] (E) edge node[above] { $\tau$ } (I);
				\draw[->,>=latex] (I) edge node[above] { $\mu$ } (R);
			\end{tikzpicture}}

		\bigskip
	\end{figure}
	\begin{itemize}
	\item[-] $\tau$ is the inverse of the incubation period
	\bigskip
	\item[-] \alert{individuals are infectious from symptom onset} (when entering $I$)
	$$
	\lambda = \beta \frac{I}{N}
	$$
	\end{itemize}
	\end{itemize}

}

\frame{
	\frametitle{Model development}
	\bigskip
	\alert{Pre-symptomatic transmission}:
	\begin{itemize}
		\item \alert{SEPIR}: adding a compartment \alert{P for pre-symptomatic}, i.e. not yet symptomatic but already infectious
		\bigskip
	\begin{figure}
		\scalebox{.8}{\begin{tikzpicture}
				% cascade of care
				\node[circle, draw, inner sep=0pt, minimum size=1cm] (S) at (0,0) {$S$};
				\node[circle, draw, inner sep=0pt, minimum size=1cm] (E) at (3,0) {$E$};
				\node[circle, draw, inner sep=0pt, minimum size=1cm] (P) at (6,0) {$P$};
				\node[circle, draw, inner sep=0pt, minimum size=1cm] (I) at (9,0) {$I$};
				\node[circle, draw, inner sep=0pt, minimum size=1cm] (R) at (12,0) {$R$};

				\draw[->,>=latex] (S) edge node[above] { $\lambda$} (E);
				\draw[->,>=latex] (E) edge node[above] { $\tau_1$ } (P);
				\draw[->,>=latex] (P) edge node[above] { $\tau_2$ } (I);
				\draw[->,>=latex] (I) edge node[above] { $\mu$ } (R);
		\end{tikzpicture}}

		\bigskip
	\end{figure}
	\begin{itemize}
		\item[-] the incubation period is split in two phases with rates $\tau_1$ and $\tau_2$
		\item[-] individuals are infectious \alert{before symptom onset} (entering $P$)
		$$
		\lambda = \beta \frac{P+I}{N}
		$$
		\item[-] we can introduce \alert{reduced transmissibility} before symptom onset
		$$
		\lambda = \beta \frac{\kappa P+I}{N}
		$$
	\end{itemize}
\end{itemize}
}

\frame{
	\frametitle{Model development}
	\bigskip
	\alert{Asymptomatic} infections:
	\begin{itemize}
		\item \alert{SEPIAR}: adding a compartment \alert{A for asymptomatic}
		\bigskip
		\begin{figure}
			\scalebox{.8}{\begin{tikzpicture}
					% cascade of care
					\node[circle, draw, inner sep=0pt, minimum size=1cm] (S) at (0,0) {$S$};
					\node[circle, draw, inner sep=0pt, minimum size=1cm] (E) at (3,0) {$E$};
					\node[circle, draw, inner sep=0pt, minimum size=1cm] (P) at (6,0) {$P$};
					\node[circle, draw, inner sep=0pt, minimum size=1cm] (A) at (9,1) {$A$};
					\node[circle, draw, inner sep=0pt, minimum size=1cm] (I) at (9,-1) {$I$};
					\node[circle, draw, inner sep=0pt, minimum size=1cm] (R) at (12,0) {$R$};

					\draw[->,>=latex] (S) edge node[above] { $\lambda$} (E);
					\draw[->,>=latex] (E) edge node[above] { $\tau_1$ } (P);
					\draw[->,>=latex] (P) edge node[above] { $\phi\tau_2$ } (I);
					\draw[->,>=latex] (P) edge node[above] { $(1-\phi)\tau_2$ } (A);
					\draw[->,>=latex] (I) edge node[above] { $\mu$ } (R);
					\draw[->,>=latex] (A) edge node[above] { $\mu$ } (R);
			\end{tikzpicture}}

			\bigskip
		\end{figure}
		\begin{itemize}
			\item[-] we introduce the proportion of symptomatics $\phi$

			\item[-] we can introduce \alert{reduced transmissibility} for asymptomatics
			$$
			\lambda = \beta \frac{\kappa P+I+ \kappa A}{N}
			$$
		\end{itemize}
	\end{itemize}
}

\frame{
	\frametitle{Model development}
	\alert{Age stratification}:
	\begin{itemize}
		\item the \alert{transmission} of respiratory viruses (influenza virus, rhinovirus...) is {highly dependent on age}
		\item the \alert{mortality} of respiratory infections (even more so for SARS-CoV-2) is highly dependent on age
		\bigskip
		\item[$\rightarrow$] stratification in nine age groups $k\in\{1,\ldots,9\}$ for (0-9, \ldots, 80+)
		\end{itemize}
	\begin{figure}
	\scalebox{.8}{\begin{tikzpicture}
			% cascade of care
			\node[circle, draw, inner sep=0pt, minimum size=1cm] (S) at (0,0) {$S_k$};
			\node[circle, draw, inner sep=0pt, minimum size=1cm] (E) at (3,0) {$E_k$};
			\node[circle, draw, inner sep=0pt, minimum size=1cm] (P) at (6,0) {$P_k$};
			\node[circle, draw, inner sep=0pt, minimum size=1cm] (A) at (9,1) {$A_k$};
			\node[circle, draw, inner sep=0pt, minimum size=1cm] (I) at (9,-1) {$I_k$};
			\node[circle, draw, inner sep=0pt, minimum size=1cm] (R) at (12,0) {$R_k$};

			\draw[->,>=latex] (S) edge node[above] { $\lambda_k$} (E);
			\draw[->,>=latex] (E) edge node[above] { $\tau_1$ } (P);
			\draw[->,>=latex] (P) edge node[above] { $\phi\tau_2$ } (I);
			\draw[->,>=latex] (P) edge node[above] { $(1-\phi)\tau_2$ } (A);
			\draw[->,>=latex] (I) edge node[above] { $\mu$ } (R);
			\draw[->,>=latex] (A) edge node[above] { $\mu$ } (R);
	\end{tikzpicture}}

	\end{figure}
}

\frame{
	\frametitle{Model development}
	Characterizing the \alert{force of infection}:
	\begin{itemize}
		\item in the simple SIR, the force of infection is defined as the rate at which susceptible individuals acquire infection
		$$
		\lambda = \beta \frac{I}{N}
		$$

		\item the transmission rate $\beta$ can be split in a \alert{contact rate} $c$ times a \alert{probability of transmission upon contact} $\beta$, so that
		$$
		\lambda = \beta c \frac{I}{N}
		$$

		\faWarning\ the same symbol $\beta$ is used for the transmission rate and the probability of transmission upon contact depending on context
	\end{itemize}
}

\frame{
	\frametitle{Model development}
	\begin{itemize}
		\item time-dependent force of infection using a \alert{forcing function}
		$$
		\lambda = f(t) \beta c \frac{I}{N}
		$$
	\begin{itemize}
		\item[-] to model the effect of control measures, we want a downward function that maps onto the interval $[0,1]$, e.g. a \alert{logistic function}:
		$$
	f(t) = \eta + \frac{1-\eta}{1+\exp(\xi(t-t_c-\nu))}
		$$

		\item[-] $\eta$ is the \alert{relative reduction in transmission} after control measures

		\item[-] $\xi$ is the \alert{slope} of implementation of the control measures

		\item[-] $\nu$ is the \alert{delay} until the control measures are 50\% effective (in days after $t_c$, the date of introduction of control measures).

	\end{itemize}
	\end{itemize}
	}
\frame{
	\frametitle{Model development}
	\begin{figure}
		\centering
		\only<1>{
			with $t_c=10$; $\eta=0.25$; $\nu=3$ and $\xi=0.5$ \\ \bigskip
		\includegraphics[width=.6\linewidth]{example_hauser/example_logfunc1.pdf}
		}
		\only<2>{
			with $\eta = 0.5$ instead of $0.25$, we get \\ \bigskip
		\includegraphics[width=.6\linewidth]{example_hauser/example_logfunc2.pdf}
		}
		\only<3>{
			with $\nu = 8$ instead of $3$, we get \\ \bigskip
			\includegraphics[width=.6\linewidth]{example_hauser/example_logfunc3.pdf}
		}
		\only<4>{
			with $\xi = 1.5$ instead of $0.5$, we get \\ \bigskip
			\includegraphics[width=.6\linewidth]{example_hauser/example_logfunc4.pdf}
		}
	\end{figure}

}

\frame{
	\frametitle{Model development}
	\begin{itemize}
		\item we account for \alert{behaviour differences across age groups}:
		$$
		\lambda_k(t) = f(t) \beta \sum_{l=1}^9  \mathds{F}_{k,l}  \dfrac{I_l}{N_l}
		$$
			\begin{itemize}
			\item[-] one force of infection for each age group $k$
			\item[-] includes a specific contact rate between age group $k$ and each age group $l$ (corresponding to one cell of the \alert{contact matrix} $\mathds{F}_{k,l}$)
			\item[-] includes the prevalence in age group $l$ ($I_l/N_l$)

		\end{itemize}
	\end{itemize}

}
\frame{
	\frametitle{Model development}
	Age-specific contact matrix in China
	\begin{figure}
	\centering
	\includegraphics[width=.7\linewidth]{example_hauser/contact_matrix_china.png}
\end{figure}
}

\frame{
	\frametitle{Model development}
	Model fit to reported cases:
	\begin{itemize}
	\item obtaining \alert{incidence} from the ODE output:

	\begin{figure}
		\scalebox{.8}{\begin{tikzpicture}
				% cascade of care
				\node[circle, draw, inner sep=0pt, minimum size=1cm] (S) at (0,0) {$S_k$};
				\node[circle, draw, inner sep=0pt, minimum size=1cm] (E) at (3,0) {$E_k$};
				\node[circle, draw, inner sep=0pt, minimum size=1cm] (P) at (6,0) {$P_k$};
				\node[circle, draw, inner sep=0pt, minimum size=1cm,gray,dashed] (C) at (8.5,-2.5) {$C_k$};
				\node[circle, draw, inner sep=0pt, minimum size=1cm,gray,dashed] (rho_C) at (12,-2.5) {$\rho_k C_k$};
				\node[circle, draw, inner sep=0pt, minimum size=1cm,fill=white] (I) at (9,-1) {$I_k$};
				\node[circle, draw, inner sep=0pt, minimum size=1cm] (A) at (9,1) {$A_k$};
				\node[circle, draw, inner sep=0pt, minimum size=1cm] (R) at (12,0) {$R_k$};

				\draw[->,>=latex] (S) edge node[above] { $\lambda_k(t)$} (E);
				\draw[->,>=latex] (E) edge node[above] { $\tau_1$ } (P);
				\draw[->,>=latex] (P) edge node[yshift=10,xshift=-5] { $\tau_2(1-\psi)$ } (A);
				\draw[->,>=latex] (P) edge node[above] { $\tau_2\psi$ } (I);
				\draw[->,>=latex,gray,dashed] (P) edge[bend left=12] node[below] { $\tau_2\psi$ } (C);
				\draw[->,>=latex] (A) edge node[above] { $\mu$ } (R);
				\draw[->,>=latex] (I) edge node[above] { $\mu$ } (R);
				\draw[double,gray] (C) -- node[above] { $\rho_k$ }  (rho_C);
			\end{tikzpicture}
		}
	\end{figure}
	\begin{itemize}
	\item[-] dummy compartment $C_k(t)$ records the cumulative incidence of symptomatic infections for each age group $k$
	$$
		\frac{dC_k}{dt} = \tau_2 \psi P_k
		$$
\end{itemize}
\end{itemize}

}

\frame{
	\frametitle{Model development}

\begin{itemize}
	\item new symptomatic infections by day of symptom onset by age:
	$$
		\Delta C_{k,t} =  C_k(t) - C_k(t-1)
	$$
	\item \alert{new reported infections} per day of symptom onset, introducing the age-specific \alert{ascertainment proportion $\rho_k$}:
	$$
		A_t = \sum_k^9 \rho_k \Delta C_{k,t}^{I}
		\label{eq:g}
	$$
	\item the \alert{age distribution} of all reported cases up to $t_{\text{max}}$ :
	$$
		B_k =  \frac{\rho_k C^I_k(t_{\text{max}})}{\sum_k^9 \rho_k C^I_k(t_{\text{max}})}
	$$

\end{itemize}
}
\frame{
	\frametitle{Model development}

\begin{itemize}

	\item $A_t$ can be mapped to \alert{reported incidence data $\mathds{A}$} using a negative binomial likelihood:
	$$
	\Pr(\theta| \mathds{A}) =  \prod_{t=t_1}^{t_{\text{max}}} \text{Neg-Bin}(\mathds{A}_t| A_t,\phi_1)
	$$

	\item $B_k$ can be mapped to the \alert{age distribution of reported cases $\mathds{B}$} using a multinomial likelihood:
	$$
		\Pr(\theta| \mathds{B}) = \text{Multinomial}(\mathds{B}_1,\ldots,\mathds{B}_9|B_1,\ldots,B_9)
	$$
\end{itemize}
}

\frame{
	\frametitle{Model development}
	Model fit to deaths:
	\begin{itemize}
		\item mortality is considered outside of the system of ODEs, using an age-specific \alert{mortality parameter $\varepsilon_k$} (probability of death given \textit{symptomatic} infection)
		\item we account for the delay with a discretized log-normal distribution of time from symptom onset to death $\mathds{I}$ of length 60
	\begin{figure}
		\centering
		\includegraphics[width=.6\linewidth]{example_hauser/distribution_onset_to_death.pdf}
	\end{figure}

\end{itemize}
}

\frame{
	\frametitle{Model development}
	\begin{itemize}
		\item deaths in age group $k$ at time $t$ ($1\leq t \leq t_{\text{max}}+60$) among people infected up to $t_{\text{max}}$:
		$$
			M_{k,t}= \varepsilon_k\sum_d^{60}  \Delta C_{k,t-d} \mathds{I}_d
			\label{eq:h}
		$$
		\item deaths summed over age groups, assuming that all deaths are reported:
		$$
			M_{t}= \sum_k^9 M_{k,t}
		$$
			\item the \alert{age distribution of all deaths} occurring up to $t_{\text{max}}$:
		$$
		D_k = \frac{\sum_{t=1}^{t_{\text{max}}} M_{k,t}}{ \sum_{t=1}^{t_{\text{max}}} M_{t}}
		$$
	\end{itemize}
}

\frame{
	\frametitle{Model development}
	\begin{itemize}
	\item $M_t$ can be mapped to \alert{daily death data $\mathds{C}$} using a negative binomial likelihood:
	$$
	\Pr(\theta| \mathds{C}) =  \prod_{t=t_1}^{t_{\text{max}}} \text{Neg-Bin}(\mathds{C}_t|M_t,\phi_2)
	$$

	\item $D_k$ can be mapped to the \alert{age distribution of deaths $\mathds{D}$} using a multinomial likelihood:
	$$
		\Pr(\theta| \mathds{D}) = \text{Multinomial}(\mathds{D}_1,\ldots,\mathds{D}_9|D_1,\ldots,D_9)
	$$
	\end{itemize}
	\bigskip
	This leads to the following joint likelihood:
	$$
	\Pr(\theta | \mathds{A},\mathds{B},\mathds{C},\mathds{D}) = \Pr(\theta| \mathds{A}) \cdot \Pr(\theta| \mathds{B}) \cdot \Pr(\theta| \mathds{C}) \cdot \Pr(\theta| \mathds{D})
	$$

	with  $\theta=\{\beta, \eta, \xi, \nu, \psi, \pi, \rho_k, \varepsilon_k, \phi_1, \phi_2 \}$.
}

\frame{
	\frametitle{Model development}
	Last bits:
	\begin{itemize}
		\item there is an \alert{identifiability issue with $\rho$}
		\item[$\rightarrow$] fix $\rho_9$ (for 80+) to 100\%, assuming that all symptomatic infections among very high risk persons will be reported
		\bigskip
		\item some \alert{remaining unknowns} (data correction in China, role of children, lower $\rho_9$...)
		\item[$\rightarrow$] sensitivity analyses
	\end{itemize}
}

\frame{
	\frametitle{Inference}
	You know the drill:
	\begin{itemize}
		\item set priors
		\item prior predictive check
		\item sampling (on high performance computing cluster $\sim$ 2h)
		\item basic diagnostic tests
		\item examine trace plots and chains
		\item posterior predictive check
	\end{itemize}
}

\frame{
	\frametitle{Results in Hubei}
	Posterior predictive check (Hubei):
		\begin{figure}
		\centering
		\includegraphics[width=1\linewidth]{example_hauser/supp_fit_16B.pdf}
	\end{figure}

}

\frame{
	\frametitle{Results in Hubei}
	Ascertainment (posteriors of $\rho_k$):
	\begin{figure}
		\centering
		\includegraphics[width=.7\linewidth]{example_hauser/ascertainment.png}
	\end{figure}

}

\frame{
	\frametitle{Results in Hubei}
	Mortality among symptomatics or sCFR (posteriors of $\varepsilon_k$):
	\begin{figure}
		\centering
		\includegraphics[width=.7\linewidth]{example_hauser/scfr.png}
	\end{figure}

}

\frame{
	\frametitle{Results in Hubei}
	Effect on the assumption on $\rho_9$ on IFR estimate:
	\begin{figure}
		\centering
		\includegraphics[width=.7\linewidth]{example_hauser/rho9.png}
	\end{figure}

}

\frame{
	\frametitle{Results in all regions}
	Posterior predictive check (Spain):
	\begin{figure}
		\centering
		\includegraphics[width=1.01\linewidth]{example_hauser/supp_fit_spain.pdf}
	\end{figure}

}

\frame{
	\frametitle{Results in all regions}
	\alert{IFR estimates} (compared to CFR and sCFR)
	\begin{figure}
		\centering
		\includegraphics[width=.7\linewidth]{example_hauser/ifr_all.png}
	\end{figure}

}
\frame{
	\frametitle{Results in all regions}
	\alert{IFR estimates} by age
	\begin{figure}
		\centering
		\includegraphics[width=.7\linewidth]{example_hauser/ifr_age_all.png}
	\end{figure}

}
\frame{
	\frametitle{Conclusions}
	\begin{figure}
		\centering
		\includegraphics[width=\linewidth]{example_hauser/table_res.png}
	\end{figure}
	\begin{itemize}
		\item IFR estimates adjusted for under-ascertainment and right-censoring are \alert{more similar across countries} than CFR
		\item still some degree of \alert{heterogeneity}
		\item clear \alert{increase of mortality with age}
	\end{itemize}
}
\frame{
	\frametitle{Conclusions}
	General comments:
	\begin{itemize}
		\item knowing the \alert{data-generating mechanisms} to avoid misinterpretation
		\item this knowledge can be used to build a model to adjust for known biases
		\item estimates of IFR obtained \alert{early in the epidemic}, mostly confirmed in later seroprevalence studies
	\end{itemize}
}

\frame{
	\frametitle{Acknowledgements \& ressources}
	\alert{General Bayesian inference \& \texttt{Stan}:}
	\begin{itemize}
		\item Andrew Gelman et al. \textit{Bayesian Data Analysis} \\ \url{http://www.stat.columbia.edu/~gelman/book/}
		\item Michael Betancourt, \textit{Introduction to Stan} \\ \url{https://betanalpha.github.io/assets/case_studies/stan_intro.html}
		\item Andrew Gelman et al., \textit{Bayesian workflow} \\ \url{https://arxiv.org/abs/2011.01808}
		\item Jonah Gabry et al., \textit{Visualization in Bayesian workflow} \\ \url{https://arxiv.org/abs/1709.01449}
		\item Sean Talts et al., \textit{Simulation-based calibration}  \\ \url{https://arxiv.org/abs/1804.06788}

	\end{itemize}
}

\frame{
	\frametitle{Acknowledgements \& ressources}
	\alert{\texttt{Stan} and ODEs or infectious disease models:}
	\begin{itemize}
		\item Daniel Lee, \textit{ODEs in Stan} \\ \url{https://youtu.be/hJ34_xJhYeY}
		\item Chatzilena et al., \textit{Contemporary statistical inference for ID models} \\
		\url{https://www.sciencedirect.com/science/article/pii/S1755436519300325}
		\item Bob Carpenter, \textit{Population dynamics: the Lotka-Volterra model} \\ \url{https://mc-stan.org/users/documentation/case-studies/lotka-volterra-predator-prey.html}
		\item Grinsztajn et al., \textit{Bayesian workflow for disease transmission modeling in Stan} \\ \url{https://arxiv.org/abs/2006.02985}
	\end{itemize}
}

\end{document}


\chapter*{Books}

Many of the statistical analyses encountered to date consist of a \emph{single response variable} and \emph{one or more explanatory variables}.  In this latter case, \emph{multiple regression}, we regressed a single response (dependent) variable on a number of explanatory (independent) variables.   This is occasionally referred to as ``multivariate regression'' which is all rather unfortunate.   There isn't an entirely clear ``canon'' of what is a multivariate technique and what isn't (one could argue that discriminant analysis involves a single dependent variable).   However, we are going to consider the simultaneous analysis of a number of related variables.   We may approach this in one of two ways.   The first group of problems relates to classification, where attention is focussed on individuals who are more alike.   In unsupervised classification (cluster analysis) we are concerned with a range of algorithms that at least try to identify individuals who are more alike if not to distinguish clear groups of individuals.   There are also a wide range of scaling techniques which help us visualise these differences in lower dimensionality.   In supervised classification (discriminant analysis) we already have information on group membership, and wish to develop rules from the data to classify future observations.

The other group of problems concerns inter-relationships between variables.   Again, we may be interested in lower dimension that help us visualise a given dataset.   Alternatively, we may be interested to see how one group of variables is correlated with another group of variables.   Finally, we may be interested in models for the interrelationships between variables.

%Here are a few examples of multivariate analyses.

%(a) Skulls have been recovered from an ancient burial ground.   These may come from one group, or a mixture of ethnic groups slaughtered in battle.   If we make a number of measurements on the skulls can we estimate the number of groups inovled.

%(b) Data are identified on business activity, such as national income, rate of interest, unemployment.   Can we generate a single index of ``business activity''.

%(c) A social scientist wishes to confirm the concept of ``self esteem'', based on student survey with 10 questions on attitudes.   Are the answers consistent with the existence of such a non-measurable concept.

%\subsection{Objectives}

%\begin{itemize}
%\item Grouping or sorting - objects, individuals or variables are arranged into similar clusters or groups
%\item Prediction or decision making - number of groups is known but rule(s) are required to classify individuals or objects into such groups
%\item Data reduction or simplification - relatively few indices are constructed from many measured variables
%\item Hypotheses are postulated, tested, investigated - either by analogy to univariate hypotheses or an attempt to reveal underlying influences or latent structure
%\end{itemize}

There is a reasonably established range of multivariate techniques which we will cover here.   Introductory level books include  \cite{Johnson+Wichern:2002}
%\cite{Afifi+Clark:1990} \cite{Chatfield+Collins:1980} \cite{Dillon+Goldstein:1984} \cite{Everitt+Dunn:1991} \cite{Flury+Riedwyl:1988} \cite{Johnson:1998}
%\cite{Kendall:1975} \cite{Hair+etal:1995} \cite{Hair+etal:1998} \cite{Manly:1994}

Intermediate level books include:
\cite{Flury:1997} (My personal favourite)
%\cite{Gnanadesikan:1997}
%\cite{Harris:1985} \cite{Krzanowski:2000} \cite{Krzanowski+Marriott:1994,Krzanowski+Marriott:1994II} \cite{Rencher:2002} \cite{Morrison:2005}
%\cite{Seber:1984} \cite{Timm:1975}

More advanced books:
%\cite{Anderson:1984} (I think there's a 2003 edition now) \cite{Bilodeau+Brenner:1999} \cite{Giri:2003} \cite{Mardia+etal:1979} \cite{Muirhead:1982}
\cite{Press:1982} \cite{Srivastava+Carter:1983}.

If you hunt around you will notice that the ``canon'' of multiviate methods does vary.   Some people include contingency tables and log-linear modelling, others exclude Cluster analysis.   Given that multivariate methods are particularly common in applied areas such Ecology and Psychology, it is worth a browse around library sections containing books aimed at these subjects.   It is quite possible that they will have very readable descriptions of particular techniques.   In particular, there seems to be a copious collection of books aimed at Psychologists on Factor Analysis - but there are a few caveats in the way they approach this technique and these books need to be read in the light of cautions given during lectures.

%%% Local Variables: ***
%%% mode:latex ***
%%% TeX-master: "../book.tex"  ***
%%% End: ***