
% \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{Censoring and Likelihood\footnote{See last slide for copyright information.}}
\subtitle{STA312 Spring 2019}
\date{} % To suppress date


\begin{document}

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


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

\begin{frame}[fragile]
\frametitle{Censored Data}
%\framesubtitle{} 
  \begin{itemize}
    \item Let $T^*$ represent time to failure. \pause
    \item Let $U$ represent censoring time. \pause
    \item We observe $T=\min(T^*,U)$. \pause
    \item And an indicator for whether failure occurred: \pause $\delta = 1$ if  uncensored\pause, and zero if censored. \pause
    \item All this is $i=1, \ldots,n$, so we observe $n$ pairs \pause $(T_1,\delta_1), (T_2,\delta_2), \ldots, (T_n,\delta_n)$.  \pause
    \item A simple data file might look like this:
  \end{itemize}
\begin{verbatim} 
Patient     Time        Uncensored (delta)
    1         5             1
    2         6             0
    3         8             1
    4         3             1
    5        22             1
\end{verbatim}
\end{frame}

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

\begin{frame}[fragile]
\frametitle{Simulation code}
\framesubtitle{To illustrate the process} 
{\footnotesize % or scriptsize
\begin{verbatim}
# Exponential distribution, true parameter lambda, right censoring
# Censoring times will be uniform(0,top)
# Observation will be censored if censoring time is less than lifetime.
rm(list=ls()); options(scipen=999)
lambda = 1/5; top=20 # True parameters
# Simulate
set.seed(9999); n = 200
delta = numeric(n) # Indicator for uncensored, initially zero
lifetime = rexp(n,rate=lambda)
censortime = runif(n,0,top)
# If censoring time is greater than lifetime, then it's NOT censored.
delta[censortime>lifetime] = 1
# Minumum of censortime and lifetime is what we can observe.
T = pmin(censortime,lifetime) # pmin is parallel minimum. 
round(cbind(lifetime,censortime,T,delta)[1:10,],2) # Take a look
expodata = cbind(T,delta) # This is all you can see in practice.
\end{verbatim} 
} % End size
Note that censoring time is independent of lifetime, and they share no parameters.
\end{frame}

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

\begin{frame}[fragile]
\frametitle{Output}
%\framesubtitle{} 
{\footnotesize % or scriptsize
{\color{blue}
\begin{verbatim}
round(cbind(lifetime,censortime,T,delta)[1:10,],2) # Take a look
\end{verbatim}
} % End color
\begin{verbatim}
      lifetime censortime    T delta
 [1,]     2.29       1.38 1.38     0
 [2,]    10.24       4.31 4.31     0
 [3,]     1.89      13.23 1.89     1
 [4,]     3.45      14.61 3.45     1
 [5,]     9.77      17.82 9.77     1
 [6,]     2.41      16.46 2.41     1
 [7,]     3.18      13.83 3.18     1
 [8,]    20.50       7.41 7.41     0
 [9,]     8.64       8.53 8.53     0
[10,]     2.65      19.61 2.65     1
\end{verbatim} 
} % End size
\end{frame}



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

\begin{frame}
\frametitle{Likelihood function for censored data}
\framesubtitle{Possibly right censored, with random censoring} \pause
{\LARGE
\begin{eqnarray*}
    L(\theta) & = & \prod_{i=1}^n f(t_i|\theta)^{\delta_i} \, S(t_i|\theta)^{1-\delta_i} \\ \pause
&& ~\strut \\
    \ell(\theta) & = & \sum_{i=1}^n \left(\strut \delta_i \log f(t_i|\theta) + (1-\delta_i) \log S(t_i|\theta) \right) \\ \pause
    &=& \sum_{i=1}^n  \delta_i \log f(t_i|\theta) + \sum_{i=1}^n (1-\delta_i) \log S(t_i|\theta) 
\end{eqnarray*} 
} % End size
\end{frame}


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

\begin{frame}
\frametitle{Example: $T_1, \ldots, T_n \stackrel{i.i.d}{\sim} \exp(\lambda)$}
\framesubtitle{$F(t|\lambda) = 1-e^{-\lambda t}$, Ordinary $\widehat{\lambda}_n = 1/\overline{T}_n$} \pause
{\LARGE
\begin{displaymath}
    L(\theta) = \prod_{i=1}^n \left(\lambda e^{-\lambda t_i}\right)^{\delta_i} \, 
    \left(e^{-\lambda t_i}\right)^{1-\delta_i}
\end{displaymath} \pause
} % End size
\vspace{3mm}

As an exercise, you will show that 
{\Large $\displaystyle \widehat{\lambda}_n = \frac{\sum_{i=1}^n \delta_i}{\sum_{i=1}^n t_i}$. } \pause
\vspace{2mm}

\begin{itemize}
    \item So the estimated expected value is 
    $\frac{\sum_{i=1}^n t_i}{\sum_{i=1}^n \delta_i} \pause
     > \frac{\sum_{i=1}^n t_i}{n} = \overline{T}_n$. \pause
    \item Ignoring the censoring would cause you to under-estimate average survival tme.
\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}


%%%%%%%%%% I dropped this because it was not clear enough.

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

\begin{frame}
\frametitle{What happened to the distribution of censoring time?} \pause
%\framesubtitle{} 
{\LARGE
\begin{displaymath}
    L(\theta) = \prod_{i=1}^n f(t_i|\theta)^{\delta_i} \, S(t_i|\theta)^{1-\delta_i}
\end{displaymath} \pause
} % End size
\begin{itemize}
    \item $\delta_i$  depends on survival time and censoring time, which are both random. \pause
    \item We saw this in the simulation code. \pause
    \item So $\delta_i$ is a random variable.  \pause
    \item Its distribution must depend on $\theta$  \pause and the parameters of censoring time. \pause
    \item But there is nothing like this in the likelihood function. \pause
    \item What is going on?
\end{itemize}
\end{frame}

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

\begin{frame}
\frametitle{Hidden assumptions}
\framesubtitle{That make everything okay}  \pause
\begin{itemize}
    \item Let $\theta_1$ be the parameters of survival time \pause and $\theta_2$ be the parameters of censoring time. \pause
    \item $\theta = (\theta_1,\theta_2)$ \pause
    \item For an ordinary likelihood without censoring, 
    $L(\theta) = \prod_{i=1}^n p(t_i|\theta) \pause = p_\theta(\mathbf{x})$. \pause
    \item With censoring, $L(\theta) = p_{(\theta_1,\theta_2)}(\mathbf{x},\boldsymbol{\delta})$
    
    
    \pause
\end{itemize}
\begin{eqnarray*}
    L(\theta) & = & p_{(\theta_1,\theta_2)}(\mathbf{x},\boldsymbol{\delta}) \\
     & = & p_{(\theta_1,\theta_2)}(\mathbf{x}|\boldsymbol{\delta}) \,
     p_{(\theta_1,\theta_2)}(\boldsymbol{\delta}) \\ 
     & = & p_{\theta_1}(\mathbf{x}|\boldsymbol{\delta}) \,
     p_{\theta_2}(\boldsymbol{\delta}) \\ 
\end{eqnarray*}

\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


