title: Subsetting Categorical Covariate of Regression in R
body: <p>I am attempting to subset a categorical covariate entitled "Public" that has two levels (0 and 1) within my regression model. I would like to look at how this covariate influences my regression curves' mean and dispersion values by subsetting when model to "1". Unfortunately I am getting an error that says:</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>My data is in a dataframe entitled "erad.surv" and looks as such:</p>
  
  <pre><code>    Surv(Erad_Time, Event)        Dist Public (weights)
  1                       12 -0.51385627      1         1
  2                      39+  0.65870948      1         1
  3                      39+  0.47563451      0         1
  4                      39+  0.73255621      1         1
  5                      39+  0.32500333      1         1
  6                      39+ -0.60323102      1         1
  7                       31  0.60391220      1         1
  
  </code></pre>
  
  <p>Finally, my regression model is the one provided below. I've also tried seemingly every other combination of the "subset" command to no avail.</p>
  
  <pre><code>model.Public &lt;- flexsurvreg(formula = Surv(Erad_Time, Event) ~ Dist + Public, data = erad.surv, subset = (Public == "1"), dist=ig)
  </code></pre>
  
  <p>Any thoughts or help would be greatly appreciated!</p>