r - 在数据子集化时,没有起始估计是 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>
我看到了这篇文章,但我无法解决我当前的问题。任何建议将不胜感激。
解决方案
这也发生在我身上,我发现使用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))
推荐阅读
- reactjs - 使用 React 钩子时无法重新渲染引导表
- android - 如何在不消失约束布局中的组件的情况下使用高程?
- python - MT5/Metatrader 5 使用 python 连接到不同的 MT5 终端
- android - AdMob 仅显示测试广告,而非真实广告
- typescript - 将数据传递给根 Vue 类组件
- rust - 如何销毁范围内的引用?
- postgresql - 生成缺失的数据并填写 - postgresql
- java - 如何处理其父类中的@Autowire 对象?
- javascript - D3.js 将圆圈添加到折线图上的每个其他点
- excel - IF公式怎么用?