[R] Odd anova(lm()) order phenomenon, looking for an explanation

Andrew Robinson A.Robinson at ms.unimelb.edu.au
Mon Apr 3 13:06:31 CEST 2006


Thanks to Berwin and Peter for their replies.  The following code
clarifies what's going on in Peter's example.  I shall upodate my
intuition!

x1 <- runif(100,8,10)
x2 <- x1^2

y <- (x1-9)^2+rnorm(100,sd=.1)

opar <- par(mfrow=c(2,2), las=1)
plot(x1, y, main="x1 Only")
plot(residuals(lm(x1~x2)), residuals(lm(y~x2)),
     main="Added-Variable Plot for x1")
plot(x2, y, main="x2 Only")
plot(residuals(lm(x2~x1)), residuals(lm(y~x1)),
     main="Added-Variable Plot for x2")
par(opar)

## Using Lattice graphics

require(lattice)

cloud(y ~ x1 * x2)

## Using RGL graphics (with brute force scaling)

require(rgl)

rgl.clear("all")
rgl.bg(sphere = TRUE, color = c("black", "green"),
       lit = FALSE, size=2, alpha=0.2, back = "lines")
rgl.light()
rgl.bbox()

x1 <- runif(100,8,10) * 10
x2 <- (x1/10)^2

esty <- ((x1/10-9)^2 + rnorm(100,sd=.1)) * 20

rgl.spheres(x1, esty, x2,
            color="gray", radius=0.5,
            specular="green",
            texture=system.file("textures/bump_dust.png",package="rgl"),
            texmipmap=T, texminfilter="linear.mipmap.linear")

Cheers

Andrew



On Fri, Mar 31, 2006 at 12:09:14PM +0200, Peter Dalgaard wrote:
> Berwin A Turlach <berwin at maths.uwa.edu.au> writes:
> 
> > Don't know if the following example, which shows the same behaviour,
> > leads to any insight. 
> > 
> > > n <- 100
> > > x1 <- runif(n, -1,1)
> > > x2 <- runif(n, -1,1)
> > > y <- x1*x1*x2 + rnorm(n, sd=0.05)
> > > y <- y - mean(y)
> > > anova(lm(y~x1+x2))
> 
> Here's another (paraphrased from the Pixel data in nlme, which have
> similar behaviour)
> 
> x1 <- runif(100,8,10)
> x2 <- x1^2
> y <- (x1 - 9)^2 + rnorm(100, sd=.1)
> plot(x1, y)
> anova(lm(y ~ x1 + x2))
> anova(lm(y ~ x2 + x1))
> summary(lm(y ~ x1))
> summary(lm(y ~ x2))
> summary(lm(y ~ x1 + x2))
> 
> 
> -- 
>    O__  ---- Peter Dalgaard             ?ster Farimagsgade 5, Entr.B
>   c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
>  (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
> ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)                  FAX: (+45) 35327907

-- 
Andrew Robinson  
Department of Mathematics and Statistics            Tel: +61-3-8344-9763
University of Melbourne, VIC 3010 Australia         Fax: +61-3-8344-4599
Email: a.robinson at ms.unimelb.edu.au         http://www.ms.unimelb.edu.au




More information about the R-help mailing list