CoxModelFit[{e1,…,en}]
构建基准风险
在事件时刻 ei 的模型.
CoxModelFit[{{{ξ11,…,ξ1p},…,{ξn1,…,ξnp}},{e1,…,en}},{f1,…,fm},{x1,…,xp}]
构建形如
的 Cox 模型, 其中 fi 取决于xk.
CoxModelFit
CoxModelFit[{e1,…,en}]
构建基准风险
在事件时刻 ei 的模型.
CoxModelFit[{{{ξ11,…,ξ1p},…,{ξn1,…,ξnp}},{e1,…,en}},{f1,…,fm},{x1,…,xp}]
构建形如
的 Cox 模型, 其中 fi 取决于xk.
更多信息和选项
- CoxModelFit 用于生存性、可靠性和持续时间分析. 它量化相对生存风险,并估计底层的基准风险.
- CoxModelFit 返回符号式 CoxModel 对象,以表示它构建的比例风险模型. 模型的属性和诊断量可以从 model["property"] 获得.
- 可用的模型属性列表可以通过使用 model["Properties"] 获得.
- 事件 ei 的形式服从 EventData 中所用的形式.
- CoxModelFit 生成条件风险函数
,与基准风险函数
成一定比例. - 模型是半参数式,参数
可通过部分似然最大化求得. 基准风险
利用非参数方法估计得到. - 仅估计
的零模型可利用 CoxModelFit[e] 指定,它等价于 CoxModelFit[{ξ,e},{},{x1,…,xp}]. - 在基函数 fi 中指定的常数值在拟合中被忽略,并在基准风险
的估计中被吸收. - 下列属性表与模型参数分量
的估计、诊断和检验相关. » - 与 model["property"] 所用的数据和所得到的拟合函数相关的属性包括:
-
"BaselineList" 包含各层基准协变量水平的列表 "BasisFunctions" 基函数
的列表"BestFitParameters" 参数估计量 
"Data" 协变量输入数据的矩阵 
"EventData" 事件输入数据 
"RelativeRisk" 模型参数的相对风险 
"StrataModels" 包含各层子模型的列表 "StrataSummary" 包含各层名称和计数配对的列表 - 测量拟合优度的属性包括:
-
"AIC" 赤池信息量准则 "BIC" 施瓦兹贝叶斯信息准则 "LogLikelihood" 模拟对数似然 "MaxRSquared" 可能的
系数的最大值"RSquared" 伪决定系数 
- 残差和影响力的测量类型:
-
"BetaDifferences" 对参数值影响的 DFBETA 测量方法 "CoxSnellResiduals" Cox–Snell 类型残差 "DevianceResiduals" 按比例调整的鞅残差 "MartingaleResiduals" 随时间的推移事件的超出数目估计 "ScaledBetaDifferences" 利用模型标准差计算的 DFBETA "SchoenfeldResiduals" 舍恩菲尔德型残差 "ScoreResiduals" Score 残差 - 参数估计的属性和诊断包括:
-
"CovarianceMatrix" 模型参数的协方差估计 "InformationMatrix" 模型参数的信息矩阵 "LikelihoodRatioStatistic" 拟合模型与零模型的似然比 "ParameterConfidenceIntervals" 参数估计的置信区间 "ParameterStandardErrors" 模型参数的标准误差 "ParameterTable" 拟合参数信息表 "ParameterTableEntries" 参数表中的条目 "RelativeRiskConfidenceIntervals" 相对风险估计值的置信区间 "RiskScores" 对每个观察值的风险评分 "ScoreStatistic" 比较拟合模型和零模型的 Score 统计量 "TestTable" 模型参数的显著信息表 "TestTableEntries" 检验表中的条目 "TestTableEntriesFunction" 用检验表函数创建的表格中的条目 "TestTableFunction" 在指定零假设下创建的检验表 "WaldStatistic" 比较拟合模型和零模型的 Wald 统计量 - 正如在 SurvivalModelFit 中一样,获得模型
的非参数分量的信息是可能的,包括生存概率的估计量、生存置信区间和矩估计量. » - CoxModelFit 具有 SurvivalModelFit 中可用的所有属性.
- 与
相关的属性的指定与 SurvivalModelFit 中一样,但额外要求协变量水平 x0 以 model["property"][x0] 的形式给出. - 通过指定 model[h][x0] 中的形式 h,可以得到协变量水平 x0 时风险率
的不同函数形式. 可以使用以下形式. -
"CDF" 累积分布函数 "CHF" 累积风险函数 "SF" 生存函数 - CoxModelFit 在特定点 t 和协变量水平 x0 时的拟合函数值 h 可从 model[h][x0][t] 得到. model[h][][t] 给出基准风险 h0[t] 的形式 h.
- 指定 Normal[model] 给出 model["SF"][][t] 的纯函数形式.
- CoxModelFit 接受以下选项:
-
ConfidenceLevel 95/100 用于区间和带的水平 ConfidenceRange All 同步置信带的范围 ConfidenceTransform "LogLog" 使用的置信变换 Method Automatic 用于模型拟合的方法 NominalVariables None 视为分类的变量 StrataVariables None 视为层的变量 WorkingPrecision Automatic 内部计算所用的精度 - 当 ConfidenceLevel->p 时,计算用于各种函数形式和参数估计时的概率 p 置信区间和置信带.
- ConfidenceRange->{tmin,tmax} 给出拟合函数在 tmin 和 tmax 之间的概率 p 同步置信区间和置信带.
- ConfidenceTransform 的可能设置包括 "Linear"、"LogLog"、"ArcSinSqrt"、 "Log"、"Logit" 或者纯函数 g.
- 设置 Method->m 指定用于处理同时发生的事件(ties)的方法。可能的设置如下.
-
"Breslow" 使用 Breslow 部分似然 "Efron" 使用 Efron 部分似然 "Exact" 使用精确的边缘似然 - 默认情况下使用 "Breslow" 方法来处理同时发生的事件.
- 其他方法设置可以在范例的选项部分找到. »
范例
打开所有单元 关闭所有单元基本范例 (1)
ξ = {2, 0, 0, 1, 1, 1, 3, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0};
e = EventData[Automatic, {{8, 22, 6, 4, 12, 11, 2, 34, 25, 15, 8, 6, 34, 6, 32, 1, 15, 9, 9, 6},
{0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0}, None}];𝒮 = CoxModelFit[{ξ, e}, x, x];𝒮["ParameterTable"]Plot[Evaluate@Table[𝒮["SF"][{x}][t], {x, r = {0, 1, 2, 3}}], {t, 0, 35}, PlotPoints -> 75, Exclusions -> None, PlotLegends -> (Row[{"x = ", #}]& /@ r)]𝒮["TestTable"]范围 (26)
基本用途 (8)
ξ = {{67, 1}, {11, 0}, {32, 0}, {50, 1}, {65, 1}, {44, 1}, {20, 1}, {26, 0}, {69, 1}, {50, 1}, {25, 1}, {18, 0}, {63, 1}, {41, 0}, {30, 0}, {32, 1}, {46, 1}, {35, 0}, {33, 0}, {22, 0}};𝒮 = CoxModelFit[{ξ, EventData[Automatic, {{8, 22, 6, 4, 12, 11, 2, 34, 25, 15, 8, 6, 34, 6, 32, 1, 15, 9, 9, 6},
{0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0}, None}]}, {Subscript[x, 1], Subscript[x, 2]}, {Subscript[x, 1], Subscript[x, 2]}];𝒮["ParameterTable"]𝒮["TestTable"]𝒮["RelativeRiskConfidenceIntervals"]𝒮["ParameterConfidenceIntervals"]ξ = {{67, 1}, {11, 0}, {32, 0}, {50, 1}, {65, 1}, {44, 1}, {20, 1}, {26, 0}, {69, 1}, {50, 1}, {25, 1}, {18, 0}, {63, 1}, {41, 0}, {30, 0}, {32, 1}, {46, 1}, {35, 0}, {33, 0}, {22, 0}};𝒮 = CoxModelFit[{ξ, EventData[Automatic, {{8, 22, 6, 4, 12, 11, 2, 34, 25, 15, 8, 6, 34, 6, 32, 1, 15, 9, 9, 6},
{0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0}, None}]}, {Subscript[x, 1], Subscript[x, 2]}, {Subscript[x, 1], Subscript[x, 2]}];将
固定为 25,比较
在不同水平下的生存时间与基准生存时间:
Plot[Evaluate@{𝒮["SF"][{25, 0}][t], 𝒮["SF"][{25, 1}][t], 𝒮["SF"][][t]}, {t, 0, 35}, Exclusions -> None, PlotPoints -> 100, PlotLegends -> {"SubscriptBox[x, 2] = 0", "SubscriptBox[x, 2] = 1", "baseline"}]𝒮["MedianSurvival"][#]& /@ {{25, 0}, {25, 1}}𝒮["MedianSurvival"][]𝒮["SF"][{30, 0}][20]𝒮["PointwiseBands", "SF"][{30, 0}][20]ξ = {{67, 1}, {11, 0}, {32, 0}, {50, 1}, {65, 1}, {44, 1}, {20, 1}, {26, 0}, {69, 1}, {50, 1}, {25, 1}, {18, 0}, {63, 1}, {41, 0}, {30, 0}, {32, 1}, {46, 1}, {35, 0}, {33, 0}, {22, 0}};𝒮S = CoxModelFit[{ξ, EventData[Automatic, {{8, 22, 6, 4, 12, 11, 2, 34, 25, 15, 8, 6, 34, 6, 32, 1, 15, 9, 9, 6},
{0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0}, None}]}, {Subscript[x, 1]}, {Subscript[x, 1], Subscript[x, 2]}, StrataVariables -> Subscript[x, 2]];𝒮S["StrataSummary"]Table[Plot[𝒮S[i][{60, 1}][t], {t, 0, 20}, PlotLabel -> i, Exclusions -> None], {i, {"SF", "CDF", "CHF"}}]𝒮S["ParameterTable"]ξ = {{67, "Orange"}, {11, "Blue"}, {32, "Blue"}, {50, "Orange"}, {65, "Orange"}, {44, "Orange"}, {20, "Orange"}, {26, "Blue"}, {69, "Orange"}, {50, "Orange"}, {25, "Orange"}, {18, "Blue"}, {63, "Orange"}, {41, "Blue"}, {30, "Blue"}, {32, "Orange"}, {46, "Orange"}, {35, "Blue"}, {33, "Blue"}, {22, "Blue"}};𝒮 = CoxModelFit[{ξ, EventData[Automatic, {{8, 22, 6, 4, 12, 11, 2, 34, 25, 15, 8, 6, 34, 6, 32, 1, 15, 9, 9, 6},
{0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0}, None}]}, {Subscript[x, 1], Subscript[x, 2]}, {Subscript[x, 1], Subscript[x, 2]}, NominalVariables -> Subscript[x, 2]];𝒮["ParameterTable"]color["Orange"] = StandardOrange;
color["Blue"] = StandardBlue;Show@Table[Plot[Evaluate[𝒮["SF"][i][t]], {t, 0, 35}, PlotStyle -> color[i[[2]]], PlotRange -> All, AxesOrigin -> {0, 0}], {i, 𝒮["Data"]}]ξ = {{67, 1}, {11, 0}, {32, 0}, {50, 1}, {65, 1}, {44, 1}, {20, 1}, {26, 0}, {69, 1}, {50, 1}, {25, 1}, {18, 0}, {63, 1}, {41, 0}, {30, 0}, {32, 1}, {46, 1}, {35, 0}, {33, 0}, {22, 0}};e = EventData[Automatic, {{8, 22, 6, 4, 12, 11, 2, 34, 25, 15, 8, 6, 34, 6, 32, 1, 15, 9, 9, 6},
{0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0}, None}];𝒮 = CoxModelFit[{ξ, e}, {Subscript[x, 1], Subscript[x, 2], Subscript[x, 1]Subscript[x, 2]}, {Subscript[x, 1], Subscript[x, 2]}];𝒮["ParameterTable"]𝒮N = CoxModelFit[{ξ, e}, {Subscript[x, 1], Subscript[x, 2], Subscript[x, 1]Subscript[x, 2]}, {Subscript[x, 1], Subscript[x, 2]}, NominalVariables -> Subscript[x, 2]];
𝒮S = CoxModelFit[{ξ, e}, {Subscript[x, 1], Subscript[x, 1]Subscript[x, 2]}, {Subscript[x, 1], Subscript[x, 2]}, StrataVariables -> Subscript[x, 2]];𝒮N["ParameterTable"]𝒮S["ParameterTable"]ξ = {{67, 1}, {11, 0}, {32, 0}, {50, 1}, {65, 1}, {44, 1}, {20, 1}, {26, 0}, {69, 1}, {50, 1}, {25, 1}, {18, 0}, {63, 1}, {41, 0}, {30, 0}, {32, 1}, {46, 1}, {35, 0}, {33, 0}, {22, 0}};𝒮 = CoxModelFit[{ξ, EventData[Automatic, {{8, 22, 6, 4, 12, 11, 2, 34, 25, 15, 8, 6, 34, 6, 32, 1, 15, 9, 9, 6},
{0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0}, None}]}, {Subscript[x, 1], Subscript[x, 2]}, {Subscript[x, 1], Subscript[x, 2]}];Subscript[β, 0] = {0, 0};𝒮["TestTableFunction"][Subscript[β, 0]]Subscript[β, 0] = {0.1, b};𝒮["TestTableFunction"][Subscript[β, 0]]ξ = {{67, 1}, {11, 0}, {32, 0}, {50, 1}, {65, 1}, {44, 1}, {20, 1}, {26, 0}, {69, 1}, {50, 1}, {25, 1}, {18, 0}, {63, 1}, {41, 0}, {30, 0}, {32, 1}, {46, 1}, {35, 0}, {33, 0}, {22, 0}};𝒮 = CoxModelFit[{ξ, EventData[Automatic, {{8, 22, 6, 4, 12, 11, 2, 34, 25, 15, 8, 6, 34, 6, 32, 1, 15, 9, 9, 6},
{0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0}, None}]}, {Subscript[x, 1], Subscript[x, 2]}, {Subscript[x, 1], Subscript[x, 2]}];c = {{1, 1}};Subscript[β, 0] = {0, 2};Total[c.{Subscript[β, 1], Subscript[β, 2]}] == Total[c.Subscript[β, 0]]𝒮["TestTableFunction"][c, Subscript[β, 0]]𝒮["BestFitParameters"]Total[c.{Subscript[β, 1], Subscript[β, 2]}] == Total[c.{0, 0}]𝒮["TestTableFunction"][c]𝒮 = CoxModelFit[{1, 2, 3}];𝒮["Properties"]模型规范 (4)
e = RandomVariate[WeibullDistribution[1, 2], 100];𝒮 = CoxModelFit[e];Plot[Evaluate@𝒮[t], {t, 0, 10}, Exclusions -> None]ξ = RandomChoice[{0, 1}, {100, 3}];𝒮2 = CoxModelFit[{ξ, e}, {}, {Subscript[x, 1], Subscript[x, 2], Subscript[x, 3]}];𝒮[t] === 𝒮2[t]ξ = RandomVariate[NormalDistribution[], {100, 4}];
e = RandomVariate[ExponentialDistribution[1 / 30], 100];𝒮 = CoxModelFit[{ξ, e}, {Subscript[x, 1], Subscript[x, 2], Subscript[x, 3], Subscript[x, 4]}, {Subscript[x, 1], Subscript[x, 2], Subscript[x, 3], Subscript[x, 4]}];𝒮["ParameterTable"]𝒮2 = CoxModelFit[{ξ, e}, {Subscript[x, 2], Subscript[x, 3]}, {Subscript[x, 1], Subscript[x, 2], Subscript[x, 3], Subscript[x, 4]}];𝒮2["ParameterTable"]ξ = RandomVariate[NormalDistribution[], {100, 4}];
e = RandomVariate[ExponentialDistribution[1 / 30], 100];𝒮 = CoxModelFit[{ξ, e}, {2Subscript[x, 1], Exp[Subscript[x, 2]], Subscript[x, 3] + Subscript[x, 4]}, {Subscript[x, 1], Subscript[x, 2], Subscript[x, 3], Subscript[x, 4]}];𝒮["ParameterTable"]使用 EventData 指定右删失或左截断的响应时间:
t = RandomVariate[WeibullDistribution[1, 2], 100];
c = RandomChoice[{0, 1}, 100];
ξ = RandomVariate[NormalDistribution[], {100, 2}];𝒮 = CoxModelFit[{ξ, EventData[t, c]}, {Subscript[x, 1], Subscript[x, 2]}, {Subscript[x, 1], Subscript[x, 2]}];𝒮["ParameterTable"]参数估计和模型诊断 (6)
ξ = {{67, 1}, {11, 0}, {32, 0}, {50, 1}, {65, 1}, {44, 1}, {20, 1}, {26, 0}, {69, 1}, {50, 1}, {25, 1}, {18, 0}, {63, 1}, {41, 0}, {30, 0}, {32, 1}, {46, 1}, {35, 0}, {33, 0}, {22, 0}};𝒮 = CoxModelFit[{ξ, EventData[Automatic, {{8, 22, 6, 4, 12, 11, 2, 34, 25, 15, 8, 6, 34, 6, 32, 1, 15, 9, 9, 6},
{0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0}, None}]}, {Subscript[x, 1], Subscript[x, 2]}, {Subscript[x, 1], Subscript[x, 2]}];𝒮["BestFitParameters"]𝒮["RelativeRisk"]𝒮["ParameterConfidenceIntervals"]𝒮["RelativeRiskConfidenceIntervals"]ξ = {{67, 1}, {11, 0}, {32, 0}, {50, 1}, {65, 1}, {44, 1}, {20, 1}, {26, 0}, {69, 1}, {50, 1}, {25, 1}, {18, 0}, {63, 1}, {41, 0}, {30, 0}, {32, 1}, {46, 1}, {35, 0}, {33, 0}, {22, 0}};𝒮 = CoxModelFit[{ξ, EventData[Automatic, {{8, 22, 6, 4, 12, 11, 2, 34, 25, 15, 8, 6, 34, 6, 32, 1, 15, 9, 9, 6},
{0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0}, None}]}, {Subscript[x, 1], Subscript[x, 2]}, {Subscript[x, 1], Subscript[x, 2]}];𝒮["ParameterTable"]𝒮["ParameterTableEntries"]ξ = {{67, 1}, {11, 0}, {32, 0}, {50, 1}, {65, 1}, {44, 1}, {20, 1}, {26, 0}, {69, 1}, {50, 1}, {25, 1}, {18, 0}, {63, 1}, {41, 0}, {30, 0}, {32, 1}, {46, 1}, {35, 0}, {33, 0}, {22, 0}};𝒮 = CoxModelFit[{ξ, EventData[Automatic, {{8, 22, 6, 4, 12, 11, 2, 34, 25, 15, 8, 6, 34, 6, 32, 1, 15, 9, 9, 6},
{0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0}, None}]}, {Subscript[x, 1], Subscript[x, 2]}, {Subscript[x, 1], Subscript[x, 2]}];Table[ListPlot[𝒮[i], Filling -> Axis, PlotLabel -> i], {i, {"MartingaleResiduals", "CoxSnellResiduals", "DevianceResiduals"}}]Table[ListPlot[Transpose@𝒮[i], Filling -> Axis, PlotLabel -> i], {i, {"BetaDifferences", "ScaledBetaDifferences"}}]Table[ListPlot[Transpose@𝒮[i], Filling -> Axis, PlotLabel -> i], {i, {"ScoreResiduals", "SchoenfeldResiduals"}}]ξ = {{67, 1}, {11, 0}, {32, 0}, {50, 1}, {65, 1}, {44, 1}, {20, 1}, {26, 0}, {69, 1}, {50, 1}, {25, 1}, {18, 0}, {63, 1}, {41, 0}, {30, 0}, {32, 1}, {46, 1}, {35, 0}, {33, 0}, {22, 0}};𝒮 = CoxModelFit[{ξ, EventData[Automatic, {{8, 22, 6, 4, 12, 11, 2, 34, 25, 15, 8, 6, 34, 6, 32, 1, 15, 9, 9, 6},
{0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0}, None}]}, {Subscript[x, 1], Subscript[x, 2]}, {Subscript[x, 1], Subscript[x, 2]}];prop = {"AIC", "BIC", "LogLikelihood", "RSquared", "MaxRSquared"};Grid[{prop, 𝒮[prop]}, Alignment -> {{Left, "."}}]ξ = {{67, 1}, {11, 0}, {32, 0}, {50, 1}, {65, 1}, {44, 1}, {20, 1}, {26, 0}, {69, 1}, {50, 1}, {25, 1}, {18, 0}, {63, 1}, {41, 0}, {30, 0}, {32, 1}, {46, 1}, {35, 0}, {33, 0}, {22, 0}};𝒮 = CoxModelFit[{ξ, EventData[Automatic, {{8, 22, 6, 4, 12, 11, 2, 34, 25, 15, 8, 6, 34, 6, 32, 1, 15, 9, 9, 6},
{0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0}, None}]}, {Subscript[x, 1], Subscript[x, 2]}, {Subscript[x, 1], Subscript[x, 2]}];𝒮["TestTable"]𝒮["TestTableEntries"]𝒮[{"LikelihoodRatioStatistic", "WaldStatistic", "ScoreStatistic"}]ξ = {{67, 1}, {11, 0}, {32, 0}, {50, 1}, {65, 1}, {44, 1}, {20, 1}, {26, 0}, {69, 1}, {50, 1}, {25, 1}, {18, 0}, {63, 1}, {41, 0}, {30, 0}, {32, 1}, {46, 1}, {35, 0}, {33, 0}, {22, 0}};𝒮 = CoxModelFit[{ξ, EventData[Automatic, {{8, 22, 6, 4, 12, 11, 2, 34, 25, 15, 8, 6, 34, 6, 32, 1, 15, 9, 9, 6},
{0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0}, None}]}, {Subscript[x, 1], Subscript[x, 2]}, {Subscript[x, 1], Subscript[x, 2]}];𝒮["TestTableFunction"][{0, Subscript[x, 2]}]𝒮["TestTableEntriesFunction"][{0, Subscript[x, 2]}]生存估计和置信度 (8)
计算 SurvivalFunction、CDF 或累积风险函数的估计量:
ξ = {{67, 1}, {11, 0}, {32, 0}, {50, 1}, {65, 1}, {44, 1}, {20, 1}, {26, 0}, {69, 1}, {50, 1}, {25, 1}, {18, 0}, {63, 1}, {41, 0}, {30, 0}, {32, 1}, {46, 1}, {35, 0}, {33, 0}, {22, 0}};𝒮 = CoxModelFit[{ξ, EventData[Automatic, {{8, 22, 6, 4, 12, 11, 2, 34, 25, 15, 8, 6, 34, 6, 32, 1, 15, 9, 9, 6},
{0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0}, None}]}, {Subscript[x, 1], Subscript[x, 2]}, {Subscript[x, 1], Subscript[x, 2]}];所估计的 SurvivalFunction,其中协变量水平为
和
:
𝒮["SF"][{60, 1}][t]//PiecewiseExpand在时刻
时,所估计的基准 SurvivalFunction、CDF 和累积风险:
𝒮["SF"][][12]𝒮["CDF"][][12]𝒮["CHF"][][12]制作所估计的 SurvivalFunction 的汇总表:
ξ = {{67, 1}, {11, 0}, {32, 0}, {50, 1}, {65, 1}, {44, 1}, {20, 1}, {26, 0}, {69, 1}, {50, 1}, {25, 1}, {18, 0}, {63, 1}, {41, 0}, {30, 0}, {32, 1}, {46, 1}, {35, 0}, {33, 0}, {22, 0}};𝒮 = CoxModelFit[{ξ, EventData[Automatic, {{8, 22, 6, 4, 12, 11, 2, 34, 25, 15, 8, 6, 34, 6, 32, 1, 15, 9, 9, 6},
{0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0}, None}]}, {Subscript[x, 1], Subscript[x, 2]}, {Subscript[x, 1], Subscript[x, 2]}];𝒮["FullEventTable", "SF"][{60, 1}]𝒮["FullEventTableEntries", "SF"][{60, 1}]ξ = {{67, 1}, {11, 0}, {32, 0}, {50, 1}, {65, 1}, {44, 1}, {20, 1}, {26, 0}, {69, 1}, {50, 1}, {25, 1}, {18, 0}, {63, 1}, {41, 0}, {30, 0}, {32, 1}, {46, 1}, {35, 0}, {33, 0}, {22, 0}};𝒮 = CoxModelFit[{ξ, EventData[Automatic, {{8, 22, 6, 4, 12, 11, 2, 34, 25, 15, 8, 6, 34, 6, 32, 1, 15, 9, 9, 6},
{0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0}, None}]}, {Subscript[x, 1], Subscript[x, 2]}, {Subscript[x, 1], Subscript[x, 2]}];𝒮["EventTable"][{60, 1}] === 𝒮["EventTable", "SF"][{60, 1}]𝒮["EventTable", "CHF"][{60, 1}]ξ = {{67, 1}, {11, 0}, {32, 0}, {50, 1}, {65, 1}, {44, 1}, {20, 1}, {26, 0}, {69, 1}, {50, 1}, {25, 1}, {18, 0}, {63, 1}, {41, 0}, {30, 0}, {32, 1}, {46, 1}, {35, 0}, {33, 0}, {22, 0}};𝒮 = CoxModelFit[{ξ, EventData[Automatic, {{8, 22, 6, 4, 12, 11, 2, 34, 25, 15, 8, 6, 34, 6, 32, 1, 15, 9, 9, 6},
{0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0}, None}]}, {Subscript[x, 1], Subscript[x, 2]}, {Subscript[x, 1], Subscript[x, 2]}];pwi = 𝒮["PointwiseIntervals"][{50, 1 / 2}]这些是在模型 "EstimationPoints" 计算的 "PointwiseBands":
pwi == 𝒮["PointwiseBands"][{50, 1 / 2}][𝒮["EstimationPoints"]]ξ = {{67, 1}, {11, 0}, {32, 0}, {50, 1}, {65, 1}, {44, 1}, {20, 1}, {26, 0}, {69, 1}, {50, 1}, {25, 1}, {18, 0}, {63, 1}, {41, 0}, {30, 0}, {32, 1}, {46, 1}, {35, 0}, {33, 0}, {22, 0}};𝒮 = CoxModelFit[{ξ, EventData[Automatic, {{8, 22, 6, 4, 12, 11, 2, 34, 25, 15, 8, 6, 34, 6, 32, 1, 15, 9, 9, 6},
{0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0}, None}]}, {Subscript[x, 1], Subscript[x, 2]}, {Subscript[x, 1], Subscript[x, 2]}];一组 Hall–Wellner 同步置信区间,其中协变量水平为
和
:
hwi = 𝒮["HallWellnerIntervals"][{35, 1}]这些是在模型 "HallWellnerBands" 计算的 "EstimationPoints":
hwi == 𝒮["HallWellnerBands"][{35, 1}][𝒮["EstimationPoints"]]另外,也可使用 "EqualPrecisionIntervals" 度量同步置信度:
epi = 𝒮["EqualPrecisionIntervals"][{35, 1}]epi == 𝒮["EqualPrecisionBands"][{35, 1}][𝒮["EstimationPoints"]]ξ = {{67, 1}, {11, 0}, {32, 0}, {50, 1}, {65, 1}, {44, 1}, {20, 1}, {26, 0}, {69, 1}, {50, 1}, {25, 1}, {18, 0}, {63, 1}, {41, 0}, {30, 0}, {32, 1}, {46, 1}, {35, 0}, {33, 0}, {22, 0}};𝒮 = CoxModelFit[{ξ, EventData[Automatic, {{8, 22, 6, 4, 12, 11, 2, 34, 25, 15, 8, 6, 34, 6, 32, 1, 15, 9, 9, 6},
{0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0}, None}]}, {Subscript[x, 1], Subscript[x, 2]}, {Subscript[x, 1], Subscript[x, 2]}];Table[Plot[Evaluate@{𝒮[i][][t], 𝒮["PointwiseBands", i][][t]}, {t, 0, 35}, PlotPoints -> 100, PlotLabel -> i], {i, {"SF", "CHF"}}]Table[Plot[Evaluate@{𝒮[i][{60, 1}][t], 𝒮["PointwiseBands", i][{60, 1}][t]}, {t, 0, 35}, PlotPoints -> 100, PlotLabel -> i], {i, {"SF", "CHF"}}]ξ = {{67, 1}, {11, 0}, {32, 0}, {50, 1}, {65, 1}, {44, 1}, {20, 1}, {26, 0}, {69, 1}, {50, 1}, {25, 1}, {18, 0}, {63, 1}, {41, 0}, {30, 0}, {32, 1}, {46, 1}, {35, 0}, {33, 0}, {22, 0}};𝒮 = CoxModelFit[{ξ, EventData[Automatic, {{8, 22, 6, 4, 12, 11, 2, 34, 25, 15, 8, 6, 34, 6, 32, 1, 15, 9, 9, 6},
{0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0}, None}]}, {Subscript[x, 1], Subscript[x, 2]}, {Subscript[x, 1], Subscript[x, 2]}];协变量水平为
和
时的中位生存时间和在基准处的中位生存时间:
{𝒮["MedianSurvival"][{60, 1}], 𝒮["MedianSurvival"][]}ξ = {{67, 1}, {11, 0}, {32, 0}, {50, 1}, {65, 1}, {44, 1}, {20, 1}, {26, 0}, {69, 1}, {50, 1}, {25, 1}, {18, 0}, {63, 1}, {41, 0}, {30, 0}, {32, 1}, {46, 1}, {35, 0}, {33, 0}, {22, 0}};e = EventData[Automatic, {{8, 22, 6, 4, 12, 11, 2, 34, 25, 15, 8, 6, 34, 6, 32, 1, 15, 9, 9, 6},
{0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0}, None}];𝒮 = CoxModelFit[{ξ, e}, {Subscript[x, 1], Subscript[x, 2]}, {Subscript[x, 1], Subscript[x, 2]}];Plot[𝒮["SF"][{60, 1}][t], {t, 0, 40}, PlotRange -> {0, 1}, Exclusions -> None]{𝒮["MeanSurvival"][{60, 1}], 𝒮["MeanSurvival"][]}𝒮2 = CoxModelFit[{ξ, e}, {Subscript[x, 1], Subscript[x, 2]}, {Subscript[x, 1], Subscript[x, 2]}, Method -> {Automatic, "TailModel" -> "Censored"}];Plot[𝒮2["SF"][{60, 1}][t], {t, 0, 40}, PlotRange -> {0, 1}, Exclusions -> None]{𝒮2["MeanSurvival"][{60, 1}], 𝒮2["MeanSurvival"][]}选项 (13)
ConfidenceLevel (3)
ξ = {{67, 1}, {11, 0}, {32, 0}, {50, 1}, {65, 1}, {44, 1}, {20, 1}, {26, 0}, {69, 1}, {50, 1}, {25, 1}, {18, 0}, {63, 1}, {41, 0}, {30, 0}, {32, 1}, {46, 1}, {35, 0}, {33, 0}, {22, 0}};
e = EventData[Automatic, {{8, 22, 6, 4, 12, 11, 2, 34, 25, 15, 8, 6, 34, 6, 32, 1, 15, 9, 9, 6},
{0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0}, None}];𝒮 = CoxModelFit[{ξ, e}, {Subscript[x, 1], Subscript[x, 2]}, {Subscript[x, 1], Subscript[x, 2]}, ConfidenceLevel -> .9];𝒮["ParameterConfidenceIntervals"]Table[𝒮["ParameterConfidenceIntervals", ConfidenceLevel -> i], {i, {.85, .9, .95}}]ξ = {{67, 1}, {11, 0}, {32, 0}, {50, 1}, {65, 1}, {44, 1}, {20, 1}, {26, 0}, {69, 1}, {50, 1}, {25, 1}, {18, 0}, {63, 1}, {41, 0}, {30, 0}, {32, 1}, {46, 1}, {35, 0}, {33, 0}, {22, 0}};
e = EventData[Automatic, {{8, 22, 6, 4, 12, 11, 2, 34, 25, 15, 8, 6, 34, 6, 32, 1, 15, 9, 9, 6},
{0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0}, None}];𝒮 = CoxModelFit[{ξ, e}, {Subscript[x, 1], Subscript[x, 2]}, {Subscript[x, 1], Subscript[x, 2]}, ConfidenceLevel -> .9];Table[Plot[Evaluate@{𝒮[i][][t], 𝒮["PointwiseBands", i][][t]}, {t, 0, 35}, PlotPoints -> 100, PlotLabel -> i], {i, {"SF", "CDF", "CHF"}}]𝒮["PointwiseBands"][][6]𝒮["PointwiseBands", ConfidenceLevel -> .95][][6]ConfidenceLevel 的设置也用于汇总表中:
ξ = {{67, 1}, {11, 0}, {32, 0}, {50, 1}, {65, 1}, {44, 1}, {20, 1}, {26, 0}, {69, 1}, {50, 1}, {25, 1}, {18, 0}, {63, 1}, {41, 0}, {30, 0}, {32, 1}, {46, 1}, {35, 0}, {33, 0}, {22, 0}};𝒮 = CoxModelFit[{ξ, EventData[Automatic, {{8, 22, 6, 4, 12, 11, 2, 34, 25, 15, 8, 6, 34, 6, 32, 1, 15, 9, 9, 6},
{0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0}, None}]}, {Subscript[x, 1], Subscript[x, 2]}, {Subscript[x, 1], Subscript[x, 2]}];𝒮["EventTable", "CHF", ConfidenceLevel -> .9][{50, 1}]ConfidenceRange (1)
𝒮 = CoxModelFit[EventData[Automatic, {{{2081, Infinity}, {1602, Infinity}, {1496, Infinity}, {1462, Infinity},
{1433, Infinity}, {1377, Infinity}, {1330, Infinity}, {996, Infinity}, {226, Infinity},
{1199, Infinity}, {1111, Infinity}, {530, Infinity}, {1182, Infinity}, {1167, Infinity}, 418,
383, 276, 104, 609, 172, 487, 662, 194, 230, 526, 122, 129, 74, 122, 86, 466, 192, 109, 55, 1,
107, 110, 332}, None, None}]];Plot[Evaluate@{𝒮["SF"][][x], 𝒮["EqualPrecisionBands", ConfidenceRange -> {172, 383}][][x]}, {x, 100, 500}, PlotRange -> {0, 1}]默认时该范围设置为 All:
Plot[Evaluate@{𝒮["SF"][][x], 𝒮["EqualPrecisionBands", ConfidenceRange -> All][][x]}, {x, 0, 2081}, PlotRange -> {0, 1}]将范围设置为 Full:
Plot[Evaluate@{𝒮["SF"][][x], 𝒮["EqualPrecisionBands", ConfidenceRange -> Full][][x]}, {x, 0, 2081}, PlotRange -> {0, 1}]ConfidenceTransform (3)
ξ = {1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0};𝒮 = CoxModelFit[{ξ, EventData[Automatic, {{8, 22, 6, 4, 12, 11, 2, 34, 25, 15, 8, 6, 34, 6, 32, 1, 15, 9, 9, 6},
{0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0}, None}]}, x, x];tr = {"Linear", "LogLog", "ArcSinSqrt", "Log", "Logit"};Table[{i, 𝒮["PointwiseBands", ConfidenceTransform -> i][{0}][15]}, {i, tr}]//Grid𝒮["PointwiseBands", ConfidenceTransform -> "LogLog"][{0}][15]𝒮["PointwiseBands"][{0}][15]𝒮 = CoxModelFit[EventData[Automatic, {{30, 32, 26, {37, Infinity}, 29, {32, Infinity}, 24, {31, Infinity},
{31, Infinity}, 42}, None, None}]];𝒮["EventTable", ConfidenceTransform -> "Linear"][]𝒮["EventTable", ConfidenceTransform -> "LogLog"][]𝒮 = CoxModelFit[EventData[Automatic, {{30, 32, 26, {37, Infinity}, 29, {32, Infinity}, 24, {31, Infinity},
{31, Infinity}, 42}, None, None}]];tr = {"Linear", "LogLog", "ArcSinSqrt", "Log", "Logit"};
trans = {#&, Log[Log[#]]&, ArcSin[Sqrt[#]]&, Log[#]&, Log[(#/1 - #)]&};MapThread[{#1, 𝒮["PointwiseBands", ConfidenceTransform -> #2][][40]}&, {tr, trans}]//GridMethod (3)
ξ = {1, 1, 1, 0, 0, 0};
e = EventData[{1, 1, 6, 6, 8, 9}, {0, 1, 0, 0, 1, 0}];efron = CoxModelFit[{ξ, e}, Subscript[x, 1], Subscript[x, 1], Method -> "Efron"];
breslow = CoxModelFit[{ξ, e}, Subscript[x, 1], Subscript[x, 1], Method -> "Breslow"];
exact = CoxModelFit[{ξ, e}, Subscript[x, 1], Subscript[x, 1], Method -> "Exact"];#["BestFitParameters"]& /@ {efron, breslow, exact}e2 = EventData[{1, 5, 3, 4, 2, 6}];Equal@@Table[CoxModelFit[{ξ, e2}, Subscript[x, 1], Subscript[x, 1], Method -> i]["BestFitParameters"], {i, {"Efron", "Breslow", "Exact"}}]ξ = {{67, 1}, {11, 0}, {32, 0}, {50, 1}, {65, 1}, {44, 1}, {20, 1}, {26, 0}, {69, 1}, {50, 1}, {25, 1}, {18, 0}, {63, 1}, {41, 0}, {30, 0}, {32, 1}, {46, 1}, {35, 0}, {33, 0}, {22, 0}};e = EventData[Automatic, {{8, 22, 6, 4, 12, 11, 2, 34, 25, 15, 8, 6, 34, 6, 32, 1, 15, 9, 9, 6},
{0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0}, None}];efron = CoxModelFit[{ξ, e}, {Subscript[x, 1], Subscript[x, 2]}, {Subscript[x, 1], Subscript[x, 2]}, Method -> {"Efron", "BaselineHazardMethod" -> "Efron"}];breslow = CoxModelFit[{ξ, e}, {Subscript[x, 1], Subscript[x, 2]}, {Subscript[x, 1], Subscript[x, 2]}, Method -> {"Breslow", "BaselineHazardMethod" -> "BreslowNelsonAalen"}];exact = CoxModelFit[{ξ, e}, {Subscript[x, 1], Subscript[x, 2]}, {Subscript[x, 1], Subscript[x, 2]}, Method -> {"Exact", "BaselineHazardMethod" -> "KalbfleischPrentice"}];Plot[Evaluate@Table[i["SF"][][t], {i, {efron, breslow, exact}}], {t, 0, 35}, PlotPoints -> 75, Exclusions -> None, PlotLegends -> {"efron", "breslow", "exact"}]ekp = CoxModelFit[{ξ, e}, {Subscript[x, 1], Subscript[x, 2]}, {Subscript[x, 1], Subscript[x, 2]}, Method -> {"Efron", "BaselineHazardMethod" -> "KalbfleischPrentice"}];Plot[ekp["SF"][][t], {t, 0, 35}, Exclusions -> None, PlotPoints -> 75]如果最后一个观察值删失,生存将在该点外被 Indeterminate:
ξ = {{67, 1}, {11, 0}, {32, 0}, {50, 1}, {65, 1}, {44, 1}, {20, 1}, {26, 0}, {69, 1}, {50, 1}, {25, 1}, {18, 0}, {63, 1}, {41, 0}, {30, 0}, {32, 1}, {46, 1}, {35, 0}, {33, 0}, {22, 0}};e = EventData[{1, 2, 4, 6, 6, 6, 6, 8, 8, 9, 9, 11, 12, 15, 15, 22, 25, 32, 34, 34}, {0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1}];𝒮 = CoxModelFit[{ξ, e}, {Subscript[x, 1], Subscript[x, 2]}, {Subscript[x, 1], Subscript[x, 2]}];Plot[𝒮["SF"][{60, 1}][x], {x, 0, 50}, PlotRange -> {0, 1}]tailMods = {"Censored", "Exponential", "Weibull", "Gamma", "Normal", "LogNormal", "GompertzMakeham", "InverseGaussian", "LogLogistic"};models = Table[CoxModelFit[{ξ, e}, {Subscript[x, 1], Subscript[x, 2]}, {Subscript[x, 1], Subscript[x, 2]}, Method -> {Automatic, "TailModel" -> i}]["SF"][{60, 1}], {i, tailMods}]//Quiet;MapThread[Plot[#1[t], {t, 0, 70}, PlotLabel -> ToString@#2, Ticks -> None, Exclusions -> None, PlotRange -> {0, 1}]&, {models, tailMods}]NominalVariables (1)
ξ = {{"dog", "no"}, {"dog", "no"}, {"dog", "no"}, {"dog", "no"}, {"dog", "no"}, {"dog", "yes"}, {"dog", "no"}, {"cat", "no"}, {"dog", "no"}, {"dog", "no"}, {"cat", "yes"}, {"dog", "no"}, {"dog", "no"}, {"cat", "yes"}, {"cat", "yes"}, {"dog", "no"}, {"cat", "no"}, {"dog", "yes"}, {"cat", "no"}, {"cat", "no"}, {"cat", "yes"}, {"cat", "yes"}, {"dog", "yes"}, {"dog", "no"}, {"dog", "yes"}};e = EventData[Automatic, {{20, 14, 20, 92, 1, 90, 5, 11, 15, 41, 60, 4, 2, 66, 21, 3, 18, 32, 33, 36,
6, 55, 134, 7, 15}, None, None}];𝒮 = CoxModelFit[{ξ, e}, {spec, treat}, {spec, treat}, NominalVariables -> {spec, treat}];𝒮["ParameterTable"]StrataVariables (1)
为一组由物种和治疗预测量组成的假设数据创建一个分层的 Cox 模型:
ξ = {{"dog", "no"}, {"dog", "no"}, {"dog", "no"}, {"dog", "no"}, {"dog", "no"}, {"dog", "yes"}, {"dog", "no"}, {"cat", "no"}, {"dog", "no"}, {"dog", "no"}, {"cat", "yes"}, {"dog", "no"}, {"dog", "no"}, {"cat", "yes"}, {"cat", "yes"}, {"dog", "no"}, {"cat", "no"}, {"dog", "yes"}, {"cat", "no"}, {"cat", "no"}, {"cat", "yes"}, {"cat", "yes"}, {"dog", "yes"}, {"dog", "no"}, {"dog", "yes"}};e = EventData[Automatic, {{20, 14, 20, 92, 1, 90, 5, 11, 15, 41, 60, 4, 2, 66, 21, 3, 18, 32, 33, 36,
6, 55, 134, 7, 15}, None, None}];𝒮 = CoxModelFit[{ξ, e}, {treat}, {spec, treat}, NominalVariables -> treat, StrataVariables -> spec];𝒮["StrataSummary"]𝒮["ParameterTable"]𝒮2 = CoxModelFit[{ξ, e}, {}, {spec, treat}, StrataVariables -> {spec, treat}];𝒮2["StrataSummary"]𝒮2["BaselineList"]Table[Plot[𝒮2["SF"][i][t], {t, 0, 50}, PlotRange -> {0, 1}, PlotLabel -> i], {i, 𝒮2["BaselineList"]}]WorkingPrecision (1)
ξ = {{67, 1}, {11, 0}, {32, 0}, {50, 1}, {65, 1}, {44, 1}, {20, 1}, {26, 0}, {69, 1}, {50, 1}, {25, 1}, {18, 0}, {63, 1}, {41, 0}, {30, 0}, {32, 1}, {46, 1}, {35, 0}, {33, 0}, {22, 0}};e = EventData[Automatic, {{8, 22, 6, 4, 12, 11, 2, 34, 25, 15, 8, 6, 34, 6, 32, 1, 15, 9, 9, 6},
{0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0}, None}];𝒮 = CoxModelFit[{ξ, e}, {Subscript[x, 1], Subscript[x, 2]}, {Subscript[x, 1], Subscript[x, 2]}, WorkingPrecision -> 30]𝒮["ParameterConfidenceIntervals"]应用 (5)
耳螨治疗 (1)
16条狗和9只猫被选为一组测试一种治疗耳螨的新疗法. 随机指定每个动物使用旧药或新药。确定新疗法是否能够延长耳螨再感染的时间(以星期为单位):
ξ = {{"dog", "no"}, {"dog", "no"}, {"dog", "no"}, {"dog", "no"}, {"dog", "no"}, {"dog", "yes"}, {"dog", "no"}, {"cat", "no"}, {"dog", "no"}, {"dog", "no"}, {"cat", "yes"}, {"dog", "no"}, {"dog", "no"}, {"cat", "yes"}, {"cat", "yes"}, {"dog", "no"}, {"cat", "no"}, {"dog", "yes"}, {"cat", "no"}, {"cat", "no"}, {"cat", "yes"}, {"cat", "yes"}, {"dog", "yes"}, {"dog", "no"}, {"dog", "yes"}};e = EventData[Automatic, {{20, 14, 20, 92, 1, 90, 5, 11, 15, 41, 60, 4, 2, 66, 21, 3, 18, 32, 33, 36,
6, 55, 134, 7, 15}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
None}];𝒮 = CoxModelFit[{ξ, e}, drug, {species, drug}, NominalVariables -> drug, StrataVariables -> species];𝒮["ParameterTable"]csr = 𝒮["CoxSnellResiduals"];Subscript[𝒮, csr] = SurvivalModelFit[EventData[csr, 𝒮["CensoringIndicators"]], Method -> "NelsonAalen"];Show[Plot[x, {x, 0, 3}, PlotStyle -> {Dashed, Gray}], ListPlot[Transpose[{Subscript[𝒮, csr]["CHF"][csr], csr}], AspectRatio -> 1]]喉癌 (3)
对一组由 90 例被确诊为喉癌的男性患者进行观察. 每个病人被归类为处于四个阶段的癌症之一,其中 1 是最不严重的,而 4 是最严重的. 要研究的是是癌症的阶段是否与生存显著关联:
larynx = ExampleData[{"Statistics", "LarynxCancer"}];ξ = larynx[[All, {1, 3}]];
e = EventData[larynx[[All, 2]], larynx[[All, 5]]];𝒮 = CoxModelFit[{ξ, e}, {stage, age}, {stage, age}, NominalVariables -> stage];𝒮["ParameterTable"]在 5% 水平下,第 2 阶段患者死亡的风险与第 1 阶段相比没有不同:
𝒮["RelativeRiskConfidenceIntervals"][[2]]求与第 2 阶段喉癌患者相比,第 4 阶段患者死亡的相对风险的估计值:
larynx = ExampleData[{"Statistics", "LarynxCancer"}];ξ = larynx[[All, {1, 3}]];
e = EventData[larynx[[All, 2]], larynx[[All, 5]]];𝒮 = CoxModelFit[{ξ, e}, {stage, age}, {stage, age}, NominalVariables -> stage];{stg2, stg4} = 𝒮["BestFitParameters"][[{1, 3}]]est = Exp[stg4 - stg2]cov = 𝒮["CovarianceMatrix"];se = Sqrt[cov[[3, 3]] + cov[[1, 1]] - 2 cov[[1, 3]]]在 5% 水平下,第 4 阶段患者死亡的风险高于第 2 阶段患者:
α = .05;z = Quantile[NormalDistribution[], 1 - α / 2];Exp[{(stg4 - stg2) - z * se, (stg4 - stg2) + z * se}]Plot[Evaluate@Table[𝒮["SF"][{i, 50}][t], {i, 4}], {t, 0, 12}, Exclusions -> None, PlotLegends -> (Row[{"Stage ", #}]& /@ Range[4])]larynx = ExampleData[{"Statistics", "LarynxCancer"}];y = EventData[larynx[[All, 2]], larynx[[All, 5]]];
x = larynx[[All, 1]];𝒮 = CoxModelFit[{x, y}, {}, stage, StrataVariables -> stage];已知有序层,LogRankTest 可用于进行趋势检验:
{z, Σ} = LogRankTest[#["Response"]& /@ 𝒮["StrataModels"], "Equal", {"TestStatisticList", "CovarianceMatrix"}];p = Length[𝒮["StrataModels"]];t = (Underoverscript[∑, j = 1, p]j z[[j]]/Sqrt[Underoverscript[∑, j = 1, p]Underoverscript[∑, g = 1, p]j g Σ[[j, g]]])NProbability[stat > t, statNormalDistribution[]]急性白血病 (1)
对101例严重急性髓系白血病的样本进行记录. 在这些患者中,有51例曾接受自体骨髓移植,50例接受异基因骨髓移植. 要研究的是比例风险模型是否对于该数据有效:
bone = ExampleData[{"Statistics", "BoneMarrowTransplants"}];y = EventData[bone[[All, 1]], bone[[All, 3]]];x = bone[[All, 2]];𝒮 = CoxModelFit[{x, y}, {}, type, StrataVariables -> type]Plot[Evaluate@{Log[𝒮["CHF"][{1}][t]], Log[𝒮["CHF"][{2}][t]]}, {t, 0, 25}, AxesOrigin -> {0, -4}, Exclusions -> None]Plot[Evaluate[Log[𝒮["CHF"][{2}][t]] - Log[𝒮["CHF"][{1}][t]]], {t, 0, 25}, AxesOrigin -> {0, 0}, Exclusions -> None, PlotRange -> {-1.5, 1}]Show[Plot[x, {x, 0, 1}, PlotStyle -> {Dashed, Gray}], ListLinePlot[Evaluate@Table[{𝒮["CHF"][{1}][t], 𝒮["CHF"][{2}][t]}, {t, 𝒮["EstimationPoints"]}], InterpolationOrder -> 0]]属性和关系 (4)
ξ = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};𝒮 = CoxModelFit[{ξ, EventData[Automatic, {{32, 34, 28, 26, 31, 25, 29, 31, 28, 25, 30, 19, 28, 35, 35, 29, 33, 32, 31,
29}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1}, None}]}, x, x];β = 𝒮["BestFitParameters"]rr = 𝒮["RelativeRisk"]Exp[β] == rrξ = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};𝒮 = CoxModelFit[{ξ, EventData[Automatic, {{32, 34, 28, 26, 31, 25, 29, 31, 28, 25, 30, 19, 28, 35, 35, 29, 33, 32, 31,
29}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1}, None}]}, x, x];𝒮["BestFitParameters"]𝒮["RelativeRisk"]Exp[Abs[𝒮["BestFitParameters"]]]𝒮2 = CoxModelFit[{1 - ξ, EventData[Automatic, {{32, 34, 28, 26, 31, 25, 29, 31, 28, 25, 30, 19, 28, 35, 35, 29, 33, 32, 31,
29}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1}, None}]}, x, x];𝒮2["RelativeRisk"]CoxModelFit 是广义的 SurvivalModelFit:
e = EventData[Automatic, {{8, 22, 6, 4, 12, 11, 2, 34, 25, 15, 8, 6, 34, 6, 32, 1, 15, 9, 9, 6},
{0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0}, None}];mod = CoxModelFit[e];
smod = SurvivalModelFit[e, Method -> "NelsonAalen"];t = smod["EstimationPoints"];Chop[mod["SF"][][t] - smod["SF"][t]]mod2 = CoxModelFit[e, Method -> {Automatic, "BaselineHazardMethod" -> "KalbfleischPrentice"}];
smod2 = SurvivalModelFit[e, Method -> "KaplanMeier"];Chop[mod2["SF"][][t] - smod2["SF"][t]]使用 LogRankTest 比较各组的风险率:
t = {32, 34, 28, 26, 31, 25, 29, 31, 28, 25, 30, 19, 28, 35, 35, 29, 33, 32, 31, 29};
ci = {0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1};
ξ = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};𝒮 = CoxModelFit[{ξ, EventData[t, ci]}, x, x];Plot[{𝒮["CHF"][{0}][t], 𝒮["CHF"][{1}][t]}, {t, 18, 40}, Exclusions -> None]LogRankTest[Table[EventData[Pick[t, ξ, i], Pick[ci, ξ, i]], {i, Union[ξ]}]]相关指南
-
▪
- 生存分析 ▪
- 非参数统计分布 ▪
- 可靠性 ▪
- 用于可靠性分析中的分布 ▪
- 科学数据分析 ▪
- 生命科学和医学:数据与计算 ▪
- 概率和统计 ▪
- 表格建模
文本
Wolfram Research (2012),CoxModelFit,Wolfram 语言函数,https://reference.wolfram.com/language/ref/CoxModelFit.html.
CMS
Wolfram 语言. 2012. "CoxModelFit." Wolfram 语言与系统参考资料中心. Wolfram Research. https://reference.wolfram.com/language/ref/CoxModelFit.html.
APA
Wolfram 语言. (2012). CoxModelFit. Wolfram 语言与系统参考资料中心. 追溯自 https://reference.wolfram.com/language/ref/CoxModelFit.html 年
BibTeX
@misc{reference.wolfram_2026_coxmodelfit, author="Wolfram Research", title="{CoxModelFit}", year="2012", howpublished="\url{https://reference.wolfram.com/language/ref/CoxModelFit.html}", note=[Accessed: 09-September-2026]}
BibLaTeX
@online{reference.wolfram_2026_coxmodelfit, organization={Wolfram Research}, title={CoxModelFit}, year={2012}, url={https://reference.wolfram.com/language/ref/CoxModelFit.html}, note=[Accessed: 09-September-2026]}