title: R coxph() with interaction term, Warning: X matrix deemed to be singular
body: <p>Please be patient with me. I'm new to this site.</p>
  
  <p>I am modeling turtle nest survival using the coxph() function and have run into a confusing problem with an interaction term between species and nest cages. I have nests from 3 species of turtles (7, 10, and 111 nests per species). </p>
  
  <p>There are nest cages on all nests for the species(1) with 7 nests. </p>
  
  <p>There are no nest cages on all the nests for the species(2) with 10 nests. </p>
  
  <p>There are nest cages on about half of the nests for the species(3) with 111 nests.</p>
  
  <p>Here is my model with the summary output:</p>
  
  <pre><code>    S&lt;-Surv(time, event)
  
      n8&lt;-coxph(S~species:cage, data=nesta1)
      Warning message:
      In coxph(S ~ species:cage, data = nesta1) :
        X matrix deemed to be singular; variable 1 5 6
  
      summary(n8)
  
      Call:
      coxph(formula = S ~ species:cage, data = nesta1)
  
        n= 128, number of events= 73 
  
                           coef exp(coef) se(coef)      z Pr(&gt;|z|)   
      species1:cageN      NA        NA   0.0000     NA       NA   
      species2:cageN  1.2399    3.4554   0.3965  3.128  0.00176 **
      species3:cageN  0.5511    1.7351   0.2664  2.068  0.03860 * 
      species1:cageY -0.1054    0.8999   0.6145 -0.172  0.86379   
      species2:cageY      NA        NA   0.0000     NA       NA   
      species3:cageY      NA        NA   0.0000     NA       NA   
      ---
      Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
  
                        exp(coef) exp(-coef) lower .95 upper .95
      species1:cageN        NA         NA        NA        NA
      species2:cageN    3.4554     0.2894    1.5887     7.515
      species3:cageN    1.7351     0.5763    1.0293     2.925
      species1:cageY    0.8999     1.1112    0.2698     3.001
      species2:cageY        NA         NA        NA        NA
      species3:cageY        NA         NA        NA        NA
  
      Concordance= 0.61  (se = 0.038 )
      Rsquare= 0.079   (max possible= 0.993 )
      Likelihood ratio test= 10.57  on 3 df,   p=0.01426
      Wald test            = 11.36  on 3 df,   p=0.009908
      Score (logrank) test = 12.22  on 3 df,   p=0.006672
  </code></pre>
  
  <p>I understand that I would have singularities for species 1 and 2, but not for species 3. Why would the "species3:cageY" line be singular when there are species 3 nests with nest cages on them? 
  Is it ok to include species 1 and 2 even though they have those singularities?</p>
  
  <p>Edit: I cannot find any errors in my data. I have decimal numbers for the time variable for a few nests, but that doesn't seem to be a problem for species 3 nests without a nest cage. For species 3, I have the full range of time values for nests with and without a nest cage and I have both true and false events for nests with and without a nest cage.</p>
  
  <p>Edit:
           with( nesta1, table(event, species, cage))</p>
  
  <pre><code>      , , cage = N
  
             species
      event    1    2    3
          0    0    1   24
          1    0    9   38
  
      , , cage = Y
  
           species
      event    1    2    3
          0    4    0   26
          1    3    0   23
  </code></pre>
  
  <p>Edit 2: I understand that interaction-only models are not very useful, but the interaction term results behave the same way whether I have other main effects in the model or not. I've removed the other main effects to simplify this question.</p>
  
  <p>Thank you!</p>