[R] Contrast specified with C() - R vs S-Plus problem

Pascal A. Niklaus Pascal.Niklaus at unibas.ch
Wed Oct 8 14:19:16 CEST 2003


Hi,

For a n-level factor, I'd like to specify the first contrast and have
the remaining n-2 constructed automatically so that the set is
orthogonal. I then test the contrasts with summary.lm(anova-object).

In S-Plus, the following works:

    >y.anova <- aov( y ~ C(CO2,c(1,0,-1)) )
    >summary.lm(y.anova)

In R, it fails with the following error:

    >levels(CO2)
    [1] ""  "A" "C" "E"

    >y.anova <- aov(y + C(CO2,c(1,0,-1)) )
    Error in "contrasts<-"(*tmp*, value = contr) :
            wrong number of contrast matrix rows

What is the way to do this in R?

Thanks

Pascal

--


Dr. Pascal A. Niklaus
Institute of Botany
University of Basel
Schönbeinstrasse 6
CH-4056 Basel / Switzerland




More information about the R-help mailing list