title: Error in model.frame.default(Terms, newdata, na.action = na.action, xlev = object$xlevels): factor X has new levels
body: <p>I did a logistic regression: </p>
  
  <pre><code> EW &lt;- glm(everwrk~age_p + r_maritl, data = NH11, family = "binomial")
  </code></pre>
  
  <p>Moreover, I want to predict <code>everwrk</code> for each level of <code>r_maritl</code>.</p>
  
  <p><code>r_maritl</code> has the following levels:</p>
  
  <pre><code>levels(NH11$r_maritl)
   "0 Under 14 years" 
   "1 Married - spouse in household" 
   "2 Married - spouse not in household"
   "3 Married - spouse in household unknown" 
   "4 Widowed"                               
   "5 Divorced"                             
   "6 Separated"                             
   "7 Never married"                        
   "8 Living with partner"  
   "9 Unknown marital status"  
  </code></pre>
  
  <p>So I did:</p>
  
  <pre><code>predEW &lt;- with(NH11,
  expand.grid(r_maritl = c( "0 Under 14 years", "1 Married - 
  spouse in household", "2 Married - spouse not in household", "3 Married - 
  spouse in household unknown", "4 Widowed", "5 Divorced", "6 Separated", "7 
  Never married", "8 Living with partner", "9 Unknown marital status"),
  age_p = mean(age_p,na.rm = TRUE)))
  
  cbind(predEW, predict(EW, type = "response",
                          se.fit = TRUE, interval = "confidence",
                          newdata = predEW))
  </code></pre>
  
  <p>The Problem is I get the following response:</p>
  
  <blockquote>
    <p>Error in model.frame.default(Terms, newdata, na.action = na.action, xlev = 
      object$xlevels) : factor r_maritl has new levels 0 Under 14 years, Married 
        - spouse in household unknown</p>
  </blockquote>
  
  <p>Sample Data:</p>
  
  <pre><code>str(NH11$age_p)
  num [1:33014] 47 18 79 51 43 41 21 20 33 56 ...
  
  str(NH11$everwrk)
  Factor w/ 2 levels "2 No","1 Yes": NA NA 2 NA NA NA NA NA 2 2 ...
  
  str(NH11$r_maritl)
  Factor w/ 10 levels "0 Under 14 years",..: 6 8 5 7 2 2 8 8 8 2 ...
  </code></pre>