I have built an extended Cox Model in R, with time-dependent covariates, as described in this R vignette.

I have built the model by running the following:

analise_teste <- coxph(Surv(tstart, tstop, Falecido) ~ Idade_no_diagnostico + Nr_cirurgias_acumuladas + Nr_infeccoes_acumuladas + Nr_dias_internamento_acumulados + Severidade + Mortalidade + Centro_Referencia ,data=analise_survival_extended_Cox_PH)


With the following results:

coxph(formula = Surv(tstart, tstop, Falecido) ~ Idade_no_diagnostico + 
    Nr_cirurgias_acumuladas + Nr_infeccoes_acumuladas + Nr_dias_internamento_acumulados + 
    Severidade + Mortalidade + Centro_Referencia, data = analise_survival_extended_Cox_PH)

  n= 331838, number of events= 46539 

                                      coef  exp(coef)   se(coef)       z Pr(>|z|)    
Idade_no_diagnostico             0.0061236  1.0061424  0.0003944  15.525  < 2e-16 ***
Nr_cirurgias_acumuladas         -0.3067127  0.7358620  0.0072666 -42.208  < 2e-16 ***
Nr_infeccoes_acumuladas         -0.0089313  0.9911084  0.0073480  -1.215    0.224    
Nr_dias_internamento_acumulados  0.0036138  1.0036203  0.0001373  26.318  < 2e-16 ***
Severidade1                     -0.8645586  0.4212375  0.0332277 -26.019  < 2e-16 ***
Severidade2                     -0.1430922  0.8666742  0.0242101  -5.910 3.41e-09 ***
Severidade3                      0.2056173  1.2282830  0.0216205   9.510  < 2e-16 ***
Severidade4                             NA         NA  0.0000000      NA       NA    
Mortalidade1                    -2.0655212  0.1267522  0.0294538 -70.128  < 2e-16 ***
Mortalidade2                    -1.4821604  0.2271464  0.0204496 -72.479  < 2e-16 ***
Mortalidade3                    -0.5915275  0.5534812  0.0175193 -33.764  < 2e-16 ***
Mortalidade4                            NA         NA  0.0000000      NA       NA    
Centro_Referencia1              -0.2474286  0.7808060  0.0159085 -15.553  < 2e-16 ***
Centro_Referencia2              -0.1390621  0.8701740  0.0240100  -5.792 6.96e-09 ***
Centro_Referencia3              -0.0079389  0.9920925  0.0384875  -0.206    0.837    

However, when I try to run cox.zph to check proportional hazard assumption, I get the following error:

> cox.zph(analise_teste)
Error in solve.default(imat, u) : 
  system is computationally singular: reciprocal condition number = 6.75764e-19

This only happens when I add the covariates Severidade and/or Mortalidade (or both, as in this case) when building the model. Without these variables, I am able to get the results for cox.zph.

Severidade and Mortalidade are both factor variables, with possible 4 values: "1","2","3" and "4".

What may be causing this error?

  • 1
    $\begingroup$ Severity and mortality are collinear. Find an appropriate encoding that doesn't result in a singular fit. $\endgroup$
    – AdamO
    Commented Apr 13, 2020 at 23:16
  • $\begingroup$ I have used those covariates to take into account the perceived morbidity of the patient at any given state, however your point makes sense, those may be related. What would be the best strategy, in your oppinion, to overcome the singular fit? I was thinking of maybe combining both as in Severity*Mortality. Thank you for your comment! $\endgroup$
    – Mateus
    Commented Apr 13, 2020 at 23:24
  • $\begingroup$ The issue is more technical than that they are (clinically) related. Calculating their interaction will certainly make things worse. I don't have the codebook. I understand severity grades, but how is "mortality" of 4 levels? $\endgroup$
    – AdamO
    Commented Apr 14, 2020 at 0:19
  • 2
    $\begingroup$ The mortality variable in this case is the risk of death in an episode, ranging from 1 (minor) to 4 (extreme). Meanwhile, I also found out the error I was getting on cox.zph ("system is computationally singular"), was due to the Severidade and Mortalidade factors had a 0 value with 0 occurrences. The solution was to convert the Severidade and Mortalidade to character->numeric->factor and re-run the model and cox.zph, getting the outputs with no function error. Thank you for the support! $\endgroup$
    – Mateus
    Commented Apr 14, 2020 at 22:02

1 Answer 1


I just had this problem, and solved it. Hopefully this will help you:

I had deleted one small group from my data set, based on a covariate with three levels. However, that covariate had been set to a factor with three levels. I noticed that there were NA’s showing up for that one level. When I recast the covariate as two levels, the error went away.

This might apply to other things with factor levels in R.

  • $\begingroup$ This is a well-intentioned answer, and your solution is serendipitous. However, this suggests a wild goose chase, and a better answer would provide some guidance on how to identify the appropriate variable(s) for removal. The R message is not helpful, but nature of the problem is mathematical - dealing with the joint structure of the covariates and outputs. Without pinpointing the precise details of the model. this is likely not the solution the OP needs to run the model. $\endgroup$
    – AdamO
    Commented Aug 7, 2023 at 16:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.