[R] Contrast specified with C() - R vs S-Plus problem
Prof Brian Ripley
ripley at stats.ox.ac.uk
Wed Oct 8 16:35:03 CEST 2003
On Wed, 8 Oct 2003, Pascal A. Niklaus wrote:
> Thanks for the reply. Below is the solution and the S-Plus and R code
> that does the same (for documentation).
>
> >I can't reproduce that in S-PLUS 6.1, and it is not as documented:
> >
> >
> In S-Plus 2000, C() complements the contrast matrix with orthogonal
> contrasts if only the first is given.
And so does R. You just did not specify it correctly in R. The code you
quote works in R as well, but your original example had four levels, not
three.
> CO2 <- factor(rep(c("A","C","E"),each=8))
> m <- rep(seq(0,3,length=8),3) + rep(c(0,1,2),each=8)
> summary.aov(aov(m ~ C(CO2,c(1,0,-1))))
Df Sum Sq Mean Sq F value Pr(>F)
C(CO2, c(1, 0, -1)) 2 16.000 8.000 7.2593 0.004014
Residuals 21 23.143 1.102
Please do not make out your user errors to be S-R differences.
Did you actually try your example in R?
> > CO2 <- factor(rep(c("A","C","E"),each=8))
>
> > m <- rep(seq(0,3,length=8),3) + rep(c(0,1,2),each=8)
>
> > summary.aov(aov(m ~ C(CO2,c(1,0,-1))))
>
> Df Sum of Sq Mean Sq F Value Pr(F)
>
> C(CO2, c(1, 0, -1)) 2 16.00000 8.000000 7.259259 0.004013532
>
> Residuals 21 23.14286 1.102041
>
> > summary.lm(aov(m ~ C(CO2,c(1,0,-1))))
>
> Coefficients:
>
> Value Std. Error t value Pr(>|t|)
>
> (Intercept) 2.5000 0.2143 11.6667 0.0000
>
> C(CO2, c(1, 0, -1))1 -1.0000 0.2624 -3.8103 0.0010
>
> C(CO2, c(1, 0, -1))2 0.0000 0.3712 0.0000 1.0000
>
> Residual standard error: 1.05 on 21 degrees of freedom
>
> Multiple R-Squared: 0.4088
>
> F-statistic: 7.259 on 2 and 21 degrees of freedom, the p-value is 0.004014
>
> Correlation of Coefficients:
>
> (Intercept) C(CO2, c(1, 0, -1))1
>
> C(CO2, c(1, 0, -1))1 0
>
> C(CO2, c(1, 0, -1))2 0 0
>
>
--
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-help
mailing list