[R] Help with lm with a nested effect

Timothy Clough tclough at purdue.edu
Fri Sep 18 03:22:03 CEST 2009


Dear All,

I am running an ANOVA model with three factors: FEATURE (3 levels),  
GROUP (5 levels), and PATIENT (2 levels), where PATIENT is nested  
within GROUP.

fit <- lm(ABUNDANCE ~ FEATURE + GROUP + FEATURE:GROUP + GROUP/PATIENT,  
example)

However, the design is not balanced:  PATIENT1 in GROUP1 is missing,  
and when I run summary(fit), I receive the following output.

Call:
lm(formula = ABUNDANCE ~ FEATURE + GROUP + FEATURE:GROUP + GROUP/ 
PATIENT,
     data = example)

Residuals:
        Min         1Q     Median         3Q        Max
-3.569e-01 -1.048e-01  1.479e-17  1.048e-01  3.569e-01

Coefficients: (1 not defined because of singularities)
                      Estimate Std. Error  t value Pr(>|t|)
(Intercept)        13.4542954  0.2790175   48.220 3.78e-11 ***
FEATURE4227        -0.9393679  0.3417252   -2.749   0.0251 *
FEATURE6374         0.1260711  0.3417252    0.369   0.7218
GROUP1              0.0020501  0.4411653    0.005   0.9964
GROUP2              0.0992019  0.3945903    0.251   0.8078
GROUP3              0.0823760  0.3945903    0.209   0.8399
GROUP4             -0.0062425  0.3945903   -0.016   0.9878
FEATURE4227:GROUP1 -0.2178760  0.5918854   -0.368   0.7223
FEATURE6374:GROUP1 -0.1109533  0.5918854   -0.187   0.8560
FEATURE4227:GROUP2  0.0001341  0.4832724 0.000278   0.9998
FEATURE6374:GROUP2  0.2720569  0.4832724    0.563   0.5889
FEATURE4227:GROUP3  0.3848577  0.4832724    0.796   0.4488
FEATURE6374:GROUP3  0.1829045  0.4832724    0.378   0.7149
FEATURE4227:GROUP4 -0.7113272  0.4832724   -1.472   0.1793
FEATURE6374:GROUP4 -0.1151362  0.4832724   -0.238   0.8177
GROUP0:PATIENT2     0.1264295  0.2790175    0.453   0.6625
GROUP1:PATIENT2            NA         NA       NA       NA
GROUP2:PATIENT2    -0.2636043  0.2790175   -0.945   0.3724
GROUP3:PATIENT2     0.0429295  0.2790175    0.154   0.8815
GROUP4:PATIENT2     0.5981179  0.2790175    2.144   0.0644 .
---


As you can see, the estimate for GROUP1:PATIENT2 is NA because of the  
missing values from PATIENT1 in GROUP1.

This becomes a problem when I want to estimate contrasts, as the  
estimable function gives me an error.

Is there a way to get around this?  When running the same model in  
SAS, instead of an NA there is simply a 0 for that level, and  
contrasts have no problem being estimated.

Sincerely,
Tim




More information about the R-help mailing list