title: How to ignore linearly correlated variables introduced by factor reference cell coding
body: <p>Assume I have a dataset containing two categorical predictor variables (a,b) and a binary target (y) variable.</p>
  
  <pre><code>&gt; df &lt;- data.frame(
  &gt;  a = factor(c("cat1","cat2","cat3","cat1","cat2")), 
  &gt;  b = factor(c("cat1","cat1","cat3","cat2","cat2")), 
  &gt;  y = factor(c(T,F,T,F,T))
  &gt; )
  </code></pre>
  
  <p>The following logical relations exist in the data:</p>
  
  <pre><code>if (a = cat3) then (b = cat3 and y = true)
  else if (a = b) then (y = true) else y = false
  </code></pre>
  
  <p>I want to use <code>glm</code> to build a model for my dataset.
  <code>glm</code> will automatically apply reference cell coding on my categorical variables a and b. It will also take care of finding the right number of codes for each factor variable, so that no <code>alias</code> variables are introduced (explained <a href="https://stats.stackexchange.com/a/70700/87383">here</a>).</p>
  
  <p>However it can happen, as for the dataset above, that a linear relationship exists between one reference code generated for variable a and one reference code of variable b.</p>
  
  <p>See the output of my model:</p>
  
  <pre><code>&gt; model &lt;- glm(y ~ ., family=binomial(link='logit'), data=df)
  &gt; summary(model)
  ...
  Coefficients: (1 not defined because of singularities)
            Estimate Std. Error z value Pr(&gt;|z|)
  (Intercept)  1.965e-16  1.732e+00   0.000    1.000
  acat2       -2.396e-16  2.000e+00   0.000    1.000
  acat3        1.857e+01  6.523e+03   0.003    0.998
  bcat2        0.000e+00  2.000e+00   0.000    1.000
  bcat3               NA         NA      NA       NA # &lt;- get rid of this?
  </code></pre>
  
  <p>How should I handle this case?
  Is there a way to tell glm to omit some of the generated reference codes?
  In the real problem my <code>"cat3"</code> value corresponds to <code>NA</code>. I have two meaningful factor variables which are <code>NA</code> in exactly the same instances of my dataset.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>The checked answer solves the question, however, in this specific case the singularities can simply be ignored as pointed out in the comments.</p>