首页 > 解决方案 > 在数据子集化时,没有起始估计是 coxme 的成功错误

问题描述

我有一个大型数据集,我对其进行了子集化并创建了一个新数据集。我使用了以下完美运行的代码

require(sjPlot);require(coxme)
tab_model(coxme(Surv(comp2_years, comp2)~FEMALE+(1|TRIAL), data))

但是当我使用以下代码使用子集数据集时,

www<- subset(data, (data$TRIAL != 5 & data$Sex.standerd.BMI.gpM1F2 >=1))
tab_model(coxme(Surv(comp2_years, comp2)~FEMALE+(1|TRIAL), www))

它给了我以下错误:

Error in coxme.fit(X, Y, strats, offset, init, control, weights = weights,  : 
  No starting estimate was successful

这是我的新数据结构

 str(www)
Classes ‘data.table’ and 'data.frame':  7576 obs. of  79 variables:
 $ TRIAL                                                          : num  1 1 1 1 1 1 1 1 1 1 ...
 $ FEMALE                                                         : Factor w/ 2 levels "1","2": 1 1 1 1 1 1 1 1 1 1 ...
 $ type_comp2                                                     : chr  "0" "0" "Revasc" "0" ...
 $ comp2                                                          : num  0 0 1 0 0 0 0 0 0 1 ...
 $ comp2_years                                                    : num  10 10 9.77 10 10 ...
 $ Sex.standerd.BMI.gpM1F2                                        : num  1 1 1 1 1 1 1 1 1 1 ...
 $ Trial1_4.MiddleBMI                                             : num  1 1 1 1 1 1 1 1 1 1 ...
 - attr(*, ".internal.selfref")=<externalptr> 

我看到了这篇文章,但我无法解决我当前的问题。任何建议将不胜感激。

标签: rrandommixed-modelscox-regression

解决方案


这也发生在我身上,我发现使用droplevels()忘记您未包含在子集中的级别解决了它:

library(survival)
library(coxme)

从数字更改ph.ecog为分类以说明这一点:

lung$ph.ecog <- as.factor(lung$ph.ecog)
(fit <- coxme(Surv(time, status) ~ ph.ecog + age + (1|inst), lung))

适用于完整的数据集。子集一些级别ph.ecog,它给出了这个错误:

lunga <- subset(lung, !ph.ecog %in% c(2, 3))
(fita <- coxme(Surv(time, status) ~ ph.ecog + age + (1|inst), lunga))
Error in coxme.fit(X, Y, strats, offset, init, control, weights = weights,  : 
  No starting estimate was successful

使用droplevels()忘记空级别允许coxme再次适应:

lungb <- droplevels(subset(lung, !ph.ecog %in% c(2, 3)))
(fitb <- coxme(Surv(time, status) ~ ph.ecog + age + (1|inst), lungb))

推荐阅读