%& --translate-file cp1250pl
\documentclass[xcolor=dvipsnames,10pt]{beamer}
% ********** Styl prezentacji **********
\usepackage[polish]{babel}
\usepackage{polski}
\usepackage{graphicx}
\mode<presentation>
{
	\usetheme{Warsaw}
  \usecolortheme[named=purple]{structure}
  \beamertemplateshadingbackground{yellow!10}{orange!5} 
  \setbeamercovered{transparent}
}



\title[Survival Analysis]{Survival Analysis}

\author[Branicka, P�kalski] % (optional, use only with lots of authors)
{Survival Analysis - analiza prze�y�}


\date[15 pa�dziernik 2008] 
{Statystyka Medyczna}

\subject{Statystyka Medyczna 2008/09}



\AtBeginSubsection[]
{
	\begin{frame}<beamer>
		\frametitle{Plan wyk�adu}
		\tableofcontents[currentsection,currentsubsection]
	\end{frame}
}


\begin{document}

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

\begin{frame}
	\frametitle{Plan wyk�adu}
	\tableofcontents
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Wprowadzenie}
\begin{frame}
	G��wne cechy modelu prze�ycia:
	\begin{itemize}
		\item co najwy�ej jedno zdarzenie na 'przedmiot' badania (mo�na umrze� tylko raz)
		\item rozk�ad ma du�� sko�no��, zazwyczaj dodatni�
		\item cenzorowanie mo�e mie� miejsce (nie wszyscy s� obserwowani ca�y czas)
	\end{itemize}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}
	Czemu standardowe techniki mog� nie zadzia�a�?
	\begin{itemize}
		\item zazwyczaj zak�ada si� rozk�ad normalny (brak normalno�ci psuje wszystko)
		\item standardowo dane nie s� cenzorowane (cenzorowanie spowoduje brak zgodno�ci estymatora)
	\end{itemize}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}
	\frametitle{Podstawowe poj�cia}
		\begin{itemize}
			\item \alert{survival time} - czas do momentu wydarzenia si� jakiego� zdarzenia
			\item \alert{failure} - zdarzenie na kt�re czekamy
		\end{itemize}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}
	\frametitle{Przyk�ady}
		\begin{itemize}
			\item prze�ywalno�� pacjent�w po operacji (�miertelno��)
			\item d�ugo�� trwania ma��e�stwa od �lubu
			\item czas pozostawania/mieszkania w jednym mie�cie (migracje)
			\item d�ugo�� �ycia
		\end{itemize}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}
	\frametitle{Powiazanie czasu i wydarze�}
	Niech \alert{$T$} b�dzie (nieujemn�) zmienn� losow� oznaczaj�c� \alert{czas} do interesuj�cego nas zdarzenia (survival time). Wtedy dystrybuanta
\begin{center}
	$F(t)=\mathbb{P}(T\leq t),\quad t\geq 0$
\end{center}
oznacza prawdopodobie�stwo, �e nasze zdarzenie wydarzy si� przed czasem \alert{$t$}. 
$\newline\newline$  
W biomedycynie u�ywa si� \alert{funkcji prze�ycia} (survival function) 
\begin{center}
	$S(t)\equiv\mathbb{P}(T\geq t) = 1- F(t^{-})$
\end{center}
wtedy \alert{$S(t)$} oznacza prawdopodobie�stwo, �e obiekt \alert{prze�yje} do czasu \alert{$t$}.
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}
	\frametitle{Intuicja dla $S(t)$}
	\begin{center}
	$S(t)=\mathbb{P}(T\geq t) = 1- F(t^{-})$
	\end{center}
	W�asno�ci $S(t)$:
	\begin{itemize}
	\item w \alert{$t=0$} mamy \alert{$S(t)=1$}, czyli nikt jeszcze nie umar�
	\item w \alert{$t=\infty$} mamy \alert{$S(t)=0$}, czyli w ko�cu ka�dy kiedy� umrze
	\end{itemize}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Hazard Rate}
