Solved – Error “system is computationally singular” when running cox.zph for a Cox Model

cox-modelproportional-hazardsr

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)

summary(analise_teste)

With the following results:

Call:
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?

Best Answer

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.