[Rd] But in add1, presumably in add1.lm (PR#7842)

ripley at stats.ox.ac.uk ripley at stats.ox.ac.uk
Fri May 6 11:55:52 CEST 2005


The problem is in the way terms() reorders interactions in forming the 
term labels.  If asked to fit  ~ Age + Eth + Eth:Age it actually fits
~ Age + Eth + Age:Eth

It is not clear to me why R does this (S does not) nor if it is safe to 
change that, but it would be better to fix the root cause if possible as 
it occurs in several places.  In particular, it affects all known add1 
methods and can affect drop1 too.

If used consistently, there is a no problem: here your upper scope does 
not (strictly) include your lower model.

On Fri, 6 May 2005 berwin at maths.uwa.edu.au wrote:

> xDear all,
>
> while investigating some data, I noticed a strange behaviour of add1
> which is reproduced below using a data set from a recommended
> package.
>
> Essentially, it seems the inclusion of an interaction term by add1 is
> only correctly handled if the order of the variables in the
> interaction coincide with the order in the formula that is given as
> the scope.  (I have a vague memory that such a bug was already once
> posted some time ago, but could not find anything in the bug report
> repository.)
>
> I noticed this problem on R 2.1.0, but it also exists in all other R
> version installed on my machine (R 1.8.1, R 1.9.1, R 2.0.0 and R
> 2.0.1).
>
> Cheers,
>
>        Berwin
>
>> library(MASS)
>> fmb <- lm(Days ~ .^4, quine)
>
>> fm0 <- lm(Days ~ Eth + Sex, quine)
>> add1(fm0, formula(fmb), test="F")
> Single term additions
>
> Model:
> Days ~ Eth + Sex
>        Df Sum of Sq   RSS   AIC F value   Pr(F)
> <none>               35045   806
> Age      3      2119 32926   803  3.0030 0.03263
> Lrn      1       162 34882   808  0.6605 0.41773
> Eth:Sex  1       141 34904   808  0.5724 0.45057
>
>> fm0 <- lm(Days ~ Sex + Eth, quine)
>> add1(fm0, formula(fmb), test="F")
> Single term additions
>
> Model:
> Days ~ Sex + Eth
>        Df Sum of Sq   RSS   AIC F value   Pr(F)
> <none>               35045   806
> Age      3      2119 32926   803  3.0030 0.03263
> Lrn      1       162 34882   808  0.6605 0.41773
> Eth:Sex  0         0 35045   806
>
>> fm0 <- lm(Days ~ Age + Eth, quine)
>> add1(fm0, formula(fmb), test="F")
> Single term additions
>
> Model:
> Days ~ Age + Eth
>        Df Sum of Sq   RSS   AIC F value  Pr(F)
> <none>               33049   802
> Sex      1       123 32926   803  0.5226 0.4710
> Lrn      1       598 32450   801  2.5815 0.1104
> Eth:Age  0         0 33049   802
>
>> fm0 <- lm(Days ~Eth + Age , quine)
>> add1(fm0, formula(fmb), test="F")
> Single term additions
>
> Model:
> Days ~ Eth + Age
>        Df Sum of Sq   RSS   AIC F value    Pr(F)
> <none>               33049   802
> Sex      1       123 32926   803  0.5226 0.470950
> Lrn      1       598 32450   801  2.5815 0.110369
> Eth:Age  3      2837 30212   795  4.3194 0.006047
>
> --please do not edit the information below--
>
> Version:
> platform = i686-pc-linux-gnu
> arch = i686
> os = linux-gnu
> system = i686, linux-gnu
> status =
> major = 2
> minor = 1.0
> year = 2005
> month = 04
> day = 18
> language = R
>
> Search Path:
> .GlobalEnv, package:methods, package:stats, package:graphics, package:grDevices, package:utils, package:datasets, Autoloads, package:base
>
> ______________________________________________
> R-devel at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>
>

-- 
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



More information about the R-devel mailing list