title: How to debug "contrasts can be applied only to factors with 2 or more levels" error?
body: <p>Here are all the variables I'm working with:</p>
  
  <pre><code>str(ad.train)
  $ Date                : Factor w/ 427 levels "2012-03-24","2012-03-29",..: 4 7 12 14 19 21 24 29 31 34 ...
   $ Team                : Factor w/ 18 levels "Adelaide","Brisbane Lions",..: 1 1 1 1 1 1 1 1 1 1 ...
   $ Season              : int  2012 2012 2012 2012 2012 2012 2012 2012 2012 2012 ...
   $ Round               : Factor w/ 28 levels "EF","GF","PF",..: 5 16 21 22 23 24 25 26 27 6 ...
   $ Score               : int  137 82 84 96 110 99 122 124 49 111 ...
   $ Margin              : int  69 18 -56 46 19 5 50 69 -26 29 ...
   $ WinLoss             : Factor w/ 2 levels "0","1": 2 2 1 2 2 2 2 2 1 2 ...
   $ Opposition          : Factor w/ 18 levels "Adelaide","Brisbane Lions",..: 8 18 10 9 13 16 7 3 4 6 ...
   $ Venue               : Factor w/ 19 levels "Adelaide Oval",..: 4 7 10 7 7 13 7 6 7 15 ...
   $ Disposals           : int  406 360 304 370 359 362 365 345 324 351 ...
   $ Kicks               : int  252 215 170 225 221 218 224 230 205 215 ...
   $ Marks               : int  109 102 52 41 95 78 93 110 69 85 ...
   $ Handballs           : int  154 145 134 145 138 144 141 115 119 136 ...
   $ Goals               : int  19 11 12 13 16 15 19 19 6 17 ...
   $ Behinds             : int  19 14 9 16 11 6 7 9 12 6 ...
   $ Hitouts             : int  42 41 34 47 45 70 48 54 46 34 ...
   $ Tackles             : int  73 53 51 76 65 63 65 67 77 58 ...
   $ Rebound50s          : int  28 34 23 24 32 48 39 31 34 29 ...
   $ Inside50s           : int  73 49 49 56 61 45 47 50 49 48 ...
   $ Clearances          : int  39 33 38 52 37 43 43 48 37 52 ...
   $ Clangers            : int  47 38 44 62 49 46 32 24 31 41 ...
   $ FreesFor            : int  15 14 15 18 17 15 19 14 18 20 ...
   $ ContendedPossessions: int  152 141 149 192 138 164 148 151 160 155 ...
   $ ContestedMarks      : int  10 16 11 3 12 12 17 14 15 11 ...
   $ MarksInside50       : int  16 13 10 8 12 9 14 13 6 12 ...
   $ OnePercenters       : int  42 54 30 58 24 56 32 53 50 57 ...
   $ Bounces             : int  1 6 4 4 1 7 11 14 0 4 ...
   $ GoalAssists         : int  15 6 9 10 9 12 13 14 5 14 ...
  </code></pre>
  
  <p>Here's the glm I'm trying to fit:</p>
  
  <pre><code>ad.glm.all &lt;- glm(WinLoss ~ factor(Team) + Season  + Round + Score  + Margin + Opposition + Venue + Disposals + Kicks + Marks + Handballs + Goals + Behinds + Hitouts + Tackles + Rebound50s + Inside50s+ Clearances+ Clangers+ FreesFor + ContendedPossessions + ContestedMarks + MarksInside50 + OnePercenters + Bounces+GoalAssists, 
                    data = ad.train, family = binomial(logit))
  </code></pre>
  
  <p>I know it's a lot of variables (plan is to reduce via forward variable selection). But even know it's a lot of variables they're either int or Factor; which as I understand things should just work with a glm. However, every time I try to fit this model I get:</p>
  
  <pre><code>Error in `contrasts&lt;-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]) : contrasts can be applied only to factors with 2 or more levels
  </code></pre>
  
  <p>Which sort of looks to me as if R isn't treating my Factor variables as Factor variables for some reason?</p>
  
  <p>Even something as simple as:</p>
  
  <pre><code>ad.glm.test &lt;- glm(WinLoss ~ factor(Team), data = ad.train, family = binomial(logit))
  </code></pre>
  
  <p>isn't working! (same error message)</p>
  
  <p>Where as this:</p>
  
  <pre><code>ad.glm.test &lt;- glm(WinLoss ~ Clearances, data = ad.train, family = binomial(logit))
  </code></pre>
  
  <p>Will work!</p>
  
  <p>Anyone know what's going on here? Why can't I fit these Factor variables to my glm??</p>
  
  <p>Thanks in advance!</p>
  
  <p>-Troy</p>