[R] "Error in contrasts" in step wise regression

From: Young Cho <iidn01_at_yahoo.com>
Date: Sat 25 Jun 2005 - 07:19:52 EST


Hi,  

I have a problem in getting step function work. I am getting the following error:  

> fit1 <- lm(Response~1)
> fmla <- as.formula(paste(" ~ ",paste(colnames,collapse="+")))
> sfit <- step(fit1,scope=list(upper= fmla,lower= ~1),k=log(nrow(dat)))
Start: AIC= -1646.66
 Response ~ 1
Error in "contrasts<-"(`*tmp*`, value = "contr.treatment") :

        contrasts can be applied only to factors with 2 or more levels

But if i count the unique values in each column by

A <- NULL
for (ii in 1:length(colnames)){

        A[ii] <- length(unique( eval(parse(text=paste('dat$',colnames[ii]))))) }  

I do not see any column with only 1 value. Is there some other possible reason why I am getting the error? Thanks a lot!  

Young.  


        [[alternative HTML version deleted]]



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Sat Jun 25 07:23:33 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:33:02 EST