[R] help with 'lm' function: contrast and separate variance terms

Timothy Clough tclough at purdue.edu
Tue Sep 8 20:47:57 CEST 2009


Dear All,

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

Currently I am using the "lm" function to fit the model, with the  
following form:

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

I have two questions:

1.  I'd like to use a contrast to estimate a model-based average  
intensity for a particular patient.  In my attempts to do this so far,  
I've tried to use the "estimable" function, but I've found that I  
would need to specify a value ('0' or '1') for each level of patient.   
Since there are 246 patients, this is time consuming and requires a  
long piece of code.  Do you recommend an R function that might  
accomplish this task more efficiently than "estimable"?

2.  I'd also like to specify a separate error variance for each level  
of feature.  I've read documentation on several functions, and it  
seems like I might need to use the "weights" command within the "lme"  
function for this.  However, I have no random effects (even though  
patient might be considered random I'd prefer to keep it fixed for  
now) and running lme gives me an error:  "Invalid formula for  
groups".  Is there a more appropriate function to be using that will  
easily allow for feature-specific error variances?

Any advice is appreciated,

Tim




More information about the R-help mailing list