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

Marc Schwartz MSchwartz at medanalytics.com
Fri Nov 7 15:32:43 CET 2003


On Fri, 2003-11-07 at 07:55, Christoph Bier wrote:
> Hi,
> 
> I use a little script¹ to make a chi-square-test on 162 
> factors (it makes no difference if I take the numeric variant 
> of the factors). At factor nr. 4 is stops with an error:
> 
> [1] "v1= V7.KARTM v11= V7.KAR1M"
> Error in chisq.test(d1, d2) : x and y must have at least 2 levels
> 
> But x and y /have/ two levels ("nein", "ja"):
> 
>  > fbhint.spss1$V7.KARTM
>   [1] nein nein nein nein nein nein nein nein nein nein nein 
> nein nein nein nein
> [16] nein nein nein nein nein nein nein nein nein nein nein 
> nein nein nein nein
> [31] nein nein nein nein nein nein nein nein nein nein nein 
> nein nein nein nein
> [46] nein nein nein nein
> Levels: nein ja
> 
>  > fbhint.spss1$V7.KAR1M
>   [1] nein nein nein nein nein nein nein nein nein nein nein 
> nein nein nein nein
> [16] nein <NA> nein nein nein nein nein nein nein nein nein 
> nein <NA> nein <NA>
> [31] nein nein nein nein nein nein nein nein nein nein nein 
> nein <NA> <NA> nein
> [46] <NA> nein nein <NA>
> Levels: nein ja
> 
> Or is there another meaning of 'levels' that doesn't 
> correspond to the one returned above?
>     Any hints what's going wrong/which mistake(s) I make?

'levels' indicates how many levels are defined for the factor. However,
it is possible that the actual data present may contain only a subset of
the levels.

In this case, your factors contain defined levels for both "ja" and
"nein", however in the subset of data that you are analyzing, only
"nein" appears (and of course NA in the second, though NA is not defined
as a level).

Hence that particular cross-tabulation of factors contains one level
each, yielding a table with a single cell.

Presumably, your original dataset contains both values prior to
subsetting.

See ?factor and ?levels for more information.

> BTW to the german speaking readers: What's the R pendant to or 
> translation for "Konfigurationsfrequenzanalyse (KFA)"?
> 

I am not a German speaker, however:

Analysis of Configuration Frequencies (CFA)?

There is a package 'cfa' on CRAN.

HTH,

Marc Schwartz




More information about the R-help mailing list