% Options for packages loaded elsewhere
\PassOptionsToPackage{unicode}{hyperref}
\PassOptionsToPackage{hyphens}{url}
%
\documentclass[
]{ctexart}
\usepackage{amsmath,amssymb}
\usepackage{iftex}
\ifPDFTeX
  \usepackage[T1]{fontenc}
  \usepackage[utf8]{inputenc}
  \usepackage{textcomp} % provide euro and other symbols
\else % if luatex or xetex
  \usepackage{unicode-math} % this also loads fontspec
  \defaultfontfeatures{Scale=MatchLowercase}
  \defaultfontfeatures[\rmfamily]{Ligatures=TeX,Scale=1}
\fi
\usepackage{lmodern}
\ifPDFTeX\else
  % xetex/luatex font selection
\fi
% Use upquote if available, for straight quotes in verbatim environments
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
\IfFileExists{microtype.sty}{% use microtype if available
  \usepackage[]{microtype}
  \UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts
}{}
\makeatletter
\@ifundefined{KOMAClassName}{% if non-KOMA class
  \IfFileExists{parskip.sty}{%
    \usepackage{parskip}
  }{% else
    \setlength{\parindent}{0pt}
    \setlength{\parskip}{6pt plus 2pt minus 1pt}}
}{% if KOMA class
  \KOMAoptions{parskip=half}}
