[R] [HH] extending ancova function for 2 factors

Patrick Drechsler patrick at pdrechsler.de
Fri Mar 30 00:22:55 CEST 2007


Hi,

what would be a good way of enhancing the ancova function from the HH
package when using a 2 factor ANCOVA?

The current behaviour for the "ancova" function from package HH is:

----------------------------------------------
|  P1  || P1   || P3   || P4   |   | PS      | <- the lattice strip
----------------------------------------------
|     x||    x ||x     ||x     |   |         |
|  x   ||x     || x    ||  x   |   |superimp.| <- the lattice plot
|x     ||  x   ||   x  ||    x |   |         |
----------------------------------------------

P1:P4 :   Show an xy-plot for each factor level of the covariate P.
PS:       Displays the previous plots superimposed
superimp: P1:P4 superimposed

I would like to use this function for a two factor design.

-------------------------------------------------
|  Q1  || Q1   || Q1   || Q1   |   | PS.Pi      | <- strip1
------------------------------------------------- 
|  P1  || P1   || P3   || P4   |   | PS.Pi      | <- strip2
-------------------------------------------------
|x     ||  x   ||   x  ||    x |   |            |
|x     ||  x   ||   x  ||    x |   |            | <- plot
|x     ||  x   ||   x  ||    x |   |            |
-------------------------------------------------

-------------------------------------------------
|  Q2  || Q2   || Q2   || Q2   |   | PS.Pi      | <- strip1
------------------------------------------------- 
|  P1  || P1   || P3   || P4   |   | PS.Pi      | <- strip2
-------------------------------------------------
|x     ||  x   ||   x  ||    x |   |            |
|x     ||  x   ||   x  ||    x |   |            | <- plot
|x     ||  x   ||   x  ||    x |   |            |
-------------------------------------------------

[...]

-------------------------------------------------
|  Q5  || Q5   || Q5   || Q5   |   | PS.Pi      | <- strip1
------------------------------------------------- 
|  P1  || P1   || P3   || P4   |   | PS.Pi      | <- strip2
-------------------------------------------------
|x     ||  x   ||   x  ||    x |   |            |
|x     ||  x   ||   x  ||    x |   |            | <- plot
|x     ||  x   ||   x  ||    x |   |            |
-------------------------------------------------


Here is an example:

--8<---------------cut here---------------start------------->8---
rm(list = ls(all = TRUE))
rm(list = c(ls()))

library(lattice)
library(HH)

## 1. generate data
random <- rnorm(200)
y <- abs(random)
x1.cont <- abs(random)
x2.fac <- as.factor(rep(1:5, 4))     # 4 groups
x3.fac <- as.factor(rep(1:4, each=5))# 5 groups
A <- data.frame(y, x1.cont, x2.fac, x2.fac)

## 2. plot trellis plot:
foo <- xyplot(log(y) ~ log(x1.cont) | x2.fac * x3.fac,
              data = A,
              type = c("p","r"),
              strip = strip.custom(strip.names=TRUE),
              as.table=TRUE)

plot(foo)

## 3. plot "ancova" plot using HH:
## normal usage:
ancova(y ~ x1.cont * x2.fac)

## 4. Trying to combine "ancova" with trellis:
## does not work:
ancova(y ~ x1.cont * x2.fac * x3.fac)
--8<---------------cut here---------------end--------------->8---

-- 
Patrick Drechsler
Department of Zoology
University of Cambridge
Downing Street
Cambridge CB2 3EJ, UK



More information about the R-help mailing list