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

Christoph Bier christoph.bier at web.de
Fri Nov 7 14:55:35 CET 2003


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?

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

TIA

Best regards,

Christoph

_____________________

¹ (I got help from a colleague to do this =))

v007.s <- fbhint.spss1[58:219]
v007.1.s <- fbhint.spss1[360:521]
name7.s<-names(v007.s)
name71.s<-names(v007.1.s)
bln<-length(name7.s)
for (i in 1:bln) {
v1<-name7.s[i]
   v11<-name71.s[i]
   print(paste("v1=",v1,"v11=",v11))
   d1<-fb.12.hint[[v1]]
   d2<-fb.12.hint[[v11]]
res<-chisq.test(d1,d2)
print(res)
}


-- 
Christoph Bier, Dipl.Oecotroph., Email: bier at wiz.uni-kassel.de
Universitaet Kassel, FG Oekologische Lebensmittelqualitaet und
Ernaehrungskultur \\ Postfach 12 52 \\ 37202 Witzenhausen
Tel.: +49 (0) 55 42 / 98 -17 21, Fax: -17 13




More information about the R-help mailing list