[R] linear contrasts with anova

Jose Claudio Faria joseclaudio.faria at terra.com.br
Tue Jan 24 18:41:14 CET 2006


> Date: Mon, 23 Jan 2006 13:25:33 +0100
> From: Christoph Buser <buser at stat.math.ethz.ch>
> Subject: Re: [R] linear contrasts with anova
> To: "Posta Univ. Cagliari" <mtommasi at unica.it>
> Cc: r-help at stat.math.ethz.ch
> Message-ID: <17364.52029.251153.507164 at stat.math.ethz.ch>
> Content-Type: text/plain; charset=us-ascii
> 
> Dear Marco
> 
> If you are interested in a comparison of a reference level
> against each other level (in your case level 1 against level 2
> and level 1 against level 3), you can use the summary.lm(),
> since this is the default contrast (see ?contr.treatment)
> 
> ar <- data.frame(GROUP = factor(rep(1:3, each = 8)),
>                  DIP = c(3.0, 3.0, 4.0, 5.0, 6.0, 7.0, 3.0, 2.0, 1.0, 6.0, 5.0,
>                    7.0, 2.0, 3.0, 1.5, 1.7, 17.0, 12.0, 15.0, 16.0, 12.0, 23.0,
>                    19.0, 21.0))
> 
> 
> r.aov10 <- aov(DIP ~  GROUP, data = ar)
> anova(r.aov10)
> summary.lm(r.aov10)
> 
> As result you will get the comparison GROUP 2 against GROUP 1,
> denoted by GROUP2 and the comparison GROUP 3 against GROUP 1,
> denoted by GROUP3.
> 
> Be careful. In your example you include both GROUP and C1 or C2,
> respectively in your model. This results in a over parameterized
> model and you get a warning that not all coefficients have been
> estimated, due to singularities.
> 
> It is possible to use other contrasts than contr.treatment,
> contr.sum, contr.helmert, contr.poly, but then you have to
> specify the correctly in the model.
> 
> Regards,
> 
> Christoph Buser
> 
> --------------------------------------------------------------
> Christoph Buser <buser at stat.math.ethz.ch>
> Seminar fuer Statistik, LEO C13
> ETH (Federal Inst. Technology)	8092 Zurich	 SWITZERLAND
> phone: x-41-44-632-4673		fax: 632-1228
> http://stat.ethz.ch/~buser/
> --------------------------------------------------------------

Dear Marco

Try also the the below:

# Loading packages
library(gplots)
library(gmodels)

# Testing the nature of dF
is.data.frame(dF)
is.factor(dF$GROUP)
is.numeric(dF$DIP)

#Plotting GROUPS
win.graph(w = 4, h = 5)
plotmeans(DIP ~ GROUP, data = dF, mean.labels = TRUE,
           digits = 3, col = 'blue', connect = FALSE,
           ylab = 'DIP', xlab = 'GROUP', pch='')

# Contrasts
attach(dF)
                              #1   2   3 GROUP
	cmat = rbind('1 vs. 3' = c( 1,  0, -1,),
	             '1 vs. 2' = c( 1, -1,  0,))

   av  = aov(DIP ~ GROUP, data = dF, contrasts = list(GROUP = 
make.contrasts(cmat)))
   sav = summary(av1, split = list(GROUP=list('1 vs. 3'=1,
                                             '1 vs. 2'=2)))
   sav
detach(dF)

# Another option

attach(dF)
                             #A   B   C
   fit.contrast(av, GROUP, c( 1,  0, -1)) # from gmodels
   fit.contrast(av, GROUP, c( 1, -1,  0))
detach(dF)

HTH, []s,
-- 
Jose Claudio Faria
Brasil/Bahia/Ilhéus/UESC/DCET
Estatística Experimental/Prof. Adjunto
mails:
    joseclaudio.faria at terra.com.br
    jc_faria at uesc.br
    jc_faria at uol.com.br




More information about the R-help mailing list