\begin{frame}
	\frametitle{Podstawowe poj�cia}
	\alert{mortality rate} - procent populacji, dla kt�rej b�dzie mia�o miejsce oczekiwane zdarzenie (np. �mier�) w okresie mi�dzy \alert{$t$} oraz \alert{$t+1$}, dla kt�rych nie mia�o miejsce oczekiwane zdarzenie (osobnik �y� w czasie \alert{$t$})
	\begin{center}
		$m(t)=\mathbb{P}(t\leq T < t +1\,|\,T\geq t)$
	\end{center}
	\alert{hazard rate}
	\begin{center}
		$\lambda(t)=\lim\limits_{\triangle t\rightarrow 0}\frac{\mathbb{P}(t\leq T < t +\triangle t\,|\,T\geq t)}{\triangle t}$
	\end{center}
	je�li $\triangle t$ jest ma�e
	\begin{center}
		$\mathbb{P}(t\leq T < t +\triangle t\,|\,T\geq t) \approx \lambda(t)\triangle t$
	\end{center}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}
	\frametitle{Inny wz�r}
	Wz�r
	\begin{center}
	$\lambda(t)=\lim\limits_{\triangle t\rightarrow 0}\frac{\mathbb{P}(t\leq T < t +\triangle t\,|\,T\geq t)}{\triangle t}$
	\end{center}
	mo�na zapisa� jako
	\begin{center}
	$\lambda(t)=\frac{\lim\limits_{\triangle t\rightarrow 0}\frac{\mathbb{P}(t\leq T < t +\triangle t)}{\triangle t}}{ \mathbb{P}(T\geq t)} =\frac{f(t)}{S(t)}=-\frac{S^{\prime}(t)}{S(t)}=-\frac{d\log[S(t)]}{dt}$
	\end{center}
	ca�kuj�c obie strony otrzymujemy
	\begin{center}
		$\Lambda(t)=\int\limits^t_0\lambda(u)\,du=\log[S(0)]-\log[S(t)]=-\log[S(t)]$
	\end{center}
	$\Lambda(t)$ oznacza \textquotedblleft akumulacj�\textquotedblright hazardu w czasie i jest zwana \alert{cumulative hazard function} - analog dystrybuanty dla g�sto�ci rozk�adu 
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}
	\frametitle{Inny wz�r c.d.}
	Ze wzoru 
	\begin{center}
		$\Lambda(t)=-\log[S(t)]$
	\end{center}
	mo�na wyliczy� $S(t)$
	\begin{center}
		$S(t)=\exp(-\Lambda(t))=\exp(-\int\limits_0^t\lambda(u)du)$
	\end{center}
	Uwaga:
	\begin{center}
		hazard rate \alert{nie jest} prawdopodobie�stwem, mo�e wi�c by� wi�ksze od $1$.
	\end{center}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}
	\begin{figure}
		\includegraphics[height=7.5cm]{hazard.pdf}
	\end{figure}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Cenzorowanie}
\begin{frame}
\frametitle{Kogo cenzurujemy?}
Cenzorowane s� te obserwacje, dla kt�rych oczekiwane zdarzenie nie mia�o miejsca do ko�ca rozpatrywanego czasu 
\begin{itemize}
\item prawostronne cenzorowanie: je�li zdarzenie mia�o miejsce \alert{po} czasie obserwacji 
\item lewostronne cenzorowanie: je�li zdarzenie mia�o miejsce \alert{przed} rozpocz�ciem obserwacji
\item cenzorowanie przedzia�owe: je�li wiadomo, �e zdarzenie mia�o miejsce w jakim� przedziale czasowym, ale dok�adny czas nie jest znany
\end{itemize}
\begin{figure}
\includegraphics[width=10cm]{przed_po.jpg}
\end{figure}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}
\frametitle{Cenzorowanie inaczej}
Cenzorowania u�ywa si� te� w inny spos�b. Na przyk�ad rozpatruj�c dochody. W celu ochrony os�b o wysokich dochodach ocenzurujemy te, kt�re wynosz� ponad $10\,000$ pln tj. 

	\begin{center}
		$f(x)=\left\{\begin{array}{lcl}
		
		x 			&\quad\mbox{ je�eli } &x< 10\,000 \\ 
		\,\\
		10\,000  &\quad\mbox{ je�eli } &x\geq 10\,000
		
		\end{array}\right.$ 
	\end{center}

\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}
	\frametitle{Wykluczanie (truncation)}
	Wykluczenie (truncation) w odr�nieniu od cenzorowania nie polega na ograniczeniu warto�ci zmiennej lecz na \alert{ca�kowitym jej wykluczeniu} z pr�bki. Oczywi�cie takie wykluczenie \alert{nie powinno} by� losowe. 
	
	\begin{center}
		wykluczenie (truncation) \alert{$\neq$} cenzorowanie
	\end{center}
