
% \documentclass[serif]{beamer} % Serif for Computer Modern math font.
\documentclass[serif, handout]{beamer} % Handout mode to ignore pause statements
\hypersetup{colorlinks,linkcolor=,urlcolor=red}

\usefonttheme{serif} % Looks like Computer Modern for non-math text -- nice!
\setbeamertemplate{navigation symbols}{} % Supress navigation symbols
\usetheme{AnnArbor}  % CambridgeUS Blue and yellow, Shows current section title
% \usetheme{Berlin} % Blue: Displays section titles on top
% \usetheme{Frankfurt}  % Displays section titles on top: Fairly thin but still swallows some material at bottom of crowded slides
\usepackage[english]{babel}
% \definecolor{links}{HTML}{2A1B81}
% \definecolor{links}{red}

\setbeamertemplate{footline}[frame number] 

\mode<presentation>
% \mode<handout>{\setbeamercolor{background canvas}{bg=black!5}}


\title{The Kaplan-Meier (Product Limit) Estimate\footnote{See last slide for copyright information.}}
\subtitle{STA312 Spring 2019}
\date{} % To suppress date


\begin{document}

\begin{frame}
  \titlepage
\end{frame}


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



\begin{frame}
\frametitle{The Kaplan-Meier Estimate} 
\framesubtitle{Reference: Chapter 3 in \emph{Applied Survival Analysis Using R}}  \pause
\begin{itemize}
    \item Objective: To estimate the survival function without making any assumptions about the distribution of survival time. \pause
    \item If there were no censoring, it would be easy. \pause
    \item Use the empirical distribution function: \pause the proportion of observations less than or equal to $t$. \pause

\begin{displaymath}
    \widehat{F}_n(t) = \frac{1}{n} \sum_{i=1}^n I\{t_i \leq t \}
\end{displaymath} \pause
    \item Then let $\widehat{S}_n(t) = 1-\widehat{F}_n(t)$
\end{itemize}
\end{frame}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}
\frametitle{Discrete Time}
\framesubtitle{Maybe time is always discrete in practice}  \pause
\begin{itemize}
    \item Consider times $t_0=0, t_1, t_2, \dots$\pause, maybe minutes or days.
    \item Let $q_j = $ the probability of failing at time $t_j$, given survival to time $t_{j-1}$. \pause
    \item $p_j = 1-q_j = $ the probability of surviving past time $t_j$, given survival to time $t_{j-1}$. \pause
\end{itemize}

\begin{eqnarray*}
    p_j & = & P(T>t_j|T>t_{j-1}) \\ \pause
    & = &  \frac{P(T>t_j,T>t_{j-1})}{P(T>t_{j-1})} \\ \pause
    & = &  \frac{P(T>t_j)}{P(T>t_{j-1})}   \\ \pause
    & = &  \frac{S(t_j)}{S(t_{j-1})}
\end{eqnarray*} 
\end{frame}

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

\begin{frame}
\frametitle{$p_j = \frac{S(t_j)}{S(t_{j-1})}$} \pause
%\framesubtitle{} 
With $S(t_0) = S(0)=1$, \pause
\begin{itemize}
    \item $p_1 = \frac{S(t_1)}{S(t_0)} = \frac{S(t_1)}{1} = S(t_1)$ \pause
    \item $p_2 = \frac{S(t_2)}{S(t_1)}$ \pause
    \item $p_3 = \frac{S(t_3)}{S(t_2)}$ \pause
    \item Continuing  \ldots \pause
    \item $p_k = \frac{S(t_k)}{S(t_{k-1})}$ \pause
\end{itemize}
Then, 
\begin{eqnarray*}
    &   & ~p_1 ~~~~~ p_2 ~~~~~ p_3 ~~ \cdots ~~~p_k \\ \pause
    & = & S(t_1) \frac{S(t_2)}{S(t_1)} \frac{S(t_3)}{S(t_2)}  \cdots \frac{S(t_k)}{S(t_{k-1})} \\ \pause
    & = & S(t_k)
\end{eqnarray*} 
\end{frame}

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

\begin{frame}
\frametitle{$\displaystyle S(t_k) = \prod_{j=1}^k p_j$}\pause
%\framesubtitle{} 
Estimate $S(t_k)$ by estimating the $p_j$. \pause
\begin{itemize}
    \item Let $d_j$ be the number of deaths at time $t_j$. \pause
    \item Let $n_j$ be the number of individuals at risk before time $t_j$. \pause
    \item Anyone censored before time $t_j$ is no longer at risk. \pause
    \item Estimated probability of failure at time $t_j$ is $\widehat{q}_j = \frac{d_j}{n_j}$. \pause
    \vspace{2mm}
    
