(R.1.9.1; win2000)

Since it's about the tenth time I had to write an "if" around this to catch the error ...
Let's look at the line 

	myfit<-lm(res~groupvar,data=Data)

Here res is of numeric type and groupvar is a factor. On first sight, it would be logical that if groupvar had only one (single) level we would get:

 	Error in "contrasts<-"(`*tmp*`, value = "contr.treatment") :         contrasts can be applied only to factors with 2 or more levels

But then again, it's also inconsistent: Normally redundant variables on the right of the ~ (variables which are constant or linearly dependent on previous variables) don't lead to "Error". They just get a "NA" as a coefficient estimate. A factor with a single level is of this type, it is just a constant. Obviously (to me) lm (or model.matrix.default) should not try to calculate contrasts on it and it's coefficient should be NA. Shouldn't it? 

Why is this not unimportant? Imagine you make a model of the above type for a data set with more than one level in groupvar. Then you select subsets and refit. It shouldn't die with error if you select a subset with only one level of groupvar. 

 Chris.


	[[alternative HTML version deleted]]