\end{frame}
\section{Modele parametryczne}
\begin{frame}
	\frametitle{Przepis na model parametryczny}
	Maj�c jedn� z funkcji $F(t)$, $S(t)$, $f(t)$, $\lambda(t)$ mo�na stworzy� model parametryczny do analizy prze�ycia. 
		$\newline\newline$
	Dobrym wyborem dla $f(t)$ bywaj� g�sto�ci rozk�ad�w:
	\begin{itemize}
	\item Wyk�adniczego
	\item Weibulla
	\item Log-normalnego
	\end{itemize}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}
	\frametitle{Zalety i wady poszczeg�lnych rozk�ad�w}
	\begin{itemize}
		\item Wyk�adniczy - funkcja hazardu ($\lambda(t)$) jest sta�a
		\item Weibull  - mo�e by� dodatnio \alert{albo} ujemnie zale�na od czasu
		\item Log-normalny - mo�e by� dodatnio \alert{lub} ujemnie zale�na od czasu	
	\end{itemize}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}
		\begin{figure}
	\centering
	\includegraphics[height=7.5cm]{hazard.jpg}
	\end{figure}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}
	\frametitle{Jak modelowa�?}
	Przyk�ad (MLE):
	\begin{center}
		$l(t,\theta)=\sum\limits_{i=1}^n\log f(t_i\,|\,X_i,\theta)$
	\end{center}
	mo�na z dekomponowa� 
	\begin{center}
		$l(t,\theta)=\sum\limits_{i=1}^n\log \lambda(t_i\,|\,X_i,\theta)+\sum\limits_{i=1}^n\log S(t_i\,|\,X_i,\theta)$
	\end{center}
	korzysta si� tu z faktu, �e $\lambda(t)=\frac{f(t)}{S(t)}$.
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Metody nieparametryczne}
\begin{frame}
	\frametitle{Najwa�niejsze metody nieparametryczne}
	\begin{itemize}
	\item Tablice trwania �ycia
	\item Metoda Kaplana -- Meiera
	\item Metoda Flemingtona -- Harringtona
	\end{itemize}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}
\frametitle{Tablice trwania �ycia 1/2}
\normalsize
Inaczej: metoda aktuarialna, metoda Cutlera -- Edelera.\\
Za�o�enia:\\
\begin{itemize}
\item dane rejestrowane w \alert{sta�ych} przedzia�ach czasu;
\item obiekty ulegaj�ce cenzurowaniu w ci�gu danego przedzia�u czasu opuszczaj� zbi�r danych w losowym momencie tego przedzia�u -- czyli przeci�tnie w po�owie przedzia�u;
\item prawdopodobie�stwo wyst�pienia badanego zdarzenia w danym okresie jest \alert{jednakowe} dla wszystkich obiekt�w w zbiorze i niezale�ne od prawdopodobie�stwa prze�ycia w pozosta�ych okresach.
\end{itemize}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}
\frametitle{Tablice trwania �ycia 2/2}
\begin{center}
\begin{tabular}{c c c c}\hline
Okres & Start & L.zdarze� & Obiekty uci�te\\
$i$   & $n_i$ & $d_i$     & $w_i$\\ \hline
$1$   & $31$  & $3$       & $4$\\
$2$   & $24$  & $2$       & $4$\\
itd. & & & \\ \hline
\end{tabular}
\end{center}

