Error with svychisq - 'contrast can be applied to factors with 2 or more levels'
<p>Error in <code>contrasts&lt;-</code>(<code>*tmp*</code>, value = contr.funs[1 + isOF[nn]]) : 
  contrasts can be applied only to factors with 2 or more levels</p>

<p>I'm getting this error whenever I try using the svychisq function in the survey package. However the function works when I use the svytable function. The error talks about a factor with 2 or more level - the DIED variable is a factor with 2 levels, 0 and 1. </p>

<pre><code>&gt; svytable(~COHORT+DIED, design=df_srvy)

  DIED
COHORT         0         1
  1997 26726.584  1647.118
  2000 26958.912  1628.692
  2003 30248.533  1599.094
  2006 36602.173  1586.526
  2009 44004.732  2531.597
  2012 56037.874  2766.386

&gt; svychisq(~COHORT+DIED, design=df_srvy)
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>EDIT:</p>

<p>Here's a small subset example of the problem </p>

<pre><code>sample &lt;- structure(list(DISCWT = c(1.36973, 1.4144, 1.41222, 1.41222, 
1.4144, 1.4144, 1.41222, 1.41222, 1.4144, 1.41222, 1.41222, 1.41222, 
1.41222, 1.4144, 1.4144), COHORT = c(1997L, 2012L, 2000L, 2003L, 
2006L, 2006L, 2009L, 2012L, 2012L, 1997L, 2003L, 2006L, 2006L, 
2003L, 1997L), DIED = c(1L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 1L, 
0L, 0L, 0L, 0L, 1L)), row.names = c(NA, -15L), class = c("tbl_df", 
"tbl", "data.frame"), .Names = c("DISCWT", "COHORT", "DIED"))

sample_survey &lt;- sample %&gt;% as_survey_design(., weight = DISCWT)

svychisq(~DIED+COHORT, sample_survey)
</code></pre>