\end{itemize}
{\large
\begin{eqnarray*}
    \widehat{p}_j & = & 1-\widehat{q}_j \pause = \frac{n_j-d_j}{n_j}  \\ \pause
    \widehat{S}(t_k) & = & \prod_{j=1}^k \widehat{p}_j \\ \pause
    \widehat{S}(t) & = & \prod_{t_j \leq t} \widehat{p}_j
\end{eqnarray*} 
} % End size

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}
\frametitle{Working toward a standard error for 
$ \displaystyle \widehat{S}(t) = \prod_{t_j \leq t} \widehat{p}_j$}
\framesubtitle{Large-sample Distribution Theory} \pause

\begin{itemize}
    \item $\widehat{p}_j = 1-\frac{d_j}{n_j} = \frac{n_j-d_j}{n_j}$ \pause is a sample proportion -- a sample mean. \pause
    \item It is the proportion of individuals eligible at risk for failure at time $t$, who did not fail. \pause
    \item Mean of independent Bernoullis (conditionally on $n_j$). \pause
    \item $E(\widehat{p}_j) = p_j$, $Var(\widehat{p}_j) = \frac{p_j(1-p_j)}{n_j}$ \pause
    \item $\widehat{p}_j \stackrel{.}{\sim} N(p_j, \frac{p_j(1-p_j)}{n_j})$ by the Central Limit Theorem. \pause
    \item This is for large $n_j$.
\end{itemize}
\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}
\frametitle{Large-sample Distribution Theory Continued}
\framesubtitle{$\displaystyle \widehat{S}(t) = \prod_{t_j \leq t} \widehat{p}_j $ with $\widehat{p}_j = \frac{n_j-d_j}{n_j}
\stackrel{.}{\sim} N\left(p_j, \frac{p_j(1-p_j)}{n_j}\right)$} \pause
  \begin{itemize}
    \item Sums are easier to work with than products. \pause
    \item $\log \widehat{S}(t) = \sum_{t_j \leq t} \log \widehat{p}_j$ \pause
    \item Using the one-variable delta method, 
          $\log \widehat{p}_j \stackrel{.}{\sim} N(\log p_j, \frac{1-p_j}{n_jp_j})$ \pause
    \item Sum of normals is normal \pause (asymptotically, too). \pause
    \item $E(\sum_{t_j \leq t} \log \widehat{p}_j) \approx \sum_{t_j \leq t} \log p_j  \pause
           = \log \prod_{t_j \leq t} \, p_j \pause =  \log S(t)$ \pause
        
  \end{itemize}
\begin{eqnarray*}
    Var\left(\sum_{t_j \leq t} \log \widehat{p}_j \right) 
    & \approx & \pause \sum_{t_j \leq t} Var(\log \widehat{p}_j)\\ \pause 
    & = & \sum_{t_j \leq t}  \frac{1-p_j}{n_jp_j}
\end{eqnarray*}
\end{frame}


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

\begin{frame}
\frametitle{Distribution of $\displaystyle \log \widehat{S}(t) =  \sum_{t_j \leq t} \log \widehat{p}_j$}  \pause
%\framesubtitle{}
\begin{displaymath}
    \log \widehat{S}(t) \stackrel{.}{\sim}
    N\left( \log S(t) , \sum_{t_j \leq t}  \frac{1-p_j}{n_jp_j} \right)
\end{displaymath} \pause

  \begin{itemize}
    \item This is a stepping stone to the distribution of $\widehat{S}(t)$. \pause
    \item Use the univariate delta method. \pause 
    \item Univariate delta method says that if $T_n \stackrel{.}{\sim} N(\theta,v_n)$ \pause 
          then $g(T_n) \stackrel{.}{\sim} N\left(g(\theta),v_n [g^\prime(\theta)]^2\right)$.
    \item Here, $T_n = \log \widehat{S}_n(t)$, \pause $\theta = \log S(t)$ \pause and $g(x) = e^x.$ \pause
    \item $g^\prime(\theta) = e^\theta \pause = e^{\log S(t)} \pause = S(t)$. \pause So, \pause
  \end{itemize}
  
\begin{displaymath}
    \widehat{S}(t) \stackrel{.}{\sim}
    N\left( S(t) , S(t)^2\sum_{t_j \leq t}  \frac{1-p_j}{n_jp_j} \right)
\end{displaymath} 
\end{frame}

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