\begin{tabular}{c c c c c}\hline
Okres & Prawdop.zdarzenia       & Prawdop.prze�ycia   & Funkcja prze�ycia\\
$i$   & $q_i=d_i/[n_i-(w_i/2)]$ & $p_i=1-q_i$         & $S_i = p_i\times S_{i-1}$\\ \hline
$1$   & $3/[31-(4/2)]=0.10$     & $1 - 0.10 = 0.90$   & $0.90\times1=0.90$\\
$2$   & $2/[24-(4/2)]=0.09$     & $1 - 0.09 = 0.91$   & $0.90\times0.91=0.82$\\
itd. & & &\\ \hline
\end{tabular}
\end{frame}
\begin{frame}
\frametitle{Tablice trwania �ycia 2/2 - problem}
\noindent Problem:\\$\newline$
\alert{d�ugi} przedzia� czasu  \newline$\Longrightarrow$\alert{z�e oszacowanie} prawdopodobie�stwo zdarzenia \newline $\Longrightarrow$\alert{obci��ony} estymator funkcji prze�ycia\\
$\newline$

\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}
\frametitle{Metoda Kaplana -- Meiera 1/2}
Za�o�enie: czas prze�ycia \alert{niezale�ny} od czynnika powoduj�cego cenzurowanie danych.\\

Estymator Kaplana Meiera funkcji prze�ycia:

\begin{equation}
 \hat{S}(t)= \prod_{j: t_j\leq t} \frac{r_j-d_j}{r_j},\qquad \textrm{dla}\; 0\leq t \leq t^+ \nonumber
\end{equation}

%te objasnienia moga byc mniejsza czcionka, tak zeby sie wszystko ladnie zmiescilo na slajdzie
gdzie:\\
\footnotesize
$\{t_j: j=1,2,\dots, n\}$ --- zbi�r wszystkich moment�w wyst�pienia zdarzenia (np. �mierci obiektu);\\
$d_j$ --- liczba wyst�pie� zdarzenia w chwili $t_j$;\\
$r_j=n_j-w_j$ --- liczba obserwowanych obiekt�w zagro�onych w chwili $t_j$;\\
$n_j$ --- liczba obserwowanych obiekt�w w okresie $(t_{j-1},t_j)$;\\
$w_j$ --- liczba obiekt�w uci�tych w okresie $(t_{j-1},t_j)$;\\
$t^+$ --- moment zako�czenia badania.
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}
\frametitle{Metoda Kaplana -- Meiera 2/2}

Przyk�ad obliczania $\hat{S}$:\\$\newline$
\scriptsize
\begin{tabular} {c c c c c c c}\hline
Czas & Start & Zdarzenia & Uci�te & Zagro�one    & Prawdop.prze�ycia      & Funkcja prze�ycia\\
$j$	 &$n_j$  &$d_j$      &$w_j$   &$r_j$         &$P_j = (r_j - d_j)/r_j$ &$S_j = P_j\times S_{j-1}$\\ \hline
$0$  &$31$   &$2$        &$3$     &$31 - 3 = 28$ &$(28 - 2)/28 = 0.93$    &$0.93\times1.00 = 0.93$\\
$1$  &$26$   &$1$        &$2$     &$26 - 2 = 24$ &$(24 - 1) / 24 = 0.96$  &$0.96\times0.93 = 0.89$\\
$2$  &$23$   &$1$        &$2$     &$23 - 2 = 21$ &$(21 - 1) / 21 = 0.95$  &$0.95\times0.89 = 0.85$\\
$3$  &$20$   &$1$        &$2$     &$20 - 2 = 18$ &$(18 - 1) / 18 = 0.94$  &$0.94\times0.85 = 0.80$\\
itd& & & & & &\\ \hline
\end{tabular}
\scriptsize �r�d�o: Mark Stevenson, {\it An Introduction to Survival Analysis}, s. 7.
$\newline\newline$
\normalsize
\noindent Metoda Kaplana -- Meiera i tablice trwania �ycia s� \alert{identyczne}, je�li w ka�dym przedziale czasu badane zdarzenie ma miejsce tylko \alert{raz}.
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{frame}
\frametitle{Metoda Flemingtona -- Harringtona}

