[R] using lm with nested factor results in NA's

Timothy Clough tclough at purdue.edu
Mon Sep 14 20:27:41 CEST 2009


Dear All,

I am attempting to perform an ANOVA with three factors:  feature (3  
levels), group (5 levels), and patient (246 levels), where patient is  
nested within group.

I am using the following command:

fit <- lm(intensity ~ feature + group + feature:group + group/patient,  
data = new)

When using summary(fit), there are many parameter estimates of patient  
within group with NA values, and I receive this message:   
"Coefficients: (984 not defined because of singularities)".

My understanding is that this is because each patient only occurs  
within a single level of group.   But when I use the estimable  
function to estimate contrasts that involve certain patients, I get  
errors such as:

Error in estimable.default(fit, cm) :
  Dimension of structure(c(1, 0, 1, 0, 0, 0, 0.5, 0, 0, 0, 0, 0, 0, 0,  
0, 0, : 1x1235, not compatible with no of parameters in fit: 251

I'm wondering if the NA's are to be expected, and if so, how to  
perform contrasts involving levels of patient in the presence of the  
NA's.

Any help is appreciated,

Tim




More information about the R-help mailing list