1

I have a large dataset that I subsetted and created a new dataset. I used the following code that works perfectly

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

But when I used the subsetted datas set using the following code,

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

it gave me the following error:

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

This is my new data structure

 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> 

I saw this post but I could not solve my current problem. Any advice will be greatly appreciated.

Mohamed Rahouma
  • 1,084
  • 9
  • 20

2 Answers2

0

Add the droplevels() command to your subset.

  • 1
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Dec 10 '21 at 21:05
0

This happened to me too, and I found that using droplevels() to forget about the levels you did not include in the subset solved it:

library(survival)
library(coxme)

Change ph.ecog from number to categorical to make this point:

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

Works well for the full data set. Subset out some levels of ph.ecog, and it gives this error:

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

Using droplevels() to forget about empty levels allows coxme to fit again:

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