Przypomnijmy zale�no�� mi�dzy funkcj� prze�ycia a skumulowanym hazardem:\\
\begin{equation}\label{hazard}
S(t)= \exp (-\Lambda(t))\nonumber
\end{equation}

Estymator Nelsona -- Aalena skumulowanego hazardu:\\
\begin{equation}
\hat{\Lambda}(t)= \sum_{j:\;t_j\leq t} \frac{d_j}{r_j},\quad \textrm{dla}\; 0\leq t\leq t^{+}\nonumber
\end{equation}
gdzie $t_j, \; r_j,\; d_j$ --- jak w przypadku estymatora Kaplana -- Meiera.

Estymator Flemingtona -- Harringtona funkcji prze�ycia otrzymamy podstawiaj�c estymator Nelsona -- Aalena do funkcji skumulowanego hazardu\\
\begin{equation}
\check{S}(t)= \exp (-\hat{\Lambda}(t))\nonumber
\end{equation}
\end{frame}
\begin{frame}
\frametitle{Metoda KM i metoda FM --- por�wnanie estymator�w}
Dla dowolnego $t$ mamy oszacowanie:
\begin{equation*}
\check{S}(t)=\exp(-\hat{\Lambda}(t))=\exp\Big(-\sum_{j:t_j\leq\,t}\frac{d_j}{r_j}\Big)\nonumber
\end{equation*}
\begin{equation*}
=\prod_{j:t_j\leq\,t} \exp\Big(-\frac{d_j}{r_j}\Big)\geq\,\prod_{j:t_j\leq\,t}\Big(1-\frac{d_j}{r_j}\Big)=\hat{S}(t)\nonumber
\end{equation*}
Estymatory s� sobie \alert{bardzo bliskie}, gdy liczba zdarze� jest \alert{ma�a} w stosunku do liczby zagro�onych obiekt�w.
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}
\frametitle{Miary po�o�enia i odchylenia dla estymator�w funkcji prze�ycia 1/2}
Wariancja hazardu skumulowanego
\begin{itemize}
\item posta� Greenwooda: $\sum\limits_j\frac{d_j}{r_j(r_j-d_j)}$
\item posta� Aalena: $\sum\limits_j\frac{d_j}{r_j^2}$
\item posta� Kleina: $\sum\limits_j\frac{d_j(r_j-d_j)}{r_j^3}$
\end{itemize}

Zale�no�� wariancji funkcji prze�ycia od wariancji hazardu skumulowanego\\
\begin{equation}\label{var}
\rm var (\hat{S}(t))=\hat{S}^2(t)\rm var(\hat{\Lambda}(t)) \nonumber
\end{equation}
Do obliczania wariancji $\hat{\Lambda}$ --- preferowana posta� Aalena;\\
Do obliczania wariancji $\hat{S}$ --- posta� Greenwooda podstawiona do wzoru powy�ej.
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}
\frametitle{Miary po�o�enia i odchylenia dla estymator�w funkcji prze�ycia 2/2}
�redni czas przetrwania\\
\begin{equation}
\hat{\mu}=\int_0^{t^{+}} \hat{S}(t)dt=\sum_{j=1}^{m}(t_j-t_{j-1})\hat{S}(t_j),
\end{equation}
gdzie $t_0=0$ --- pocz�tek badania, $t_m=t^{+}$ --- moment zako�czenia badania.\\
Zak�adamy, �e $\hat{S}(t)=0$ dla $t\geq\,t^{+}\;\;\Longrightarrow$ estymator $\hat{\mu}$ mo�e by� obci��ony.\\

