[R] Contrasts within ANOVA frame (Repost)

Mark Difford mark_difford at yahoo.co.uk
Thu Aug 20 10:24:24 CEST 2009


Hi Jun,

>> I have three levels for a factor names "StdLot" and want to make three
>> comparisons, 1 vs 2, 1 vs 3 and 2 vs 3.

With only three levels to your factor, the contrast matrix you are
specifying is over-parametrized (i.e. over-specified): it has 3 rows and 3
columns.

## Look at the default behaviour
contrasts(d3$StdLot) <- NULL
contrasts(d3$StdLot)

contrasts(d3$StdLot) <- contr.helmert
contrasts(d3$StdLot)

I think what you really want are linear contrasts, which you will find in
package car (?linear.hypothesis), in gmodels (?estimable) [based on Frank
Harrell's approach; so look at his package Design], and package multcomp,
amongst others.

Regards, Mark.


Jun Shen-3 wrote:
> 
> Would like to try my luck to see if I can catch your eyes.
> 
> I was trying to do some contrasts within ANOVA. I searched the archive and
> found a clue posted by Steffen Katzner
> ( http://tolstoy.newcastle.edu.au/R/help/06/01/19385.html)
> 
> I have three levels for a factor names "StdLot" and want to make three
> comparisons, 1 vs 2, 1 vs 3 and 2 vs 3.
> 
> First,
> contrasts(d3$StdLot,3)<-matrix(c(1,-1, 0,0,1,-1,1,0,-1),3,3)   #d3 is the
> data set. set up the contrast matrix
> 
> Second,
> aov(Bkg~StdLot,na.rm=T,data=d3,contrasts=contrasts(d3$StdLot))->mod.aov
> #ANOVA,
> 
> Finally,
> summary(mod.aov,split=list(StdLot=list('1 vs 2'=1,'2 vs 3'=2,'1 vs 3'=3)))
> #comparison summary
> 
> Here is the final result I got, the third comparison is missing. Does
> anyone
> have any idea what is wrong here? If I change the order of the comparisons
> it's always the third one missing.  So I guess it's not due to the data.
> Appreciate any comment.
> 
>                   Df Sum Sq Mean Sq F value    Pr(>F)
> StdLot             2  1.905   0.953 10.3769 3.710e-05 ***
>   StdLot: 1 vs 2   1  0.223   0.223  2.4239    0.1200
>   StdLot: 2 vs 3   1  1.683   1.683 18.3299 2.162e-05 ***
>   StdLot: 1 vs 3   1
> Residuals        601 55.173   0.092
> ---
> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
> 2 observations deleted due to missingness
> 
> 
> -- 
> Jun Shen PhD
> PK/PD Scientist
> BioPharma Services
> Millipore Corporation
> 15 Research Park Dr.
> St Charles, MO 63304
> Direct: 636-720-1589
> 
> 	[[alternative HTML version deleted]]
> 
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
> 

-- 
View this message in context: http://www.nabble.com/Contrasts-within-ANOVA-frame-%28Repost%29-tp25052361p25057955.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list