[R] chisq.test error: x and y must have at least 2 levels

Thomas Lumley tlumley at u.washington.edu
Fri Nov 7 17:19:52 CET 2003

On Fri, 7 Nov 2003, Christoph Bier wrote:

> Peter Dalgaard wrote:
> > Well, the error message might be slightly beside the point, but the
> > issue would seem to be that there are no "ja"'s inside either vector.
> > I.e. it first reduces each factor to those levels that are actually
> > present, then checks whether there are at least two levels.
> Thanks for this explanation.
> > You can't do a chisquare test on a table that looks like this
> >
> >       nein   ja
> > nein    42    0
> >   ja     0    0
> >
> Hm, and now? There is data like this and I need to do a chisquare
> test. Spencer's answer seems to be the solution.
>     Is my data that uncommon, that chisq.test hasn't a built-in
> function to avoid this error?

It's not that your data are uncommon.  Your data contain no information
about whether `ja' answers tend to occur together for the two variables,
because there no `ja' answers.


More information about the R-help mailing list