\makeatother
\usepackage{xcolor}
\usepackage{color}
\usepackage{fancyvrb}
\newcommand{\VerbBar}{|}
\newcommand{\VERB}{\Verb[commandchars=\\\{\}]}
\DefineVerbatimEnvironment{Highlighting}{Verbatim}{commandchars=\\\{\}}
% Add ',fontsize=\small' for more characters per line
\usepackage{framed}
\definecolor{shadecolor}{RGB}{248,248,248}
\newenvironment{Shaded}{\begin{snugshade}}{\end{snugshade}}
\newcommand{\AlertTok}[1]{\textcolor[rgb]{0.94,0.16,0.16}{#1}}
\newcommand{\AnnotationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\newcommand{\AttributeTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{#1}}
\newcommand{\BaseNTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}}
\newcommand{\BuiltInTok}[1]{#1}
\newcommand{\CharTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
\newcommand{\CommentTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textit{#1}}}
\newcommand{\CommentVarTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\newcommand{\ConstantTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{#1}}
\newcommand{\ControlFlowTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{\textbf{#1}}}
\newcommand{\DataTypeTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{#1}}
\newcommand{\DecValTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}}
\newcommand{\DocumentationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\newcommand{\ErrorTok}[1]{\textcolor[rgb]{0.64,0.00,0.00}{\textbf{#1}}}
\newcommand{\ExtensionTok}[1]{#1}
\newcommand{\FloatTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}}
\newcommand{\FunctionTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{\textbf{#1}}}
\newcommand{\ImportTok}[1]{#1}
\newcommand{\InformationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\newcommand{\KeywordTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{\textbf{#1}}}
\newcommand{\NormalTok}[1]{#1}
\newcommand{\OperatorTok}[1]{\textcolor[rgb]{0.81,0.36,0.00}{\textbf{#1}}}
\newcommand{\OtherTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{#1}}
\newcommand{\PreprocessorTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textit{#1}}}
\newcommand{\RegionMarkerTok}[1]{#1}
\newcommand{\SpecialCharTok}[1]{\textcolor[rgb]{0.81,0.36,0.00}{\textbf{#1}}}
\newcommand{\SpecialStringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
\newcommand{\StringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
\newcommand{\VariableTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
\newcommand{\VerbatimStringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
\newcommand{\WarningTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\usepackage{graphicx}
\makeatletter
\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth\else\Gin@nat@width\fi}
\def\maxheight{\ifdim\Gin@nat@height>\textheight\textheight\else\Gin@nat@height\fi}
\makeatother
% Scale images if necessary, so that they will not overflow the page
% margins by default, and it is still possible to overwrite the defaults
% using explicit options in \includegraphics[width, height, ...]{}
\setkeys{Gin}{width=\maxwidth,height=\maxheight,keepaspectratio}
% Set default figure placement to htbp
\makeatletter
\def\fps@figure{htbp}
\makeatother
\setlength{\emergencystretch}{3em} % prevent overfull lines
\providecommand{\tightlist}{%
  \setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
\setcounter{secnumdepth}{5}
\usepackage[most]{tcolorbox}
\definecolor{boxidea}{HTML}{6c8aa5}
\definecolor{boxwarn}{HTML}{b58266}
\definecolor{boxtip}{HTML}{8aa085}
\newtcolorbox{concept}[1][]{enhanced, breakable, colback=boxidea!7, colframe=boxidea, coltitle=white, fonttitle=\bfseries, title=#1, arc=2pt, left=8pt, right=8pt, top=4pt, bottom=4pt}
\newtcolorbox{pitfall}[1][]{enhanced, breakable, colback=boxwarn!7, colframe=boxwarn, coltitle=white, fonttitle=\bfseries, title=#1, arc=2pt, left=8pt, right=8pt, top=4pt, bottom=4pt}
\newtcolorbox{keypoint}[1][]{enhanced, breakable, colback=boxtip!7, colframe=boxtip, coltitle=white, fonttitle=\bfseries, title=#1, arc=2pt, left=8pt, right=8pt, top=4pt, bottom=4pt}
\renewcommand{\and}{\\}
\ifLuaTeX
  \usepackage{selnolig}  % disable illegal ligatures
\fi
\IfFileExists{bookmark.sty}{\usepackage{bookmark}}{\usepackage{hyperref}}
\IfFileExists{xurl.sty}{\usepackage{xurl}}{} % add URL line breaks if available
\urlstyle{same}
\hypersetup{
  pdftitle={Survival Analysis},
  pdfauthor={Rui},
  hidelinks,
  pdfcreator={LaTeX via pandoc}}

\title{Survival Analysis}
\author{Rui}
\date{2026-05-26}

\begin{document}
\maketitle

{
\setcounter{tocdepth}{2}
\tableofcontents
}
\hypertarget{ux8fd9ux7ae0ux5728ux8bb2ux4ec0ux4e48}{%
\section{这章在讲什么}\label{ux8fd9ux7ae0ux5728ux8bb2ux4ec0ux4e48}}

生存分析（survival
analysis）解决的是「事件什么时候发生」类的问题。这类数据的特殊之处在于\textbf{右删失}（right
censoring）：研究结束时一部分被试还没发生事件（比如复发、死亡、离职），你只知道「至少活到了这个时间」，不知道确切的事件时间。直接把这些观测当作「永远没事件」会低估事件率，扔掉他们又损失信息------生存分析的
Kaplan--Meier 估计和 Cox 回归专门处理这种数据。

心理学的典型用法：跟踪干预 /
治疗的效果在多长时间内保持、研究戒断（戒烟、戒毒）的「复发时间」、教育研究里的「辍学时间」。本章用
\texttt{survival} 包自带的 \texttt{lung} 数据集（肺癌患者）演示 K--M
估计 + log-rank 检验 + Cox 比例风险模型完整流程。

\begin{concept}[两个关键对象]
\textbf{生存函数} $S(t) = P(T > t)$：到时刻 $t$ 还没发生事件的概率，KM 估计：$\hat S(t) = \prod_{t_i \le t} \big(1 - \frac{d_i}{n_i}\big)$，其中 $d_i$ 是 $t_i$ 时发生事件的人数，$n_i$ 是 $t_i$ 之前还在「风险集」里的人数。

\textbf{风险函数} $h(t) = \lim_{\Delta t \to 0} \frac{P(t \le T < t+\Delta t \mid T \ge t)}{\Delta t}$：到了 $t$ 还活着，下一瞬间发生事件的「瞬时率」。Cox 模型假设 $h(t \mid X) = h_0(t) \exp(\beta'X)$——协变量只乘一个常数因子在基线风险上（\textbf{比例风险假设}）。系数 $\exp(\beta_j)$ 解读为风险比（HR）：$X_j$ 增加 1 单位时风险翻几倍。
\end{concept}

\hypertarget{packages}{%
\section{Packages}\label{packages}}

\begin{itemize}
\tightlist
\item
  Survival Analysis

  \begin{itemize}
  \tightlist
  \item
    survival
  \item
    survminer
  \end{itemize}
\item
  Plots of Survival Analysis

  \begin{itemize}
  \tightlist
  \item
    ggfortify
  \item
    ggplot
  \end{itemize}
\end{itemize}

\begin{Shaded}
\begin{Highlighting}[]
\FunctionTok{library}\NormalTok{(survival)}
\FunctionTok{library}\NormalTok{(survminer)}
\FunctionTok{library}\NormalTok{(ggplot2)}
\FunctionTok{library}\NormalTok{(ggfortify)}
\end{Highlighting}
\end{Shaded}

Dataset ``lung'' in package ``survival'' is of interest, which contains
the information about survival in patients with advanced lung cancer
from the North Central Cancer Treatment Group. Performance scores rate
how well the patient can perform usual daily activities. Variables
include:

\begin{itemize}
\tightlist
\item
  inst: Institution code
\item
  time: Survival time in days
\item
  status: censoring status \texttt{1=censored}, \texttt{2=dead}
\item
  age: Age in years
\item
  sex: \texttt{Male=1} \texttt{Female=2}
\item
  ph.ecog: ECOG performance score as rated by the physician.
  \texttt{0=asymptomatic}, \texttt{1=\ symptomatic} but completely
  ambulatory, \texttt{2=\ in\ bed\ \textless{}50\%\ of\ the\ day},
  \texttt{3=\ in\ bed\ \textgreater{}\ 50\%\ of\ the\ day\ but\ not\ bedbound},
  \texttt{4\ =\ bedbound}
\item
  ph.karno: Karnofsky performance score
  (\texttt{bad=0}-\texttt{good=100}) rated by physician
\item
  pat.karno: Karnofsky performance score as rated by patient
\item
  meal.cal: Calories consumed at meals
\item
  wt.loss: Weight loss in last six months (pounds)
\end{itemize}

\begin{Shaded}
\begin{Highlighting}[]
\FunctionTok{attach}\NormalTok{(lung)}
\end{Highlighting}
\end{Shaded}

\hypertarget{survival-object}{%
\section{Survival Object}\label{survival-object}}

\texttt{survival::Surv()} creates a survival object, with censored data
marked with ``\texttt{+}'' following up censoring time and death cases
simply showing the death time. The result is usually used as a response
variable in a model formula.

Two most important parameters:

\begin{itemize}
\tightlist
\item
  \texttt{time} :For right censored data, this is the follow up time.
  For interval data, the first argument is the starting time for the
  interval.
\item
  \texttt{event}: The status indicator, normally \texttt{0=alive},
  \texttt{1=dead}. Other choices are \texttt{TRUE/FALSE}
  (\texttt{TRUE\ =\ death}) or \texttt{1/2} (\texttt{2=death}). For
  interval censored data, the status indicator is 0=right censored,
  1=event at time, 2=left censored, 3=interval censored. For multiple
  endpoint data the event variable will be a factor, whose first level
  is treated as censoring. Although unusual, the event indicator can be
  omitted, in which case all subjects are assumed to have an event.
\end{itemize}

\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{survobj }\OtherTok{=} \FunctionTok{Surv}\NormalTok{(time, status}\SpecialCharTok{==}\DecValTok{2}\NormalTok{)}
\end{Highlighting}
\end{Shaded}

\hypertarget{surv-model}{%
\section{Surv Model}\label{surv-model}}

For the overall survival analysis, just specify the null hypothesis with
\texttt{Surv\textasciitilde{}1}, i.e., NO groups.

\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{sfit }\OtherTok{\textless{}{-}} \FunctionTok{survfit}\NormalTok{(}\FunctionTok{Surv}\NormalTok{(time, status}\SpecialCharTok{==}\DecValTok{2}\NormalTok{)}\SpecialCharTok{\textasciitilde{}}\DecValTok{1}\NormalTok{, }\AttributeTok{data=}\NormalTok{lung)}
\end{Highlighting}
\end{Shaded}

The fitted survival model itself will tell you the results, with
observations, events, median and 95\% CI.

\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{sfit}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
## Call: survfit(formula = Surv(time, status == 2) ~ 1, data = lung)
## 
##        n events median 0.95LCL 0.95UCL
## [1,] 228    165    310     285     363
\end{verbatim}

If more details are needed, i.e., the instantaneous events, and
estimates of survival, std.err, 95\% CI, just \texttt{summary(sfit)}.

Moreover, if \texttt{time} is designated, then the \texttt{summary()}
function will return the estimated results.

\begin{Shaded}
\begin{Highlighting}[]
\FunctionTok{summary}\NormalTok{(sfit,}\AttributeTok{time =} \DecValTok{200}\NormalTok{)}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
## Call: survfit(formula = Surv(time, status == 2) ~ 1, data = lung)
## 
##  time n.risk n.event survival std.err lower 95% CI upper 95% CI
##   200    144      72     0.68  0.0311        0.622        0.744
\end{verbatim}

However, if group is of interest, specify it in the formula with
\texttt{Surv\textasciitilde{}group}.

\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{sfit\_sex }\OtherTok{=} \FunctionTok{survfit}\NormalTok{(}\FunctionTok{Surv}\NormalTok{(time, status}\SpecialCharTok{==}\DecValTok{2}\NormalTok{) }\SpecialCharTok{\textasciitilde{}}\NormalTok{ sex, }\AttributeTok{data =}\NormalTok{ lung)}
\NormalTok{sfit\_sex}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
## Call: survfit(formula = Surv(time, status == 2) ~ sex, data = lung)
## 
##         n events median 0.95LCL 0.95UCL
## sex=1 138    112    270     212     310
## sex=2  90     53    426     348     550
\end{verbatim}

From the model itself, we can get an overall picture of the differences
between groups.

\begin{Shaded}
\begin{Highlighting}[]
\FunctionTok{summary}\NormalTok{(sfit\_sex,}\AttributeTok{time =} \DecValTok{365}\NormalTok{)}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
## Call: survfit(formula = Surv(time, status == 2) ~ sex, data = lung)
## 
##                 sex=1 
##         time       n.risk      n.event     survival      std.err lower 95% CI 
##     365.0000      35.0000      85.0000       0.3361       0.0434       0.2609 
## upper 95% CI 
##       0.4329 
## 
##                 sex=2 
##         time       n.risk      n.event     survival      std.err lower 95% CI 
##     365.0000      30.0000      36.0000       0.5265       0.0597       0.4215 
## upper 95% CI 
##       0.6576
\end{verbatim}

It's ideal that the 95\% CI of groups doesn't intersect, and a
significant result can be obtained instantly. However, that's not the
case, take a step further and use Cox regression to see exactly.

\hypertarget{cox-regression}{%
\section{Cox Regression}\label{cox-regression}}

\begin{Shaded}
\begin{Highlighting}[]
\FunctionTok{coxph}\NormalTok{(}\FunctionTok{Surv}\NormalTok{(time, status}\SpecialCharTok{==}\DecValTok{2}\NormalTok{)}\SpecialCharTok{\textasciitilde{}}\NormalTok{sex)}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
## Call:
## coxph(formula = Surv(time, status == 2) ~ sex)
## 
##        coef exp(coef) se(coef)      z       p
## sex -0.5310    0.5880   0.1672 -3.176 0.00149
## 
## Likelihood ratio test=10.63  on 1 df, p=0.001111
## n= 228, number of events= 165
\end{verbatim}

where ``\texttt{exp(coef)}'' is the HR (hazard ratio)， which measures
the relative risk between two groups.

Theoretically, it's better only open to binary variables in Cox
regression. However, for categorical variables with more than 2 levels,
use ``\texttt{as.factor(cat\_var)}'' with ``\texttt{model\ =\ TRUE}'' to
generate corresponding dummy variables. For continuous variables,
they'll be included into the regression model as usual, but the model
will be plotted with expected value of continuou variables.

However, similar to \texttt{coxph()} which returns the differences
through the view of regression, the simpler version of such comparison
can be accomplished by ``\texttt{survdiff()}'', also in package
``survival''. Both of the functions have the same formula.

From ``\texttt{survdiff()}'', we can get the intermediate products when
computing the log rank, or the chi-square test. However, this wouldn't
return the coefficient.

Jointly speaking, the combined results of two functions emphasize the
fact that the log rank test (named Mantel-Haenszel test), is a
chi-square test in essence.

\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{surv\_diff }\OtherTok{=} \FunctionTok{survdiff}\NormalTok{(}\FunctionTok{Surv}\NormalTok{(time, status}\SpecialCharTok{==}\DecValTok{2}\NormalTok{)}\SpecialCharTok{\textasciitilde{}}\NormalTok{sex)}
\NormalTok{surv\_diff}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
## Call:
## survdiff(formula = Surv(time, status == 2) ~ sex)
## 
##         N Observed Expected (O-E)^2/E (O-E)^2/V
## sex=1 138      112     91.6      4.55      10.3
## sex=2  90       53     73.4      5.68      10.3
## 
##  Chisq= 10.3  on 1 degrees of freedom, p= 0.001
\end{verbatim}

\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{surv\_diff}\SpecialCharTok{$}\NormalTok{chisq}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
## [1] 10.32674
\end{verbatim}

\hypertarget{surv-plots}{%
\section{Surv Plots}\label{surv-plots}}

Finally, we can visualize the survival analysis.

Note that even if analysed data has been attached, if the
``\texttt{data}'' isn't passed into \texttt{survfit()}, then an error
will be raised.

The parameter ``\texttt{risk.table}'' provides you with the freedom to
decide whether or not to add a risk table below the Kaplan-Meier
curve(s). Meanwhile, various options are available!

\begin{Shaded}
\begin{Highlighting}[]
\FunctionTok{ggsurvplot}\NormalTok{(sfit\_sex,}\AttributeTok{data =}\NormalTok{ lung,}
           \AttributeTok{conf.int=}\ConstantTok{TRUE}\NormalTok{, }\AttributeTok{pval=}\ConstantTok{TRUE}\NormalTok{, }
           \AttributeTok{risk.table=}\StringTok{\textquotesingle{}abs\_pct\textquotesingle{}}\NormalTok{,}
           \AttributeTok{legend.labs=}\FunctionTok{c}\NormalTok{(}\StringTok{"Male"}\NormalTok{, }\StringTok{"Female"}\NormalTok{), }\AttributeTok{legend.title=}\StringTok{"Sex"}\NormalTok{,}
           \AttributeTok{title=}\StringTok{"Kaplan{-}Meier Curve for Lung Cancer Survival"}\NormalTok{)}
\end{Highlighting}
\end{Shaded}

\includegraphics{r-survival-analysis_files/figure-latex/unnamed-chunk-11-1.pdf}

Moreover, the parameter ``\texttt{fun}'' is quite useful, which will
define a transformation of the survival curve.

\begin{itemize}
\tightlist
\item
  ``pct'': for survival probability in percentage, \textbf{by default}.
\item
  ``event'': plots cumulative events, \(f(y)=1-y\).
\item
  ``cumhaz'': plots the cumulative hazard function, \(f(y)=-\log(y)\).
\end{itemize}

\begin{Shaded}
\begin{Highlighting}[]
\FunctionTok{ggsurvplot}\NormalTok{(sfit\_sex,}\AttributeTok{data =}\NormalTok{ lung,}
           \AttributeTok{conf.int=}\ConstantTok{TRUE}\NormalTok{, }\AttributeTok{pval=}\ConstantTok{TRUE}\NormalTok{, }
           \CommentTok{\# risk.table=\textquotesingle{}abs\_pct\textquotesingle{},}
           \AttributeTok{legend.labs=}\FunctionTok{c}\NormalTok{(}\StringTok{"Male"}\NormalTok{, }\StringTok{"Female"}\NormalTok{), }\AttributeTok{legend.title=}\StringTok{"Sex"}\NormalTok{,}
           \CommentTok{\# title="Kaplan{-}Meier Curve for Lung Cancer Survival",}
           \AttributeTok{fun =} \StringTok{\textquotesingle{}event\textquotesingle{}}\NormalTok{)}
\end{Highlighting}
\end{Shaded}

\includegraphics{r-survival-analysis_files/figure-latex/unnamed-chunk-12-1.pdf}

\begin{Shaded}
\begin{Highlighting}[]
\FunctionTok{ggsurvplot}\NormalTok{(sfit\_sex,}\AttributeTok{data =}\NormalTok{ lung,}
           \AttributeTok{conf.int=}\ConstantTok{TRUE}\NormalTok{, }\AttributeTok{pval=}\ConstantTok{TRUE}\NormalTok{, }
           \CommentTok{\# risk.table=\textquotesingle{}abs\_pct\textquotesingle{},}
           \AttributeTok{legend.labs=}\FunctionTok{c}\NormalTok{(}\StringTok{"Male"}\NormalTok{, }\StringTok{"Female"}\NormalTok{), }\AttributeTok{legend.title=}\StringTok{"Sex"}\NormalTok{,}
           \AttributeTok{title=}\StringTok{"Kaplan{-}Meier Curve for Lung Cancer Survival"}\NormalTok{,}
           \AttributeTok{fun =} \StringTok{\textquotesingle{}cumhaz\textquotesingle{}}\NormalTok{)}
\end{Highlighting}
\end{Shaded}

\includegraphics{r-survival-analysis_files/figure-latex/unnamed-chunk-13-1.pdf}

\hypertarget{ux5bb9ux6613ux8e29ux7684ux5751}{%
\section{容易踩的坑}\label{ux5bb9ux6613ux8e29ux7684ux5751}}

\begin{pitfall}[生存分析最常见的三个误区]
\begin{enumerate}
\item \textbf{忘了检验比例风险假设}：Cox 模型最核心的假设是「协变量的影响在所有时点上是常数比例」。检验方法：\texttt{cox.zph(fit)}，对每个协变量画 Schoenfeld 残差与时间的图，残差应该围绕水平线，$p > 0.05$。若违反，要么对应变量做分层（\texttt{strata()}）、要么引入时间交互项 $\beta(t) = \beta_0 + \beta_1 \cdot t$。本笔记上方代码没显式跑 \texttt{cox.zph}——读者实际用时务必补上。
\item \textbf{把删失当作「没发生」}：原始数据里 \texttt{status} 列通常 1 = 删失 / 2 = 事件（或 0/1）。\texttt{Surv(time, status == 2)} 里必须显式说明「哪个值代表事件」。看错编码会让事件率算反，KM 曲线整个倒过来。
\item \textbf{log-rank 显著但 HR $\approx 1$}：log-rank 检验对「曲线交叉」的差异最敏感，Cox 假设曲线不交叉（比例风险）。两组曲线在前期分得开、后期合并 → log-rank 可能显著但 HR 接近 1，因为 HR 是「平均效应」。这种情况下不该用 Cox，可以试 AFT 模型（\texttt{survreg}）或分段 Cox（按时间段拆）。
\end{enumerate}
\end{pitfall}

\end{document}
