[R] error: in catg (xi, name=nam, label=lab): "LO2" has <2 category levels

PIKAL Petr petr.pikal at precheza.cz
Fri Sep 7 16:21:44 CEST 2012


Hi

It is good to cc to list. Somebody could have better insight.


> 
> Dear Petr,
> 
> Thank you for responding. It seems right what you say. The funny thing
> however is that the 'LO2' variable in SPSS has 2 answer categories. If
> I look at the same variable in R, again I see 2 different values.

How do you know? Any command? You shall provide at least 

str(LO2)

result as we do not have access to your PC.

> 
> I used your "sapply" code and guess that I retrieved (per variable) the
> amount of answer categories/possible values. LO2 scores a 3 in the
> accompanying results. Do you know how I can change that?

Hm. Result of this depends on what is LO2. If it is numeric, you have 3 unique values. If it is factor you can have either 3 levels or 2 levels and NA values(again str result would be helpful and we need not just guess how your data look like). Well let me guess

levels(dat$LO2) says you have 3 levels 2 meaningful and one comes out probably as empty string "".

It shall be the first level so

levels(dat$LO2)[1] <- NA

shall drop this unused and created levels. Or maybe you can get rid of this unwanted levels by setting na.string to empty string during import, however my knowledge of SPSS limitedly approaching zero so I could be completely wrong.

If your values are factors, you can change the code to

sapply(sapply(ff, levels), length)

and you will get 0 for numeric variables and number of levels for factor variables. More complete insight in your data can be also found by 

summary(dat)

Regards
Petr


> 
> Kind regards, Tobias
> 
> 
> -----Oorspronkelijk bericht-----
> Van: PIKAL Petr [mailto:petr.pikal at precheza.cz]
> Verzonden: vrijdag 7 september 2012 15:02
> Aan: Berg, Tobias van den; r-help at r-project.org
> Onderwerp: RE: [R] error: in catg (xi, name=nam, label=lab): "LO2" has
> <2 category levels
> 
> Hi
> 
> > -----Original Message-----
> > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> > project.org] On Behalf Of Tvandenberg
> > Sent: Friday, September 07, 2012 1:05 PM
> > To: r-help at r-project.org
> > Subject: [R] error: in catg (xi, name=nam, label=lab): "LO2" has <2
> > category levels
> >
> > Dear R-users,
> >
> > During a fit procedure in a  Logistic prediction model I encounter
> the
> > following problem:
> >
> > error: in catg (xi, name=nam, label=lab: X has <2 category levels
> 
> I do not know lrm but the error seems to be explaining itself, some
> variable has only one level and shall have 2
> 
> sapply(sapply(dat, unique), length)
> 
> shall give you for used variables value 2 or more.
> 
> Regards
> Petr
> 
> 
> >
> > The following code is used:
> >
> > fit <-lrm(MRI_Diag_RC ~ factor(O4_1r) + N6_1r + leeftijd + LO1 + LO2
> +
> > LO3+
> > LO4+ LO5+ LO6+ LO7+ LO8+ LO9+ LO10+ LO11+ LO12+ LO13 + LO14+ LO15+
> > LO16+
> > LO17+ LO18+ LO19+ LO20+ LO21+ LO22+ LO23+ LO24 + LO26+ LO27 + LO29,
> > LO17+ LO18+ LO19+ LO20+ LO21+ LO22+ LO23+ model=T,
> > x=T, y=T, data=dat)
> >
> > Most predictors are (dichotomous) nominal variables as is the
> > problematic "LO2". Does anyone know what the problem is and how I can
> > correct it?
> >
> > Kind regards,
> >
> > Tobias
> >
> >
> >
> > --
> > View this message in context: http://r.789695.n4.nabble.com/error-in-
> > catg-xi-name-nam-label-lab-LO2-has-2-category-levels-tp4642495.html
> > Sent from the R help mailing list archive at Nabble.com.
> >
> > ______________________________________________
> > R-help at r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/posting-
> > guide.html and provide commented, minimal, self-contained,
> > reproducible code.




More information about the R-help mailing list