Mediana czasu przetrwania\\
--- zdefiniowana jako moment, w kt�rym po raz pierwszy $\hat{S}(t)\leq 0,5$.\\
Na wykresie krzywej prze�ycia --- punkt przeci�cia krzywej z poziom� prost� $\hat{S}(t)=0,5$.
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Analiza prze�ycia w R}
\begin{frame}
\frametitle{Pakiet survival}

U�yteczne funkcje z pakietu \texttt{survival}:
\begin{itemize}
\item \texttt{Surv} --- tworzy obiekt typu \texttt{Surv};
\item \texttt{survfit} --- oblicza m.in. warto�ci funkcji prze�ycia, kt�re nast�pnie mo�na przedstawi� w formie krzywej prze�ycia.
\end{itemize}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}
\frametitle{Funkcja \texttt{Surv}}

Sk�adnia:
$\newline$\alert{\textgreater Surv (time, event)}$\newline$
gdzie
\begin{itemize}
\item \texttt{time} --- 	zmienna reprezentuj�ca d�ugo�� czasu obserwacji obiekt�w;
\item \texttt{event} --- zmienna zero-jedynkowa okre�laj�ca, czy dla danego obiektu ze zbioru danych wyst�pi�o w okresie obserwacji badane zdarzenie;
\end{itemize}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}
\frametitle{Funkcja \texttt{survfit}}

Sk�adnia (podstawowe argumenty):$\newline$
\alert{\textgreater survfit(formula, data, type, conf.int, conf.type, error)}
$\newline$
gdzie
\footnotesize
\begin{itemize}
\item \texttt{formula} --- formu�a postaci \texttt{ob.Surv$\sim$var1+var2+\dots+vark}, gdzie \texttt{ob.Surv} --- obiekt typu \texttt{Surv}; lewa strona formu�y mo�e by� pusta;
\item \texttt{data} --- zbi�r danych;
\item \texttt{type} --- metoda estymowania funkcji prze�ycia; do wyboru: \textquotedblleft\texttt{kaplan-meier}\textquotedblright, \textquotedblleft\texttt{fleming-harrington}\textquotedblright, \textquotedblleft\texttt{fh2}\textquotedblright; domy�lnie \textquotedblleft\texttt{kaplan-meier}\textquotedblright;
\item \texttt{conf.int} --- poziom ufno�ci dla przedzia��w ufno�ci; domy�lnie $0.95$;
\item \texttt{conf.type} --- typ przedzia��w ufno�ci; do wyboru: \textquotedblleft\texttt{none}\textquotedblright, \textquotedblleft\texttt{plain}\textquotedblright, \textquotedblleft\texttt{log}\textquotedblright, \textquotedblleft\texttt{log-log}\textquotedblright;
\item \texttt{error} --- metoda obliczania odchylenia standardowego; do wyboru: \textquotedblleft\texttt{greenwood}\textquotedblright, \textquotedblleft\texttt{tsiatis}\textquotedblright; domy�lnie \textquotedblleft\texttt{greenwood}\textquotedblright.
\end{itemize}

\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}
\frametitle{Przyk�ad zastosowania 1/5}

Wst�pne obejrzenie i przer�bka danych:
$\newline$\alert{\textgreater dane\$status=is.na(dane\$rok.utraty.przeszczepu)}
$\newline$\alert{\textgreater dane\$status=!dane\$status}$\newline$

Utworzenie obiektu typu \texttt{surv} (wykorzystujemy zmienne \texttt{czas.obserwacji} i \texttt{status}):

$\newline$\alert{\textgreater dane.surv=with(dane, Surv(dane\$czas.obserwacji, dane\$status))}$\newline$
\normalsize
Najprostsze zastosowanie funkcji \texttt{survfit} (metoda Kaplana -- Meiera):

