title: R - How to contrast code factors and retain meaningful labels in output summary
body: <p>Ok everyone, once and for all, how do you (emphasis on you, because I'm sure there is more than one way to achieve this) contrast code (treatment, sum, helmert, etc.) and retain a meaningful factor label (so you can make meaningful interpretations of effects) in the glm function?</p>
  
  <p>I understand I can use level() to understand which factor level is the reference, but that get's tedious when I begin to involve factors with 5 or 10 levels and their interactions.</p>
  
  <p>Here is a quick two factor example of what I mean</p>
  
  <pre><code>outcome &lt;- c(1,0,0,1,1,0,0,0,1, 0, 0, 1)
  firstvar &lt;- c("A", "B", "C", "C", "B", "B", "A", "A", "C", "A", "C", "B")
  secondvar &lt;- c("D", "D", "E", "F", "F", "E", "D", "E", "F", "F", "D", "E")
  df &lt;- as.data.frame(cbind(outcome, firstvar, secondvar))
  
  df$firstvar &lt;- as.factor(df$firstvar)
  df$secondvar &lt;- as.factor(df$secondvar)
  
  #not coded manually (and default appears to be dummy or treatment coding)
  #gives meaningful factor labels in summary function
  summary(glm(outcome ~ firstvar*secondvar, data=df, family="binomial"))
  
  #effects coded
  #does not give meaningful factor labels
  contrasts(df$firstvar)=contr.sum(3)
  contrasts(df$secondvar)=contr.sum(3)
  summary(glm(outcome ~ firstvar*secondvar, data=df, family="binomial"))
  
  #dummy coded
  contrasts(df$firstvar)=contr.treatment(3); 
  contrasts(df$secondvar)=contr.treatment(3); 
  summary(glm(outcome ~ firstvar*secondvar, data=df, family="binomial"))
  </code></pre>
  
  <p>Any and all suggestions will be appreciated. This problem has bugged me for a while, and I'm sure there is a simple(ish) solution.</p>