Dear All,
I am writing to ask a clarification on what R, and in particular lme, is
doing.
I have an experiment where fly wing area was measured in 4 selection lines,
measured at 18 and 25 degrees. I am using a lme model because I have three
replicated per line (coded 1:12 so I need not use getGroups to creat an
orederd factor).
The lines are called: "18"; "25"; "l";
"s". My data looks like:
temp line replicate area
1 25 l 3 92693
2 25 l 3 100092
3 25 l 3 100039
4 25 l 3 97558
5 25 l 3 95603
6 25 l 3 100482
.....
"18" and "25" are controls for the two other lines so I have
set the
following contrasts for lines:
[,1] [,2] [,3]
18 1 0 1
25 -1 0 1
l 0 1 -1
s 0 -1 -1
If I do the following:
mod1<-lme(area ~ line * temp, random = ~1|replicate/temp, mydata)
anova(mod1)
I get:
numDF denDF F-value p-value
(Intercept) 1 336 41817.83 <.0001
line 3 8 14.38 0.0014
temp 1 8 338.21 <.0001
line:temp 3 8 0.62 0.6211
I have a significant effect of selection line. Eyeballing the
interction.plot, it is clear the the line called "25" is smaller at
both
temperatures than the other lines.
but when I check the contrasts with summary(mod1) I get:
Fixed effects: area ~ line * temp
Value Std.Error DF t-value p-value
(Intercept) 165417.32 3102.751 336 53.31312 <.0001
line1 2631.71 4387.952 8 0.59976 0.5653
line2 -2603.27 4387.952 8 -0.59328 0.5694
line3 -4667.61 3102.751 8 -1.50435 0.1709
temp -2614.39 142.160 8 -18.39045 <.0001
line1:temp 96.39 201.045 8 0.47946 0.6444
line2:temp 95.74 201.045 8 0.47623 0.6466
line3:temp 168.55 142.160 8 1.18561 0.2698
There seems to be no difference in my lines, according to the contrasts I set!
I tried to do the same analysis using temperature as an orderd factor:
mod2<-lme(area ~ line * ordered(temp), random = ~1|replicate/ordered(temp),
mydata)
anova(mod2)
numDF denDF F-value p-value
(Intercept) 1 336 41817.83 <.0001
line 3 8 14.38 0.0014
ordered(temp) 1 8 338.21 <.0001
line:ordered(temp) 3 8 0.62 0.6211
the same anova, but the contrasts are :
Fixed effects: area ~ line * ordered(temp)
Value Std.Error DF t-value p-value
(Intercept) 109207.89 534.0393 336 204.49409 <.0001
line1 4704.14 755.2457 8 6.22862 0.0003
line2 -544.76 755.2457 8 -0.72130 0.4913
line3 -1043.87 534.0393 8 -1.95467 0.0864
ordered(temp).L -12940.58 703.6576 8 -18.39045 <.0001
line1:ordered(temp).L 477.12 995.1221 8 0.47946 0.6444
line2:ordered(temp).L 473.91 995.1221 8 0.47623 0.6466
line3:ordered(temp).L 834.26 703.6576 8 1.18561 0.2698
way different from the previous model. This time the "18" and
"25" lines
are different!
As I do not want to specify a model thinking I am doing something when I am
not, I would like to ask you why the difference in the results?
the fact that my continuous variable, temperature, is rapresented by two
integers, 18 or 25, can cause the difference? assuming I were interested in
the interaction between my contrasts and temperature, to asses differences
in the slope between treatments, what should I do?
Again, I ask this in order to properly understand what lme is doing so I
can go back to work and specify the model I want rather than something else
altogether.
Regards,
Federico Calboli
========================
Federico C.F. Calboli
Department of Biology
University College London
Room 327
Darwin Building
Gower Street
London
WClE 6BT
Tel: (+44) 020 7679 4395
Fax (+44) 020 7679 7096
f.calboli at ucl.ac.uk
Your anova call is a sequential anova, which you are misinterpreting. You can't conclude terms are significant or not if later terms are. You need to use type="marginal" to interpret things the way you do (except that I hope that does not drop the main effect and keep the interaction). You also seem to be interpreting main effects in the presence of interactions incorrectly. In your first model the coefs for `line' are intercepts at 0 temp (probably uninteresting) whereas in the second they are at intercepts at temp=21.5 (probably also uninteresting). It makes perfect sense to have lines of different slopes with similar intercepts at 0 but different ones at 21.5. Perhaps it is `temp' you want to think hard about how to code? On Sun, 27 Jul 2003, Federico Calboli wrote:> I am writing to ask a clarification on what R, and in particular lme, is > doing.Actually, it is the user who tells R what to do, and it does as it is told. What you are asking is what the language you used means.> I have an experiment where fly wing area was measured in 4 selection lines, > measured at 18 and 25 degrees. I am using a lme model because I have three > replicated per line (coded 1:12 so I need not use getGroups to creat an > orederd factor). > > The lines are called: "18"; "25"; "l"; "s". My data looks like: > > temp line replicate area > 1 25 l 3 92693 > 2 25 l 3 100092 > 3 25 l 3 100039 > 4 25 l 3 97558 > 5 25 l 3 95603 > 6 25 l 3 100482 > ..... > > "18" and "25" are controls for the two other lines so I have set the > following contrasts for lines: > > [,1] [,2] [,3] > 18 1 0 1 > 25 -1 0 1 > l 0 1 -1 > s 0 -1 -1 > > If I do the following: > > mod1<-lme(area ~ line * temp, random = ~1|replicate/temp, mydata) > anova(mod1) > > I get: > > numDF denDF F-value p-value > (Intercept) 1 336 41817.83 <.0001 > line 3 8 14.38 0.0014 > temp 1 8 338.21 <.0001 > line:temp 3 8 0.62 0.6211 > > > I have a significant effect of selection line. Eyeballing the > interction.plot, it is clear the the line called "25" is smaller at both > temperatures than the other lines. > > but when I check the contrasts with summary(mod1) I get: > > Fixed effects: area ~ line * temp > Value Std.Error DF t-value p-value > (Intercept) 165417.32 3102.751 336 53.31312 <.0001 > line1 2631.71 4387.952 8 0.59976 0.5653 > line2 -2603.27 4387.952 8 -0.59328 0.5694 > line3 -4667.61 3102.751 8 -1.50435 0.1709 > temp -2614.39 142.160 8 -18.39045 <.0001 > line1:temp 96.39 201.045 8 0.47946 0.6444 > line2:temp 95.74 201.045 8 0.47623 0.6466 > line3:temp 168.55 142.160 8 1.18561 0.2698 > > There seems to be no difference in my lines, according to the contrasts I set! > > I tried to do the same analysis using temperature as an orderd factor: > > mod2<-lme(area ~ line * ordered(temp), random = ~1|replicate/ordered(temp), > mydata) > anova(mod2) > > numDF denDF F-value p-value > (Intercept) 1 336 41817.83 <.0001 > line 3 8 14.38 0.0014 > ordered(temp) 1 8 338.21 <.0001 > line:ordered(temp) 3 8 0.62 0.6211 > > the same anova, but the contrasts are : > > Fixed effects: area ~ line * ordered(temp) > Value Std.Error DF t-value p-value > (Intercept) 109207.89 534.0393 336 204.49409 <.0001 > line1 4704.14 755.2457 8 6.22862 0.0003 > line2 -544.76 755.2457 8 -0.72130 0.4913 > line3 -1043.87 534.0393 8 -1.95467 0.0864 > ordered(temp).L -12940.58 703.6576 8 -18.39045 <.0001 > line1:ordered(temp).L 477.12 995.1221 8 0.47946 0.6444 > line2:ordered(temp).L 473.91 995.1221 8 0.47623 0.6466 > line3:ordered(temp).L 834.26 703.6576 8 1.18561 0.2698 > > way different from the previous model. This time the "18" and "25" lines > are different!Yes, as the interpretation is different.> As I do not want to specify a model thinking I am doing something when I am > not, I would like to ask you why the difference in the results? > > the fact that my continuous variable, temperature, is rapresented by two > integers, 18 or 25, can cause the difference? assuming I were interested in > the interaction between my contrasts and temperature, to asses differences > in the slope between treatments, what should I do?Code treatment sensibly, as a factor. What is sensible depends on your subject's context.> Again, I ask this in order to properly understand what lme is doing so I > can go back to work and specify the model I want rather than something else > altogether.Almost nothing to do with lme, only with linear-model coding. Please read thoroughly e.g. the appropriate chapters of MASS so you understand coding. -- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
At 14:14 27/07/2003 +0100, you wrote:>Your anova call is a sequential anova, which you are misinterpreting. >You can't conclude terms are significant or not if later terms are. >You need to use type="marginal" to interpret things the way you do (except >that I hope that does not drop the main effect and keep the interaction). > >You also seem to be interpreting main effects in the presence of >interactions incorrectly. In your first model the coefs for `line' are >intercepts at 0 temp (probably uninteresting) whereas in the second they >are at intercepts at temp=21.5 (probably also uninteresting). It makes >perfect sense to have lines of different slopes with similar intercepts at >0 but different ones at 21.5. > >Perhaps it is `temp' you want to think hard about how to code?Prof. Ripley, many thanks for your reply. I coded temperature as a factor and imposed the contrasts: [,1] 18 1 25 -1 After doing this, the results of anova() are the following: anova(lme(area ~line*temp, random= ~ 1|replicate/temp, mydata), type="m") numDF denDF F-value p-value (Intercept) 1 336 41817.83 <.0001 line 3 8 14.38 0.0014 temp 1 8 338.21 <.0001 line:temp 3 8 0.62 0.6211 which, incidentally, are identical to the call: anova(lme(area ~line*temp, random= ~ 1|replicate/temp, mydata)) numDF denDF F-value p-value (Intercept) 1 336 41817.83 <.0001 line 3 8 14.38 0.0014 temp 1 8 338.21 <.0001 line:temp 3 8 0.62 0.6211 as my data is perfectly balanced (at lest I think this is the most plausible explanation). The contrasts read: Value Std.Error DF t-value p-value (Intercept) 109207.89 534.0393 336 204.49409 <.0001 line1 4704.14 755.2457 8 6.22862 0.0003 line2 -544.76 755.2457 8 -0.72130 0.4913 line3 -1043.87 534.0393 8 -1.95467 0.0864 temp1 9150.37 497.5610 8 18.39045 <.0001 line1:temp1 -337.37 703.6576 8 -0.47946 0.6444 line2:temp1 -335.11 703.6576 8 -0.47623 0.6466 line3:temp1 -589.91 497.5610 8 -1.18561 0.2698 which is what I would expect from eyeballing the interaction.plot. I imagine I could come up with a better model, but I still need more pondering over chpt 6 of MASS. Nonetheless I think I have a better grasp of what I am doing now. Regards, Federico Calboli ======================== Federico C.F. Calboli Department of Biology University College London Room 327 Darwin Building Gower Street London WClE 6BT Tel: (+44) 020 7679 4395 Fax (+44) 020 7679 7096 f.calboli at ucl.ac.uk