$\newline$\alert{\textgreater dane.fit=survfit(dane.surv$\sim$1, data=dane)}$\newline$
\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}

\frametitle{Przyk�ad zastosowania 2/5}
$\newline$\alert{\textgreater summary(dane.fit)}$\newline$
\footnotesize
Call: survfit(formula = dane.surv $\sim$ 1, data = dane)
\begin{tabular}{ccc ccc c }
\textbf{time} & \textbf{n.risk} & \textbf{n.event} & \textbf{survival} & \textbf{std.err} & \textbf{lower 95\% CI} & \textbf{upper 95\% CI} \\
  5.0  &  136  &     1 &   0.993 & 0.00733  &      0.978   &     1.000\\
  5.5  &  128  &     1 &   0.985 & 0.01061  &      0.964   &     1.000\\
  5.8  &  113  &     1 &   0.976 & 0.01363  &      0.950   &     1.000\\
  ...  &       &       &         &          &              &
\end{tabular}
\normalsize
Zmienne w tabeli oznaczaj�:
\footnotesize
\begin{itemize}
\item \texttt{time} --- moment zdarzenia;
\item \texttt{n.risk} --- liczba zagro�onych obiekt�w badania w momencie t;
\item \texttt{n.event} --- liczba zdarze� w momencie t;
\item \texttt{survival} --- funkcja prze�ycia;
\item \texttt{std.err} --- odchylenie standardowe funkcji prze�ycia;
\item \texttt{lower 95\% CI, upper 95\% CI} --- przedzia�y ufno�ci;
\end{itemize}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}
\frametitle{Przyk�ad zastosowania  3/5}
Wykres krzywej prze�ycia z zaznaczon� median� czasu prze�ycia:
$\newline$\alert{\textgreater plot(dane.fit, xlab=\textquotedblleft Czas obserwacji\textquotedblright, ylab=\textquotedblleft S(t)\textquotedblright, col=\textquotedblleft red\textquotedblright, lwd=2)}
$\newline$\alert{\textgreater abline(h=0.5, lty=2)}
$\newline$\alert{\textgreater title(\textquotedblleft Krzywa prze�ycia dla przeszczepu nerki\textquotedblright)}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}
\frametitle{Przyk�ad zastosowania 3/5 - rysunek}
\begin{figure}
\centering
\includegraphics[height=7.5cm]{krzywa.pdf}
\end{figure}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}
	\frametitle{Przyk�ad zastosowania 4/5}
	\normalsize
	Tak mo�na unikn�� rysowania przedzia��w ufno�ci:
	
	$\newline$\alert{\textgreater dane.fit.noconf=survfit(dane.surv$\sim$1, data=dane, conf.type=\textquotedblleft none\textquotedblright)}$\newline$
	
	A tak obliczy� funkcje prze�ycia z podzia�em ze wzgl�du na p�e� biorcy:
	
	$\newline$\alert{\textgreater dane.fit.noconf.gender=survfit(dane.surv$\sim$plec.biorcy, data=dane, conf.type=\textquotedblleft none\textquotedblright)}$\newline$
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}
	\frametitle{Przyk�ad zastosowania 4/5  - rysunek}
	\begin{figure}
	\includegraphics[height=7.5cm]{krzyweplec.pdf}
	\end{figure}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}
	\frametitle{Przyk�ad zastosowania 5/5}
	\normalsize
	Krzywa prze�ycia przy zastosowaniu metody Flemingtona -- Harringtona:
	$\newline$\alert{\textgreater dane.fit.fh=survfit(dane.surv$\sim$1, data=dane, type=\textquotedblleft fleming-harrington\textquotedblright)}$\newline$
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}
	\frametitle{Przyk�ad zastosowania 5/5 - rysunek}
	\begin{figure}
		\includegraphics[height=5.5cm]{km_vs_fh.pdf}
	\end{figure}
\end{frame}
\end{document}