\begin{frame}
\frametitle{Standard error of $\widehat{S}(t)$}
\framesubtitle{Used in the denominator of $Z$-tests and $\widehat{S}(t) \pm 1.96 \, se$} \pause
\begin{displaymath}
    \widehat{S}(t) \stackrel{.}{\sim}
    N\left( S(t) , S(t)^2\sum_{t_j \leq t}  \frac{1-p_j}{n_jp_j} \right)
\end{displaymath} 

  \begin{itemize}
    \item Of course we don't know $S(t)$ or $p_j$ in the variance. \pause
    \item So use estimates. \pause Estimate $S(t)$ with $\widehat{S}(t)$. \pause
    \item And estimate $p_j$ with $\widehat{p}_j = \frac{n_j-d_j}{n_j}$. \pause
    \item The resulting estimated asymptotic variance is 
          $\widehat{S}(t)^2 \sum_{t_j \leq t} \left(\frac{d_j}{n_j(n_j-d_j)}\right)$ \pause
    \item  This is expression (3.1.2) on p.~27 of the text. \pause
%    \item[]
    \item The standard error of $\widehat{S}(t)$ is 
          $\widehat{S}(t)\sqrt{\sum_{t_j \leq t} \left(\frac{d_j}{n_j(n_j-d_j)}\right)}$. \pause
    \item In R's \texttt{survival} package, the default confidence interval for the Kaplan-Meier estimate uses this standard error.
  \end{itemize}
\end{frame}

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

\begin{frame}
\frametitle{Counting Processes}
\framesubtitle{The theoretical state of the art} \pause
  \begin{itemize}
    \item Distribution theory for the Kaplan Meier estimate (asymptotic normality, standard error etc.) has been presented the way it was originally developed. \pause
    \item The derivation is partly sound, but it has some holes. \pause
    \item More recently, viewing number of deaths up to a point as a counting process \pause (stochastic processes, STA348 and beyond) has cleaned the whole thing up. \pause
    \item Results are the same, but now the proofs are rigorous. \pause
    \item There was some guesswork in the development of these ideas, but the main guesses were right. 
  \end{itemize}
\end{frame}

% 

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


\begin{frame}
\frametitle{Copyright Information}

This slide show was prepared by  \href{http://www.utstat.toronto.edu/~brunner}{Jerry Brunner},
Department of Statistics, University of Toronto. It is licensed under a 
\href{http://creativecommons.org/licenses/by-sa/3.0/deed.en_US}
     {Creative Commons Attribution - ShareAlike 3.0 Unported License}. Use any part of it as you like and share the result freely. The \LaTeX~source code is available from the course website:
\href{http://www.utstat.toronto.edu/~brunner/oldclass/312s19} {\footnotesize \texttt{http://www.utstat.toronto.edu/$^\sim$brunner/oldclass/312s19}}

\end{frame}


\end{document}



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

\begin{frame}
\frametitle{}\pause
%\framesubtitle{} 
  \begin{itemize}
    \item \pause
    \item \pause
    \item 
  \end{itemize}
\end{frame}

{\LARGE
\begin{displaymath}
    \log \widehat{S}(t) = \sum_{t_j \leq t} \log \widehat{p}_j
\end{displaymath}  \pause
} % End size


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


% I like this but it's not implemented in the survival package.
\begin{frame}
\frametitle{Log Survival Function }
\framesubtitle{That is, the log \emph{estimated} survival function}  \pause
\begin{displaymath}
    \log \widehat{S}(t) = \sum_{t_j \leq t} \log \widehat{p}_j \stackrel{.}{\sim}
    N\left( \log S(t) , \sum_{t_j \leq t}  \frac{1-p_j}{n_jp_j} \right)
\end{displaymath} \pause
  \begin{itemize}
    \item For any fixed $t$, we can get a point estimate and a confidence interval for $\log S(t)$. \pause
    \item Convert to a CI for $S(t)$ by taking the exponential function. \\ \pause
    $0.95 \approx P\{A \leq \log S(t) \leq B \} \pause = P\{e^A \leq S(t) \leq e^B \} $. \pause
    \item For the standard error of $\log \widehat{S}(t)$, estimate $p_j$ with $\widehat{p}_j = \frac{n_j-d_j}{n_j}$. \pause
    \item Estimated variance of $\log \widehat{S}(t)$ is $\sum_{t_j \leq t} \left(\frac{d_j}{n_j(n_j-d_j)}\right)$. \pause
    \item This is expression 3.1.1 on p.~27 of the text. \pause
    \item Standard error of  $\log \widehat{S}(t)$ is 
          $\sqrt{\sum_{t_j \leq t} \left(\frac{d_j}{n_j(n_j-d_j)}\right)}$.
  \end{itemize}
  
\end{frame}

